chore: cargo fmt

This commit is contained in:
Alain Emilia Anna Zscheile 2024-10-01 20:47:12 +02:00 committed by mikolaj
parent f653a96eb0
commit 5e3ccf2560
15 changed files with 105 additions and 123 deletions

View File

@ -27,9 +27,5 @@ fn attr_content(attrs: &Vec<Attribute>, name: &str) -> Option<String> {
attrs
.iter()
.find(|attr| attr.path().is_ident(name))
.and_then(|attr| Some(attr
.parse_args::<LitStr>()
.expect("string literal")
.value()
))
.and_then(|attr| Some(attr.parse_args::<LitStr>().expect("string literal").value()))
}

View File

@ -1,11 +1,11 @@
use proc_macro2::TokenStream;
use quote::quote;
use syn::{Data, DeriveInput, Fields, Field};
use syn::Type::Path;
use syn::ext::IdentExt;
use syn::Type::Path;
use syn::{Data, DeriveInput, Field, Fields};
use crate::attr_present;
use crate::attr_content;
use crate::attr_present;
pub fn impl_read(input: &DeriveInput) -> TokenStream {
let name = &input.ident;
@ -24,26 +24,22 @@ pub fn impl_read(input: &DeriveInput) -> TokenStream {
fn impl_body(data: &Data) -> TokenStream {
match data {
Data::Struct(data) => {
match &data.fields {
Fields::Named(fields) => {
let fields = fields.named.iter().map(|field| {
impl_field(field)
});
Data::Struct(data) => match &data.fields {
Fields::Named(fields) => {
let fields = fields.named.iter().map(|field| impl_field(field));
quote! {
Ok(Self {
#(#fields)*
})
}
quote! {
Ok(Self {
#(#fields)*
})
}
_ => unimplemented!()
}
}
_ => unimplemented!(),
},
Data::Enum(_data) => {
todo!();
}
_ => unimplemented!()
_ => unimplemented!(),
}
}
@ -71,7 +67,7 @@ fn impl_field(field: &Field) -> TokenStream {
if ident == "Option" {
return quote! {
#name: tokenizer.read_optional(stringify!(#name_str))?,
}
};
}
}
}
@ -81,4 +77,3 @@ fn impl_field(field: &Field) -> TokenStream {
}
}
}

View File

@ -5,11 +5,7 @@ use thiserror::Error;
use crate::{
board::{mesadata::AccessMesadata, Board},
drawing::{
band::BandTermsegIndex,
dot::FixedDotIndex,
Infringement,
},
drawing::{band::BandTermsegIndex, dot::FixedDotIndex, Infringement},
layout::via::ViaWeight,
router::{navmesh::NavmeshError, RouterError, RouterOptions},
triangulation::GetTrianvertexNodeIndex,
@ -99,7 +95,10 @@ impl<M: AccessMesadata> Autorouter<M> {
Ok(())
}
pub fn place_via(&self, weight: ViaWeight) -> Result<PlaceViaExecutionStepper, AutorouterError> {
pub fn place_via(
&self,
weight: ViaWeight,
) -> Result<PlaceViaExecutionStepper, AutorouterError> {
PlaceViaExecutionStepper::new(weight)
}

View File

@ -44,9 +44,9 @@ impl ExecutionStepper {
match autoroute.step(&mut invoker.autorouter)? {
AutorouteStatus::Running => InvokerStatus::Running,
AutorouteStatus::Routed(..) => InvokerStatus::Running,
AutorouteStatus::Finished => InvokerStatus::Finished(
"finished autorouting".to_string(),
),
AutorouteStatus::Finished => {
InvokerStatus::Finished("finished autorouting".to_string())
}
}
}
ExecutionStepper::PlaceVia(place_via) => {
@ -70,10 +70,7 @@ impl ExecutionStepper {
}
ExecutionStepper::MeasureLength(measure_length) => {
let length = measure_length.doit(&mut invoker.autorouter)?;
InvokerStatus::Finished(format!(
"Total length of selected bands: {}",
length
))
InvokerStatus::Finished(format!("Total length of selected bands: {}", length))
}
})
}

View File

