From f653a96eb0250a4fa7cc67717d1c5df620209900 Mon Sep 17 00:00:00 2001 From: Alain Emilia Anna Zscheile Date: Tue, 1 Oct 2024 20:13:14 +0200 Subject: [PATCH] chore: trivial fixes of clippy warnings --- src/autorouter/autorouter.rs | 11 +++---- src/autorouter/command.rs | 32 +++++++++---------- src/autorouter/history.rs | 7 ++--- src/autorouter/ratsnest.rs | 60 +++++++++++++----------------------- src/autorouter/selection.rs | 21 +++++-------- src/drawing/collect.rs | 2 +- src/drawing/drawing.rs | 50 ++++++++++++++---------------- src/drawing/primitive.rs | 6 ++-- src/geometry/geometry.rs | 17 ++-------- src/layout/poly.rs | 11 +++---- src/math.rs | 18 +++++------ src/router/astar.rs | 4 +-- src/router/draw.rs | 6 ++-- src/router/navmesh.rs | 2 +- src/router/router.rs | 8 ++--- src/router/trace.rs | 2 +- src/router/tracer.rs | 2 +- src/specctra/design.rs | 58 +++++++++++++++++----------------- src/specctra/read.rs | 24 +++++++-------- src/specctra/structure.rs | 2 +- src/specctra/write.rs | 8 ++--- 21 files changed, 148 insertions(+), 203 deletions(-) diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index cbf05d7..4fd5438 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -124,13 +124,10 @@ impl Autorouter { options: AutorouterOptions, ) -> Result { let ratlines = self.selected_ratlines(selection); - let ratline1 = *ratlines - .get(0) - .ok_or(AutorouterError::NeedExactlyTwoRatlines)?; - let ratline2 = *ratlines - .get(1) - .ok_or(AutorouterError::NeedExactlyTwoRatlines)?; - self.compare_detours_ratlines(ratline1, ratline2, options) + if ratlines.len() < 2 { + return Err(AutorouterError::NeedExactlyTwoRatlines); + } + self.compare_detours_ratlines(ratlines[0], ratlines[1], options) } pub(super) fn compare_detours_ratlines( diff --git a/src/autorouter/command.rs b/src/autorouter/command.rs index f730d34..d56fec7 100644 --- a/src/autorouter/command.rs +++ b/src/autorouter/command.rs @@ -39,47 +39,43 @@ impl ExecutionStepper { &mut self, invoker: &mut Invoker, ) -> Result { - match self { + Ok(match self { ExecutionStepper::Autoroute(autoroute) => { match autoroute.step(&mut invoker.autorouter)? { - AutorouteStatus::Running => Ok(InvokerStatus::Running), - AutorouteStatus::Routed(..) => Ok(InvokerStatus::Running), - AutorouteStatus::Finished => Ok(InvokerStatus::Finished(String::from( - "finished autorouting", - ))), + AutorouteStatus::Running => InvokerStatus::Running, + AutorouteStatus::Routed(..) => InvokerStatus::Running, + AutorouteStatus::Finished => InvokerStatus::Finished( + "finished autorouting".to_string(), + ), } } ExecutionStepper::PlaceVia(place_via) => { place_via.doit(&mut invoker.autorouter)?; - Ok(InvokerStatus::Finished(String::from( - "finished placing via", - ))) + InvokerStatus::Finished("finished placing via".to_string()) } ExecutionStepper::RemoveBands(remove_bands) => { remove_bands.doit(&mut invoker.autorouter)?; - Ok(InvokerStatus::Finished(String::from( - "finished removing bands", - ))) + InvokerStatus::Finished("finished removing bands".to_string()) } ExecutionStepper::CompareDetours(compare_detours) => { match compare_detours.step(&mut invoker.autorouter)? { - CompareDetoursStatus::Running => Ok(InvokerStatus::Running), + CompareDetoursStatus::Running => InvokerStatus::Running, CompareDetoursStatus::Finished(total_length1, total_length2) => { - Ok(InvokerStatus::Finished(String::from(format!( + InvokerStatus::Finished(format!( "total detour lengths are {} and {}", total_length1, total_length2 - )))) + )) } } } ExecutionStepper::MeasureLength(measure_length) => { let length = measure_length.doit(&mut invoker.autorouter)?; - Ok(InvokerStatus::Finished(format!( + InvokerStatus::Finished(format!( "Total length of selected bands: {}", length - ))) + )) } - } + }) } } diff --git a/src/autorouter/history.rs b/src/autorouter/history.rs index 3730480..18ea10f 100644 --- a/src/autorouter/history.rs +++ b/src/autorouter/history.rs @@ -11,7 +11,7 @@ pub enum HistoryError { NoNextCommand, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct History { done: Vec, undone: Vec, @@ -19,10 +19,7 @@ pub struct History { impl History { pub fn new() -> Self { - Self { - done: vec![], - undone: vec![], - } + Self::default() } pub fn destruct(self) -> (Vec, Vec) { diff --git a/src/autorouter/ratsnest.rs b/src/autorouter/ratsnest.rs index 14652fe..9cdae3b 100644 --- a/src/autorouter/ratsnest.rs +++ b/src/autorouter/ratsnest.rs @@ -84,52 +84,36 @@ impl Ratsnest { }; let mut triangulations = HashMap::new(); + let node_bound = layout.drawing().geometry().graph().node_bound(); for layer in 0..layout.drawing().layer_count() { - for node in layout.drawing().layer_primitive_nodes(layer) { - match node { - PrimitiveIndex::FixedDot(dot) => { - if layout.polys(dot).next().is_none() { - if let Some(net) = layout.drawing().primitive(dot).maybe_net() { - if !triangulations.contains_key(&(layer, net)) { - triangulations.insert( - (layer, net), - Triangulation::new( - layout.drawing().geometry().graph().node_bound(), - ), - ); - } + let mut handle_rvw = |maybe_net: Option, vertex: RatvertexIndex, pos: Point| { + if let Some(net) = maybe_net { + triangulations.entry((layer, net)) + .or_insert_with(|| Triangulation::new(node_bound)) + .add_vertex(RatvertexWeight { vertex, pos })?; + } + Ok(()) + }; - triangulations.get_mut(&(layer, net)).unwrap().add_vertex( - RatvertexWeight { - vertex: RatvertexIndex::FixedDot(dot), - pos: node.primitive(layout.drawing()).shape().center(), - }, - )?; - } - } + for node in layout.drawing().layer_primitive_nodes(layer) { + if let PrimitiveIndex::FixedDot(dot) = node { + if layout.polys(dot).next().is_none() { + handle_rvw( + layout.drawing().primitive(dot).maybe_net(), + RatvertexIndex::FixedDot(dot), + node.primitive(layout.drawing()).shape().center(), + )?; } - _ => (), } } for poly in layout.layer_poly_nodes(layer) { - if let Some(net) = layout.drawing().compound_weight(poly.into()).maybe_net() { - if !triangulations.contains_key(&(layer, net)) { - triangulations.insert( - (layer, net), - Triangulation::new(layout.drawing().geometry().graph().node_bound()), - ); - } - - triangulations - .get_mut(&(layer, net)) - .unwrap() - .add_vertex(RatvertexWeight { - vertex: RatvertexIndex::Poly(poly), - pos: layout.poly(poly).shape().center(), - })? - } + handle_rvw( + layout.drawing().compound_weight(poly.into()).maybe_net(), + RatvertexIndex::Poly(poly), + layout.poly(poly).shape().center(), + )?; } } diff --git a/src/autorouter/selection.rs b/src/autorouter/selection.rs index 815bc6f..b060328 100644 --- a/src/autorouter/selection.rs +++ b/src/autorouter/selection.rs @@ -16,16 +16,14 @@ pub struct PinSelector { pub layer: String, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct PinSelection { selectors: HashSet, } impl PinSelection { pub fn new() -> Self { - Self { - selectors: HashSet::new(), - } + Self::default() } pub fn new_select_layer(board: &Board, layer: usize) -> Self { @@ -100,16 +98,14 @@ pub struct BandSelector { pub band: BandName, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct BandSelection { selectors: HashSet, } impl BandSelection { pub fn new() -> Self { - Self { - selectors: HashSet::new(), - } + Self::default() } fn node_selector( @@ -141,7 +137,7 @@ impl BandSelection { } fn deselect(&mut self, selector: &BandSelector) { - self.selectors.remove(&selector); + self.selectors.remove(selector); } pub fn contains_node(&self, board: &Board, node: NodeIndex) -> bool { @@ -154,7 +150,7 @@ impl BandSelection { } } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct Selection { pub pin_selection: PinSelection, pub band_selection: BandSelection, @@ -162,10 +158,7 @@ pub struct Selection { impl Selection { pub fn new() -> Self { - Self { - pin_selection: PinSelection::new(), - band_selection: BandSelection::new(), - } + Self::default() } pub fn toggle_at_node(&mut self, board: &Board, node: NodeIndex) { diff --git a/src/drawing/collect.rs b/src/drawing/collect.rs index feab07b..cd7d765 100644 --- a/src/drawing/collect.rs +++ b/src/drawing/collect.rs @@ -88,7 +88,7 @@ impl<'a, CW: Copy, R: AccessRules> Collect<'a, CW, R> { let mut gear = bend; while let Some(outer) = self.drawing.primitive(gear).outer() { - v.append(&mut self.bend_bow(outer.into())); + v.append(&mut self.bend_bow(outer)); gear = outer; } diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index 68d6889..17873ca 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -357,7 +357,7 @@ impl Drawing { GeometryLabel::Core ) }) - .map(|ni| FixedDotIndex::new(ni)) + .map(FixedDotIndex::new) .collect::>() .first() .unwrap(); @@ -418,7 +418,7 @@ impl Drawing { if let Some(outer) = self.primitive(cane.bend).outer() { self.update_this_and_outward_bows(outer).map_err(|err| { let joint = self.primitive(cane.bend).other_joint(cane.dot); - self.remove_cane(&cane, joint.into()); + self.remove_cane(&cane, joint); err })?; } @@ -426,11 +426,11 @@ impl Drawing { // Segs must not cross. if let Some(collision) = self.detect_collision(cane.seg.into()) { let joint = self.primitive(cane.bend).other_joint(cane.dot); - self.remove_cane(&cane, joint.into()); - return Err(collision.into()); + self.remove_cane(&cane, joint); + Err(collision.into()) + } else { + Ok(cane) } - - Ok(cane) } #[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))] @@ -453,7 +453,7 @@ impl Drawing { if let Some(inner) = rail_primitive.inner() { let from = guide .head_around_bend_segment( - &from_head.into(), + &from_head, inner.into(), true, self.primitive(rail).width(), @@ -461,14 +461,14 @@ impl Drawing { .end_point(); let to = guide .head_around_bend_segment( - &to_head.into(), + &to_head, inner.into(), false, self.primitive(rail).width(), )? .end_point(); let offset = guide.head_around_bend_offset( - &from_head.into(), + &from_head, inner.into(), self.primitive(rail).width(), ); @@ -495,7 +495,7 @@ impl Drawing { let core = rail_primitive.core(); let from = guide .head_around_dot_segment( - &from_head.into(), + &from_head, core.into(), true, self.primitive(rail).width(), @@ -503,14 +503,14 @@ impl Drawing { .end_point(); let to = guide .head_around_dot_segment( - &to_head.into(), + &to_head, core.into(), false, self.primitive(rail).width(), )? .end_point(); let offset = guide.head_around_dot_offset( - &from_head.into(), + &from_head, core.into(), self.primitive(rail).width(), ); @@ -659,7 +659,7 @@ impl Drawing { self.geometry_with_rtree.move_dot(dot, to); for limb in dot.primitive(self).limbs() { - if let Some(infringement) = self.detect_infringement_except(limb.into(), infringables) { + if let Some(infringement) = self.detect_infringement_except(limb, infringables) { // Restore original state. self.geometry_with_rtree.move_dot(dot, old_pos); return Err(infringement); @@ -713,10 +713,8 @@ impl Drawing { } }) .filter(|primitive_node| !self.are_connectable(node, *primitive_node)) - .filter(|primitive_node| shape.intersects(&primitive_node.primitive(self).shape())) - .map(|primitive_node| primitive_node) - .next() - .and_then(|collidee| Some(Collision(shape, collidee))) + .find(|primitive_node| shape.intersects(&primitive_node.primitive(self).shape())) + .map(|collidee| Collision(shape, collidee)) } } @@ -784,7 +782,7 @@ impl Drawing { } }) .filter(|primitive_node| { - maybe_except.is_some_and(|except| !except.contains(&primitive_node)) + maybe_except.is_some_and(|except| !except.contains(primitive_node)) }), ) } @@ -796,7 +794,7 @@ impl Drawing { let limiting_shape = node.primitive(self).shape().inflate( node.primitive(self) .maybe_net() - .and_then(|net| Some(self.rules.largest_clearance(Some(net)))) + .map(|net| self.rules.largest_clearance(Some(net))) .unwrap_or(0.0), ); @@ -929,13 +927,12 @@ impl Drawing { fn test_if_looses_dont_infringe_each_other(&self) -> bool { !self .primitive_nodes() - .filter(|node| match node { + .filter(|node| matches!(node, PrimitiveIndex::LooseDot(..) | PrimitiveIndex::LoneLooseSeg(..) | PrimitiveIndex::SeqLooseSeg(..) - | PrimitiveIndex::LooseBend(..) => true, - _ => false, - }) + | PrimitiveIndex::LooseBend(..) + )) .any(|node| { self.find_infringement( node, @@ -947,13 +944,12 @@ impl Drawing { None } }) - .filter(|primitive_node| match primitive_node { + .filter(|primitive_node| matches!(primitive_node, PrimitiveIndex::LooseDot(..) | PrimitiveIndex::LoneLooseSeg(..) | PrimitiveIndex::SeqLooseSeg(..) - | PrimitiveIndex::LooseBend(..) => true, - _ => false, - }), + | PrimitiveIndex::LooseBend(..) + )), ) .is_some() }) diff --git a/src/drawing/primitive.rs b/src/drawing/primitive.rs index 51b697d..eda9c19 100644 --- a/src/drawing/primitive.rs +++ b/src/drawing/primitive.rs @@ -193,7 +193,7 @@ impl<'a, W, CW: Copy, R: AccessRules> GenericPrimitive<'a, W, CW, R> { } fn primitive(&self, index: GenericIndex) -> GenericPrimitive { - GenericPrimitive::new(index, &self.drawing) + GenericPrimitive::new(index, self.drawing) } } @@ -379,7 +379,7 @@ impl<'a, CW: Copy, R: AccessRules> GetJoints for SeqLoo if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.0) { ( FixedDotIndex::new(joints.0.petgraph_index()).into(), - LooseDotIndex::new(joints.1.petgraph_index()).into(), + LooseDotIndex::new(joints.1.petgraph_index()), ) } else if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.1) { ( @@ -389,7 +389,7 @@ impl<'a, CW: Copy, R: AccessRules> GetJoints for SeqLoo } else { ( LooseDotIndex::new(joints.0.petgraph_index()).into(), - LooseDotIndex::new(joints.1.petgraph_index()).into(), + LooseDotIndex::new(joints.1.petgraph_index()), ) } } diff --git a/src/geometry/geometry.rs b/src/geometry/geometry.rs index 0556286..f12fc74 100644 --- a/src/geometry/geometry.rs +++ b/src/geometry/geometry.rs @@ -221,8 +221,7 @@ impl< if let Some(old_inner_edge) = self .graph .edges_directed(bend.petgraph_index(), Incoming) - .filter(|edge| *edge.weight() == GeometryLabel::Outer) - .next() + .find(|edge| *edge.weight() == GeometryLabel::Outer) { self.graph.remove_edge(old_inner_edge.id()); } @@ -274,10 +273,7 @@ impl< let mut rail = bend; while let Some(inner) = self.inner(rail) { - let weight: BW = self - .bend_weight(inner) - .try_into() - .unwrap_or_else(|_| unreachable!()); + let weight: BW = self.bend_weight(inner); r += weight.width() + weight.offset(); rail = inner; } @@ -441,8 +437,6 @@ impl< .map(|ni| { self.primitive_weight(ni) .retag(ni) - .try_into() - .unwrap_or_else(|_| unreachable!()) }) } @@ -485,12 +479,7 @@ impl< GeometryLabel::Compound ) }) - .map(|ni| { - self.primitive_weight(ni) - .retag(ni) - .try_into() - .unwrap_or_else(|_| unreachable!()) - }) + .map(|ni| self.primitive_weight(ni).retag(ni)) } pub fn graph(&self) -> &StableDiGraph, GeometryLabel, usize> { diff --git a/src/layout/poly.rs b/src/layout/poly.rs index 657d1c3..f124607 100644 --- a/src/layout/poly.rs +++ b/src/layout/poly.rs @@ -37,13 +37,12 @@ impl<'a, R: AccessRules> Poly<'a, R> { } fn is_apex(&self, dot: FixedDotIndex) -> bool { - self.layout + !self.layout .drawing() .primitive(dot) .segs() .iter() - .find(|seg| matches!(seg, SegIndex::Fixed(..))) - .is_none() + .any(|seg| matches!(seg, SegIndex::Fixed(..))) && self.layout.drawing().primitive(dot).bends().is_empty() } } @@ -84,7 +83,7 @@ impl<'a, R: AccessRules> MakePolyShape for Poly<'a, R> { }; if self.is_apex(dot) { - return None; + None } else { Some( self.layout @@ -164,13 +163,13 @@ pub struct PourPolyWeight { pub maybe_net: Option, } -impl<'a> GetLayer for PourPolyWeight { +impl GetLayer for PourPolyWeight { fn layer(&self) -> usize { self.layer } } -impl<'a> GetMaybeNet for PourPolyWeight { +impl GetMaybeNet for PourPolyWeight { fn maybe_net(&self) -> Option { self.maybe_net } diff --git a/src/math.rs b/src/math.rs index 1aea605..0489458 100644 --- a/src/math.rs +++ b/src/math.rs @@ -81,13 +81,12 @@ fn _tangents(circle1: Circle, circle2: Circle) -> Result<[CanonicalLine; 4], ()> } fn cast_point_to_canonical_line(pt: Point, line: CanonicalLine) -> Point { - return ( + ( (line.b * (line.b * pt.x() - line.a * pt.y()) - line.a * line.c) / (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( @@ -193,6 +192,7 @@ pub fn intersect_circle_segment(circle: &Circle, segment: &Line) -> Vec { let from = segment.start_point(); let to = segment.end_point(); let epsilon = 1e-9; + let interval01 = 0.0..=1.0; let a = delta.dot(delta); let b = @@ -209,24 +209,24 @@ pub fn intersect_circle_segment(circle: &Circle, segment: &Line) -> Vec { if discriminant == 0.0 { let u = -b / (2.0 * a); - if u >= 0.0 && u <= 1.0 { - return [from + (to - from) * -b / (2.0 * a)].into(); + return if interval01.contains(&u) { + vec![from + (to - from) * -b / (2.0 * a)] } else { - return [].into(); - } + vec![] + }; } let mut v = vec![]; let u1 = (-b + discriminant.sqrt()) / (2.0 * a); - if u1 >= 0.0 && u1 <= 1.0 { + if interval01.contains(&u1) { v.push(from + (to - from) * u1); } let u2 = (-b - discriminant.sqrt()) / (2.0 * a); - if u2 >= 0.0 && u2 <= 1.0 { + if interval01.contains(&u2) { v.push(from + (to - from) * u2); } diff --git a/src/router/astar.rs b/src/router/astar.rs index 2d6aec0..eab2214 100644 --- a/src/router/astar.rs +++ b/src/router/astar.rs @@ -111,7 +111,7 @@ where graph: &'a G, edge: <&'a G as IntoEdgeReferences>::EdgeRef, ) -> Option; - fn remove_probe<'a>(&mut self, graph: &'a G); + fn remove_probe(&mut self, graph: &G); fn estimate_cost(&mut self, graph: &G, node: G::NodeId) -> K; } @@ -198,7 +198,7 @@ where let zero_score = K::default(); this.scores.insert(start, zero_score); this.visit_next.push(MinScored( - strategy.estimate_cost(&&this.graph, start), + strategy.estimate_cost(&this.graph, start), start, )); this diff --git a/src/router/draw.rs b/src/router/draw.rs index 04d3668..74185eb 100644 --- a/src/router/draw.rs +++ b/src/router/draw.rs @@ -67,7 +67,7 @@ impl<'a, R: AccessRules> Draw<'a, R> { self.layout .add_lone_loose_seg( dot, - into.into(), + into, LoneLooseSegWeight { width, layer, @@ -130,10 +130,10 @@ impl<'a, R: AccessRules> Draw<'a, R> { ) -> Result { let tangent = self .guide() - .head_around_bend_segment(&head, around.into(), cw, width)?; + .head_around_bend_segment(&head, around, cw, width)?; let offset = self .guide() - .head_around_bend_offset(&head, around.into(), width); + .head_around_bend_offset(&head, around, width); self.cane_around( head, diff --git a/src/router/navmesh.rs b/src/router/navmesh.rs index 1bc308f..bb5f514 100644 --- a/src/router/navmesh.rs +++ b/src/router/navmesh.rs @@ -367,7 +367,7 @@ impl<'a> IntoNeighbors for &'a Navmesh { Box::new( self.graph .neighbors(vertex.petgraph_index()) - .map(|ni| NavvertexIndex(ni)), + .map(NavvertexIndex), ) } } diff --git a/src/router/router.rs b/src/router/router.rs index 44e2827..72d63ab 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -109,11 +109,11 @@ impl<'a, R: AccessRules> AstarStrategy let width = self.trace.width; self.tracer - .rework_path(navmesh, &mut self.trace, &new_path[..], width) + .rework_path(navmesh, self.trace, &new_path[..], width) .unwrap(); self.tracer - .finish(navmesh, &mut self.trace, self.target, width) + .finish(navmesh, self.trace, self.target, width) .ok() } @@ -205,11 +205,11 @@ impl<'a, R: AccessRules> Router<'a, R> { } pub fn layout_mut(&mut self) -> &mut Layout { - &mut self.layout + self.layout } pub fn layout(&self) -> &Layout { - &self.layout + self.layout } pub fn options(&self) -> RouterOptions { diff --git a/src/router/trace.rs b/src/router/trace.rs index 644a3a6..9073092 100644 --- a/src/router/trace.rs +++ b/src/router/trace.rs @@ -70,7 +70,7 @@ impl TraceStepper { cw: bool, width: f64, ) -> Result { - Ok(Draw::new(tracer.layout).cane_around_dot(head, around.into(), cw, width)?) + Ok(Draw::new(tracer.layout).cane_around_dot(head, around, cw, width)?) } fn wrap_around_loose_bend( diff --git a/src/router/tracer.rs b/src/router/tracer.rs index b63b93a..d8dc2b7 100644 --- a/src/router/tracer.rs +++ b/src/router/tracer.rs @@ -102,7 +102,7 @@ impl<'a, R: AccessRules> Tracer<'a, R> { width, }) { self.undo_path(trace, i); - return Err(err.into()); + return Err(err); } } diff --git a/src/specctra/design.rs b/src/specctra/design.rs index 8b0932a..51bc81e 100644 --- a/src/specctra/design.rs +++ b/src/specctra/design.rs @@ -178,8 +178,8 @@ impl SpecctraDesign { ListWriter::new(writer).write_value(&ses) } - - /// Generates a [`Board`] from the current PCB data. + + /// Generates a [`Board`] from the current PCB data. /// /// This function takes the internal `Pcb` structure and transforms it into a [`Board`] object, /// which is used for layout and routing operations. The board is initialized with [`SpecctraMesadata`], @@ -193,31 +193,29 @@ impl SpecctraDesign { ))); // mapping of pin -> net prepared for adding pins - let pin_nets = HashMap::::from_iter( - self.pcb - .network - .nets - .iter() - .map(|net_pin_assignments| { - // resolve the id so we don't work with strings - let net = board - .layout() - .drawing() - .rules() - .netname_net(&net_pin_assignments.name) - .unwrap(); + let pin_nets = self.pcb + .network + .nets + .iter() + // flatten the nested iters into a single stream of tuples + .flat_map(|net_pin_assignments| { + // resolve the id so we don't work with strings + let net = board + .layout() + .drawing() + .rules() + .netname_net(&net_pin_assignments.name) + .unwrap(); - // take the list of pins - // and for each pin id output (pin id, net id) - net_pin_assignments - .pins - .names - .iter() - .map(move |pinname| (pinname.clone(), net)) - }) - // flatten the nested iters into a single stream of tuples - .flatten(), - ); + // take the list of pins + // and for each pin id output (pin id, net id) + net_pin_assignments + .pins + .names + .iter() + .map(move |pinname| (pinname.clone(), net)) + }) + .collect::>(); // add pins from components for component in &self.pcb.placement.components { @@ -416,7 +414,7 @@ impl SpecctraDesign { fn layer( board: &Board, - layers: &Vec, + layers: &[Layer], layername: &str, front: bool, ) -> usize { @@ -571,7 +569,7 @@ impl SpecctraDesign { board: &mut Board, place: PointWithRotation, pin: PointWithRotation, - coords: &Vec, + coords: &[structure::Point], width: f64, layer: usize, net: usize, @@ -632,7 +630,7 @@ impl SpecctraDesign { board: &mut Board, place: PointWithRotation, pin: PointWithRotation, - coords: &Vec, + coords: &[structure::Point], width: f64, layer: usize, net: usize, @@ -667,7 +665,7 @@ impl SpecctraDesign { let index = board.add_poly_fixed_dot_infringably( FixedDotWeight { circle: Circle { - pos: Self::pos(place, pin, coord.x, coord.y).into(), + pos: Self::pos(place, pin, coord.x, coord.y), r: width / 2.0, }, layer, diff --git a/src/specctra/read.rs b/src/specctra/read.rs index 51e1288..cc4ee45 100644 --- a/src/specctra/read.rs +++ b/src/specctra/read.rs @@ -82,7 +82,7 @@ impl ReadDsn for Parser { impl ReadDsn for String { fn read_dsn(tokenizer: &mut ListTokenizer) -> Result { - Ok(tokenizer.consume_token()?.expect_leaf()?) + tokenizer.consume_token()?.expect_leaf() } } @@ -109,51 +109,51 @@ impl ReadDsn for bool { impl ReadDsn for i32 { fn read_dsn(tokenizer: &mut ListTokenizer) -> Result { - Ok(tokenizer + tokenizer .consume_token()? .expect_leaf()? .parse() - .map_err(|_| tokenizer.add_context(ParseError::Expected("i32")))?) + .map_err(|_| tokenizer.add_context(ParseError::Expected("i32"))) } } impl ReadDsn for u32 { fn read_dsn(tokenizer: &mut ListTokenizer) -> Result { - Ok(tokenizer + tokenizer .consume_token()? .expect_leaf()? .parse() - .map_err(|_| tokenizer.add_context(ParseError::Expected("u32")))?) + .map_err(|_| tokenizer.add_context(ParseError::Expected("u32"))) } } impl ReadDsn for usize { fn read_dsn(tokenizer: &mut ListTokenizer) -> Result { - Ok(tokenizer + tokenizer .consume_token()? .expect_leaf()? .parse() - .map_err(|_| tokenizer.add_context(ParseError::Expected("usize")))?) + .map_err(|_| tokenizer.add_context(ParseError::Expected("usize"))) } } impl ReadDsn for f32 { fn read_dsn(tokenizer: &mut ListTokenizer) -> Result { - Ok(tokenizer + tokenizer .consume_token()? .expect_leaf()? .parse() - .map_err(|_| tokenizer.add_context(ParseError::Expected("f32")))?) + .map_err(|_| tokenizer.add_context(ParseError::Expected("f32"))) } } impl ReadDsn for f64 { fn read_dsn(tokenizer: &mut ListTokenizer) -> Result { - Ok(tokenizer + tokenizer .consume_token()? .expect_leaf()? .parse() - .map_err(|_| tokenizer.add_context(ParseError::Expected("f64")))?) + .map_err(|_| tokenizer.add_context(ParseError::Expected("f64"))) } } @@ -170,7 +170,7 @@ pub struct ListTokenizer { impl ListTokenizer { pub fn new(reader: R) -> Self { Self { - reader: reader, + reader, peeked_char: None, cached_token: None, space_in_quoted: false, diff --git a/src/specctra/structure.rs b/src/specctra/structure.rs index 11674fd..58d21a6 100644 --- a/src/specctra/structure.rs +++ b/src/specctra/structure.rs @@ -212,7 +212,7 @@ pub struct Library { impl Library { pub fn find_padstack_by_name(&self, name: &str) -> Option<&Padstack> { - self.padstacks.iter().find(|padstack| &padstack.name == name) + self.padstacks.iter().find(|padstack| padstack.name == name) } } diff --git a/src/specctra/write.rs b/src/specctra/write.rs index fb5155e..340be12 100644 --- a/src/specctra/write.rs +++ b/src/specctra/write.rs @@ -13,13 +13,9 @@ impl WriteSes for char { impl WriteSes for String { fn write_dsn(&self, writer: &mut ListWriter) -> Result<(), io::Error> { - let string = if self.len() == 0 { + let string = if self.is_empty() { "\"\"".to_string() - } else if self.contains(" ") - || self.contains("(") - || self.contains(")") - || self.contains("\n") - { + } else if self.contains(|i: char| i == ' ' || i == '(' || i == ')' || i == '\n') { format!("\"{}\"", self) } else { self.to_string()