@ -89,7 +89,8 @@ impl Ratsnest {
for layer in 0..layout.drawing().layer_count() {
let mut handle_rvw = |maybe_net: Option<usize>, vertex: RatvertexIndex, pos: Point| {
if let Some(net) = maybe_net {
triangulations.entry((layer, net))
triangulations
.entry((layer, net))
.or_insert_with(|| Triangulation::new(node_bound))
.add_vertex(RatvertexWeight { vertex, pos })?;
}

View File

@ -927,12 +927,15 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
fn test_if_looses_dont_infringe_each_other(&self) -> bool {
!self
.primitive_nodes()
.filter(|node| matches!(node,
PrimitiveIndex::LooseDot(..)
| PrimitiveIndex::LoneLooseSeg(..)
| PrimitiveIndex::SeqLooseSeg(..)
| PrimitiveIndex::LooseBend(..)
))
.filter(|node| {
matches!(
node,
PrimitiveIndex::LooseDot(..)
| PrimitiveIndex::LoneLooseSeg(..)
| PrimitiveIndex::SeqLooseSeg(..)
| PrimitiveIndex::LooseBend(..)
)
})
.any(|node| {
self.find_infringement(
node,
@ -944,12 +947,15 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
None
}
})
.filter(|primitive_node| matches!(primitive_node,
PrimitiveIndex::LooseDot(..)
| PrimitiveIndex::LoneLooseSeg(..)
| PrimitiveIndex::SeqLooseSeg(..)
| PrimitiveIndex::LooseBend(..)
)),
.filter(|primitive_node| {
matches!(
primitive_node,
PrimitiveIndex::LooseDot(..)
| PrimitiveIndex::LoneLooseSeg(..)
| PrimitiveIndex::SeqLooseSeg(..)
| PrimitiveIndex::LooseBend(..)
)
}),
)
.is_some()
})

View File

@ -434,10 +434,7 @@ impl<
GeometryLabel::Joined
)
})
.map(|ni| {
self.primitive_weight(ni)
.retag(ni)
})
.map(|ni| self.primitive_weight(ni).retag(ni))
}
pub fn seg_joints(&self, seg: SI) -> (DI, DI) {

View File

@ -37,7 +37,8 @@ impl<'a, R: AccessRules> Poly<'a, R> {
}
fn is_apex(&self, dot: FixedDotIndex) -> bool {
!self.layout
!self
.layout
.drawing()
.primitive(dot)
.segs()

View File

@ -86,7 +86,8 @@ fn cast_point_to_canonical_line(pt: Point, line: CanonicalLine) -> Point {
/ (line.a * line.a + line.b * line.b),
(line.a * (-line.b * pt.x() + line.a * pt.y()) - line.b * line.c)
/ (line.a * line.a + line.b * line.b),
).into()
)
.into()
}
fn tangent_point_pairs(

View File

@ -197,10 +197,8 @@ where
let zero_score = K::default();
this.scores.insert(start, zero_score);
this.visit_next.push(MinScored(
strategy.estimate_cost(&this.graph, start),
start,
));
this.visit_next
.push(MinScored(strategy.estimate_cost(&this.graph, start), start));
this
}
}

View File

@ -131,9 +131,7 @@ impl<'a, R: AccessRules> Draw<'a, R> {
let tangent = self
.guide()
.head_around_bend_segment(&head, around, cw, width)?;
let offset = self
.guide()
.head_around_bend_offset(&head, around, width);
let offset = self.guide().head_around_bend_offset(&head, around, width);
self.cane_around(
head,

View File

@ -39,7 +39,6 @@ pub enum LoadingError {
Parse(#[from] read::ParseErrorContext),
}
/// This struct is responsible for managing the various Specctra components of a PCB design,
/// including parsing the DSN file, handling the resolution, unit of measurement,
/// and organizing the PCB's structure, placement, library, network, and wiring.
@ -68,16 +67,16 @@ impl SpecctraDesign {
pub fn get_name(&self) -> &str {
&self.pcb.name
}
/// Writes the Specctra Session (.ses) file format using the current board layout and mesadata.
///
/// This function generates a Specctra SES session file that represents the board's net routing and
/// writes it to the provided output stream. The session data includes routed nets, wires,
/// writes it to the provided output stream. The session data includes routed nets, wires,
/// layers, and other essential information for routing management.
pub fn write_ses(
pub fn write_ses(
&self,
board: &Board<SpecctraMesadata>,
writer: impl std::io::Write,
writer: impl std::io::Write,
) -> Result<(), std::io::Error> {
let mesadata = board.mesadata();
let drawing = board.layout().drawing();
@ -150,8 +149,8 @@ impl SpecctraDesign {
structure::NetOut {
name: mesadata.net_netname(net).unwrap().to_owned(),
wire: vec![wire],
via: Vec::new()
},
via: Vec::new(),
},
);
}
}
@ -193,7 +192,8 @@ impl SpecctraDesign {
)));
// mapping of pin -> net prepared for adding pins
let pin_nets = self.pcb
let pin_nets = self
.pcb
.network
.nets
.iter()
@ -229,22 +229,15 @@ impl SpecctraDesign {
.unwrap();
let place_side_is_front = place.side == "front";
let get_layer = |board: &Board<SpecctraMesadata>, name: &str| Self::layer(
board,
&self.pcb.structure.layers,
name,
place_side_is_front,
);
let get_layer = |board: &Board<SpecctraMesadata>, name: &str| {
Self::layer(board, &self.pcb.structure.layers, name, place_side_is_front)
};
for pin in &image.pins {
let pinname = format!("{}-{}", place.name, pin.id);
let net = pin_nets.get(&pinname).unwrap();
let padstack = self
.pcb
.library
.find_padstack_by_name(&pin.name)
.unwrap();
let padstack = self.pcb.library.find_padstack_by_name(&pin.name).unwrap();
for shape in padstack.shapes.iter() {
match shape {
@ -315,14 +308,11 @@ impl SpecctraDesign {
.netname_net(&via.net)
.unwrap();
let padstack = self
.pcb
.library
.find_padstack_by_name(&via.name)
.unwrap();
let padstack = self.pcb.library.find_padstack_by_name(&via.name).unwrap();
let get_layer = |board: &Board<SpecctraMesadata>, name: &str|
Self::layer(board, &self.pcb.structure.layers, name, true);
let get_layer = |board: &Board<SpecctraMesadata>, name: &str| {
Self::layer(board, &self.pcb.structure.layers, name, true)
};
for shape in &padstack.shapes {
match shape {
@ -692,12 +682,7 @@ impl SpecctraDesign {
}
}
fn pos(
place: PointWithRotation,
pin: PointWithRotation,
x: f64,
y: f64,
) -> Point {
fn pos(place: PointWithRotation, pin: PointWithRotation, x: f64, y: f64) -> Point {
let pos = (point! {x: x, y: y} + pin.pos).rotate_around_point(pin.rot, pin.pos);
(pos + place.pos).rotate_around_point(place.rot, place.pos)
}

View File

@ -1,5 +1,5 @@
//! Module for handling Specctra's mesadata - design rules, as well as layers
//! or net properties
//! or net properties
use std::collections::HashMap;
@ -16,7 +16,7 @@ use crate::{
/// the Topola auto-router, in a PCB design process. This struct defines two key design
/// rules: the width of the trace and the minimum clearance between electrical features.
pub struct SpecctraRule {
/// Specifies the width of the trace (or conductor) in millimeters.
/// Specifies the width of the trace (or conductor) in millimeters.
/// This value ensures that the traces meet electrical
/// and mechanical requirements, such as current-carrying capacity or signal integrity.
pub width: f64,
@ -42,10 +42,9 @@ impl SpecctraRule {
/// This struct encapsulates information about rules for individual nets, net classes,
/// layers, and their corresponding relationships.
pub struct SpecctraMesadata {
/// The default routing rule applied globally if no specific net class rule is defined.
structure_rule: SpecctraRule,
// net class name -> rule
/// A map from net class names to their specific `SpecctraRule` constraints.
/// These rules are applied to all nets belonging to the respective net clas
@ -67,7 +66,6 @@ pub struct SpecctraMesadata {
net_netclass: HashMap<usize, String>,
}
impl SpecctraMesadata {
/// Creates a [`SpecctraMesadata`] instance from a given `Pcb` reference.
///
@ -75,10 +73,11 @@ impl SpecctraMesadata {
/// layer-to-layer name mappings, net-to-net name mappings, and net class rules.
pub fn from_pcb(pcb: &Pcb) -> Self {
let layer_layername = BiHashMap::from_iter(
pcb.structure.layers
pcb.structure
.layers
.iter()
.enumerate()
.map(|(index, layer)| (index, layer.name.clone()))
.map(|(index, layer)| (index, layer.name.clone())),
);
// keeping this as a separate iter pass because it might be moved into a different struct later?
@ -115,7 +114,9 @@ impl SpecctraMesadata {
if rule.width.is_some() {
structure_rule.width = rule.width.unwrap()
}
structure_rule.clearances.extend_from_slice(&rule.clearances);
structure_rule
.clearances
.extend_from_slice(&rule.clearances);
}
Self {
@ -129,9 +130,9 @@ impl SpecctraMesadata {
/// Retrieves the Specctra routing rule associated with a specified net ID.
///
/// This function looks up the routing rule for a given net ID. It first checks if the net is
/// associated with a net class. If a net class is found, it retrieves the corresponding rule
/// from the class rules. If no class is associated, or if the class does not have a defined rule,
/// This function looks up the routing rule for a given net ID. It first checks if the net is
/// associated with a net class. If a net class is found, it retrieves the corresponding rule
/// from the class rules. If no class is associated, or if the class does not have a defined rule,
/// it defaults to the general structure rule.
///
pub fn get_rule(&self, net: usize) -> &SpecctraRule {

View File

@ -38,26 +38,31 @@ pub struct InputToken {
impl InputToken {
pub fn new(token: ListToken, context: (usize, usize)) -> Self {
Self {
token,
context,
}
Self { token, context }
}
pub fn expect_start(self, name: &'static str) -> Result<(), ParseErrorContext> {
self.token.expect_start(name).map_err(|err| err.add_context(self.context))
self.token
.expect_start(name)
.map_err(|err| err.add_context(self.context))
}
pub fn expect_any_start(self) -> Result<String, ParseErrorContext> {
self.token.expect_any_start().map_err(|err| err.add_context(self.context))
self.token
.expect_any_start()
.map_err(|err| err.add_context(self.context))
}
pub fn expect_leaf(self) -> Result<String, ParseErrorContext> {
self.token.expect_leaf().map_err(|err| err.add_context(self.context))
self.token
.expect_leaf()
.map_err(|err| err.add_context(self.context))
}
pub fn expect_end(self) -> Result<(), ParseErrorContext> {
self.token.expect_end().map_err(|err| err.add_context(self.context))
self.token
.expect_end()
.map_err(|err| err.add_context(self.context))
}
}
@ -191,9 +196,7 @@ impl<R: std::io::BufRead> ListTokenizer<R> {
}
}
fn map_context<T>(&self, result: Result<T, ParseError>)
-> Result<T, ParseErrorContext>
{
fn map_context<T>(&self, result: Result<T, ParseError>) -> Result<T, ParseErrorContext> {
result.map_err(|err| self.add_context(err))
}
@ -215,7 +218,8 @@ impl<R: std::io::BufRead> ListTokenizer<R> {
Ok(if let Some(chr) = self.peeked_char {
chr
} else {
let chr = self.reader
let chr = self
.reader
.read_char()
.transpose()
.ok_or(self.add_context(ParseError::Eof))?
@ -332,7 +336,10 @@ impl<R: std::io::BufRead> ListTokenizer<R> {
T::read_dsn(self)
}
pub fn read_named<T: ReadDsn<R>>(&mut self, name: &'static str) -> Result<T, ParseErrorContext> {
pub fn read_named<T: ReadDsn<R>>(
&mut self,
name: &'static str,
) -> Result<T, ParseErrorContext> {
self.consume_token()?.expect_start(name)?;
let value = self.read_value::<T>()?;
self.consume_token()?.expect_end()?;

View File

@ -99,9 +99,7 @@ pub struct Structure {
// custom impl to handle layers appearing late
impl<R: std::io::BufRead> ReadDsn<R> for Structure {
fn read_dsn(
tokenizer: &mut ListTokenizer<R>,
) -> Result<Self, ParseErrorContext> {
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
let mut value = Self {
layers: tokenizer.read_named_array("layer")?,
boundary: tokenizer.read_named("boundary")?,
@ -111,7 +109,9 @@ impl<R: std::io::BufRead> ReadDsn<R> for Structure {
rules: tokenizer.read_named_array("rule")?,
};
value.layers.append(&mut tokenizer.read_named_array("layer")?);
value
.layers
.append(&mut tokenizer.read_named_array("layer")?);
Ok(value)
}