diff --git a/src/autorouter/pointroute.rs b/src/autorouter/pointroute.rs index 082979e..7a37d63 100644 --- a/src/autorouter/pointroute.rs +++ b/src/autorouter/pointroute.rs @@ -10,7 +10,7 @@ use crate::{ board::AccessMesadata, drawing::{ band::BandTermsegIndex, - dot::{FixedDotIndex, FixedDotWeight}, + dot::{FixedDotIndex, FixedDotWeight, GeneralDotWeight}, }, layout::LayoutEdit, math::Circle, @@ -34,14 +34,14 @@ impl PointrouteExecutionStepper { ) -> Result { let destination = autorouter.board.add_fixed_dot_infringably( &mut LayoutEdit::new(), - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle: Circle { pos: point, r: options.router_options.routed_band_width / 2.0, }, layer: 0, maybe_net: None, - }, + }), None, ); diff --git a/src/board/mod.rs b/src/board/mod.rs index 0fab29f..f009f55 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -18,7 +18,7 @@ use crate::{ drawing::{ band::BandUid, bend::{BendIndex, BendWeight}, - dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight}, + dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, GeneralDotWeight}, graph::{GetLayer, GetMaybeNet, PrimitiveIndex, PrimitiveWeight}, seg::{FixedSegIndex, FixedSegWeight, SegIndex, SegWeight}, Collect, @@ -246,14 +246,14 @@ impl Board { } else { self.add_poly_fixed_dot_infringably( recorder, - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle: Circle { pos: resolved_poly.shape().center(), r: 100.0, }, layer: resolved_poly.layer(), maybe_net: resolved_poly.maybe_net(), - }, + }), poly, ) } diff --git a/src/drawing/bend.rs b/src/drawing/bend.rs index 7759ec1..3d75fbe 100644 --- a/src/drawing/bend.rs +++ b/src/drawing/bend.rs @@ -74,57 +74,71 @@ impl TryFrom for BendWeight { } #[derive(Debug, Clone, Copy, PartialEq)] -pub struct FixedBendWeight { - pub width: f64, - pub offset: f64, - pub layer: usize, - pub maybe_net: Option, -} - -impl_fixed_weight!(FixedBendWeight, FixedBend, FixedBendIndex); +pub struct FixedBendWeight(pub GeneralBendWeight); +impl_weight_forward!(FixedBendWeight, FixedBend, FixedBendIndex); impl GetOffset for FixedBendWeight { fn offset(&self) -> f64 { - self.offset + self.0.offset() } } impl SetOffset for FixedBendWeight { fn set_offset(&mut self, offset: f64) { - self.offset = offset - } -} - -impl GetWidth for FixedBendWeight { - fn width(&self) -> f64 { - self.width + self.0.set_offset(offset); } } #[derive(Debug, Clone, Copy, PartialEq)] -pub struct LooseBendWeight { +pub struct LooseBendWeight(pub GeneralBendWeight); +impl_weight_forward!(LooseBendWeight, LooseBend, LooseBendIndex); + +impl GetOffset for LooseBendWeight { + fn offset(&self) -> f64 { + self.0.offset() + } +} + +impl SetOffset for LooseBendWeight { + fn set_offset(&mut self, offset: f64) { + self.0.set_offset(offset); + } +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct GeneralBendWeight { pub width: f64, pub offset: f64, pub layer: usize, pub maybe_net: Option, } -impl GetOffset for LooseBendWeight { +impl GetLayer for GeneralBendWeight { + fn layer(&self) -> usize { + self.layer + } +} + +impl GetMaybeNet for GeneralBendWeight { + fn maybe_net(&self) -> Option { + self.maybe_net + } +} + +impl GetOffset for GeneralBendWeight { fn offset(&self) -> f64 { self.offset } } -impl SetOffset for LooseBendWeight { +impl SetOffset for GeneralBendWeight { fn set_offset(&mut self, offset: f64) { self.offset = offset } } -impl GetWidth for LooseBendWeight { +impl GetWidth for GeneralBendWeight { fn width(&self) -> f64 { self.width } } - -impl_loose_weight!(LooseBendWeight, LooseBend, LooseBendIndex); diff --git a/src/drawing/dot.rs b/src/drawing/dot.rs index 87ab230..f337dbe 100644 --- a/src/drawing/dot.rs +++ b/src/drawing/dot.rs @@ -76,50 +76,61 @@ impl TryFrom for DotWeight { } #[derive(Debug, Clone, Copy, PartialEq)] -pub struct FixedDotWeight { - pub circle: Circle, - pub layer: usize, - pub maybe_net: Option, -} - -impl_fixed_weight!(FixedDotWeight, FixedDot, FixedDotIndex); +pub struct FixedDotWeight(pub GeneralDotWeight); +impl_weight_forward!(FixedDotWeight, FixedDot, FixedDotIndex); impl GetSetPos for FixedDotWeight { fn pos(&self) -> Point { - self.circle.pos + self.0.pos() } - fn set_pos(&mut self, pos: Point) { - self.circle.pos = pos - } -} - -impl GetWidth for FixedDotWeight { - fn width(&self) -> f64 { - self.circle.r * 2.0 + self.0.set_pos(pos); } } #[derive(Debug, Clone, Copy, PartialEq)] -pub struct LooseDotWeight { +pub struct LooseDotWeight(pub GeneralDotWeight); +impl_weight_forward!(LooseDotWeight, LooseDot, LooseDotIndex); + +impl GetSetPos for LooseDotWeight { + fn pos(&self) -> Point { + self.0.pos() + } + fn set_pos(&mut self, pos: Point) { + self.0.set_pos(pos); + } +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct GeneralDotWeight { pub circle: Circle, pub layer: usize, pub maybe_net: Option, } -impl_loose_weight!(LooseDotWeight, LooseDot, LooseDotIndex); +impl GetLayer for GeneralDotWeight { + fn layer(&self) -> usize { + self.layer + } +} -impl GetSetPos for LooseDotWeight { +impl GetMaybeNet for GeneralDotWeight { + fn maybe_net(&self) -> Option { + self.maybe_net + } +} + +impl GetSetPos for GeneralDotWeight { fn pos(&self) -> Point { self.circle.pos } fn set_pos(&mut self, pos: Point) { - self.circle.pos = pos + self.circle.pos = pos; } } -impl GetWidth for LooseDotWeight { +impl GetWidth for GeneralDotWeight { fn width(&self) -> f64 { self.circle.r * 2.0 } diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index baffa77..8e136bb 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -329,7 +329,7 @@ impl Drawing { ) -> Result { // It makes no sense to wrap something around or under one of its connectables. // - if let Some(net) = weight.maybe_net { + if let Some(net) = weight.maybe_net() { if let Some(around_net) = around.primitive(self).maybe_net() { if net == around_net { return Err(AlreadyConnected(net, around.into()).into()); diff --git a/src/drawing/graph.rs b/src/drawing/graph.rs index 944c1ef..990e80a 100644 --- a/src/drawing/graph.rs +++ b/src/drawing/graph.rs @@ -59,23 +59,29 @@ pub trait MakePrimitive { ) -> Primitive<'a, CW, R>; } -macro_rules! impl_weight { - ($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => { +macro_rules! impl_weight_forward { + ($weight_struct:ty, $weight_variant:ident, $index_struct:ident) => { impl Retag for $weight_struct { fn retag(&self, index: NodeIndex) -> PrimitiveIndex { PrimitiveIndex::$weight_variant($index_struct::new(index)) } } - impl<'a> GetLayer for $weight_struct { + impl GetLayer for $weight_struct { fn layer(&self) -> usize { - self.layer + self.0.layer() } } - impl<'a> GetMaybeNet for $weight_struct { + impl GetMaybeNet for $weight_struct { fn maybe_net(&self) -> Option { - self.maybe_net + self.0.maybe_net() + } + } + + impl GetWidth for $weight_struct { + fn width(&self) -> f64 { + self.0.width() } } @@ -92,18 +98,6 @@ macro_rules! impl_weight { }; } -macro_rules! impl_fixed_weight { - ($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => { - impl_weight!($weight_struct, $weight_variant, $index_struct); - }; -} - -macro_rules! impl_loose_weight { - ($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => { - impl_weight!($weight_struct, $weight_variant, $index_struct); - }; -} - // TODO: This enum shouldn't exist: we shouldn't be carrying the tag around like this. Instead we // should be getting it from the graph when it's needed. #[enum_dispatch(GetPetgraphIndex, MakePrimitive)] diff --git a/src/drawing/guide.rs b/src/drawing/guide.rs index 51dde74..1943425 100644 --- a/src/drawing/guide.rs +++ b/src/drawing/guide.rs @@ -82,7 +82,7 @@ impl Guide for Drawing { ) -> Result { let from_circle = self.head_circle(head, width); let to_circle = Circle { - pos: self.primitive(into).weight().circle.pos, + pos: self.primitive(into).weight().0.circle.pos, r: 0.0, }; diff --git a/src/drawing/primitive.rs b/src/drawing/primitive.rs index 2ac5200..585e920 100644 --- a/src/drawing/primitive.rs +++ b/src/drawing/primitive.rs @@ -476,7 +476,7 @@ impl<'a, CW: Copy, R: AccessRules> GetLimbs for LooseBend<'a, CW, R> {} impl<'a, CW: Copy, R: AccessRules> GetOffset for LooseBend<'a, CW, R> { fn offset(&self) -> f64 { - self.weight().offset + self.weight().offset() } } diff --git a/src/drawing/seg.rs b/src/drawing/seg.rs index 5dade7a..216155a 100644 --- a/src/drawing/seg.rs +++ b/src/drawing/seg.rs @@ -80,45 +80,37 @@ impl TryFrom for SegWeight { } #[derive(Debug, Clone, Copy, PartialEq)] -pub struct FixedSegWeight { - pub width: f64, - pub layer: usize, - pub maybe_net: Option, -} - -impl_fixed_weight!(FixedSegWeight, FixedSeg, FixedSegIndex); - -impl GetWidth for FixedSegWeight { - fn width(&self) -> f64 { - self.width - } -} +pub struct FixedSegWeight(pub GeneralSegWeight); +impl_weight_forward!(FixedSegWeight, FixedSeg, FixedSegIndex); #[derive(Debug, Clone, Copy, PartialEq)] -pub struct LoneLooseSegWeight { - pub width: f64, - pub layer: usize, - pub maybe_net: Option, -} - -impl_loose_weight!(LoneLooseSegWeight, LoneLooseSeg, LoneLooseSegIndex); - -impl GetWidth for LoneLooseSegWeight { - fn width(&self) -> f64 { - self.width - } -} +pub struct LoneLooseSegWeight(pub GeneralSegWeight); +impl_weight_forward!(LoneLooseSegWeight, LoneLooseSeg, LoneLooseSegIndex); #[derive(Debug, Clone, Copy, PartialEq)] -pub struct SeqLooseSegWeight { +pub struct SeqLooseSegWeight(pub GeneralSegWeight); +impl_weight_forward!(SeqLooseSegWeight, SeqLooseSeg, SeqLooseSegIndex); + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct GeneralSegWeight { pub width: f64, pub layer: usize, pub maybe_net: Option, } -impl_loose_weight!(SeqLooseSegWeight, SeqLooseSeg, SeqLooseSegIndex); +impl GetLayer for GeneralSegWeight { + fn layer(&self) -> usize { + self.layer + } +} -impl GetWidth for SeqLooseSegWeight { +impl GetMaybeNet for GeneralSegWeight { + fn maybe_net(&self) -> Option { + self.maybe_net + } +} + +impl GetWidth for GeneralSegWeight { fn width(&self) -> f64 { self.width } diff --git a/src/layout/layout.rs b/src/layout/layout.rs index 27b4432..2b5d58c 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -12,7 +12,10 @@ use crate::{ drawing::{ band::BandTermsegIndex, bend::{BendIndex, BendWeight, LooseBendWeight}, - dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight}, + dot::{ + DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, GeneralDotWeight, LooseDotIndex, + LooseDotWeight, + }, gear::GearIndex, graph::{GetMaybeNet, IsInLayer, MakePrimitive, PrimitiveIndex, PrimitiveWeight}, primitive::MakePrimitiveShape, @@ -99,11 +102,11 @@ impl Layout { for layer in weight.from_layer..=weight.to_layer { match self.drawing.add_fixed_dot( recorder, - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle: weight.circle, layer, maybe_net: weight.maybe_net, - }, + }), ) { Ok(dot) => { self.drawing.add_to_compound(recorder, dot, compound); diff --git a/src/router/draw.rs b/src/router/draw.rs index 6e305d4..6ec362d 100644 --- a/src/router/draw.rs +++ b/src/router/draw.rs @@ -11,14 +11,14 @@ use thiserror::Error; use crate::{ drawing::{ band::BandTermsegIndex, - bend::{BendIndex, LooseBendWeight}, - dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight}, + bend::{BendIndex, GeneralBendWeight, LooseBendWeight}, + dot::{DotIndex, FixedDotIndex, GeneralDotWeight, LooseDotIndex, LooseDotWeight}, gear::GearIndex, graph::{GetLayer, GetMaybeNet, MakePrimitive}, head::{CaneHead, GetFace, Head}, primitive::GetOtherJoint, rules::AccessRules, - seg::{LoneLooseSegWeight, SeqLooseSegWeight}, + seg::{GeneralSegWeight, LoneLooseSegWeight, SeqLooseSegWeight}, DrawingException, Guide, Infringement, }, layout::{Layout, LayoutEdit}, @@ -98,11 +98,11 @@ impl Draw for Layout { recorder, dot, into, - LoneLooseSegWeight { + LoneLooseSegWeight(GeneralSegWeight { width, layer, maybe_net, - }, + }), ) .map_err(|err| DrawException::CannotFinishIn(into, err.into()))?, ), @@ -111,11 +111,11 @@ impl Draw for Layout { recorder, into.into(), dot, - SeqLooseSegWeight { + SeqLooseSegWeight(GeneralSegWeight { width, layer, maybe_net, - }, + }), ) .map_err(|err| DrawException::CannotFinishIn(into, err.into()))?, ), @@ -279,25 +279,25 @@ impl DrawPrivate for Layout { recorder, head.face(), around, - LooseDotWeight { + LooseDotWeight(GeneralDotWeight { circle: Circle { pos: to, r: width / 2.0, }, layer, maybe_net, - }, - SeqLooseSegWeight { + }), + SeqLooseSegWeight(GeneralSegWeight { width, layer, maybe_net, - }, - LooseBendWeight { + }), + LooseBendWeight(GeneralBendWeight { width, offset, layer, maybe_net, - }, + }), cw, )?; Ok(CaneHead { diff --git a/src/specctra/design.rs b/src/specctra/design.rs index fef3bb1..f386d42 100644 --- a/src/specctra/design.rs +++ b/src/specctra/design.rs @@ -13,10 +13,10 @@ use geo::{point, Point, Rotate}; use crate::{ board::{AccessMesadata, Board}, drawing::{ - dot::FixedDotWeight, + dot::{FixedDotWeight, GeneralDotWeight}, graph::{GetLayer, GetMaybeNet, MakePrimitive}, primitive::MakePrimitiveShape, - seg::FixedSegWeight, + seg::{FixedSegWeight, GeneralSegWeight}, Drawing, }, geometry::{primitive::PrimitiveShape, GetWidth}, @@ -434,11 +434,11 @@ impl SpecctraDesign { board.add_fixed_dot_infringably( recorder, - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle, layer, maybe_net, - }, + }), maybe_pin, ); } @@ -465,50 +465,50 @@ impl SpecctraDesign { // Corners. let dot_1_1 = board.add_poly_fixed_dot_infringably( recorder, - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle: Circle { pos: Self::pos(place, pin, x1, y1), r: 0.5, }, layer, maybe_net, - }, + }), poly, ); let dot_2_1 = board.add_poly_fixed_dot_infringably( recorder, - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle: Circle { pos: Self::pos(place, pin, x2, y1), r: 0.5, }, layer, maybe_net, - }, + }), poly, ); let dot_2_2 = board.add_poly_fixed_dot_infringably( recorder, - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle: Circle { pos: Self::pos(place, pin, x2, y2), r: 0.5, }, layer, maybe_net, - }, + }), poly, ); let dot_1_2 = board.add_poly_fixed_dot_infringably( recorder, - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle: Circle { pos: Self::pos(place, pin, x1, y2), r: 0.5, }, layer, maybe_net, - }, + }), poly, ); // Sides. @@ -516,44 +516,44 @@ impl SpecctraDesign { recorder, dot_1_1, dot_2_1, - FixedSegWeight { + FixedSegWeight(GeneralSegWeight { width: 1.0, layer, maybe_net, - }, + }), poly, ); board.add_poly_fixed_seg_infringably( recorder, dot_2_1, dot_2_2, - FixedSegWeight { + FixedSegWeight(GeneralSegWeight { width: 1.0, layer, maybe_net, - }, + }), poly, ); board.add_poly_fixed_seg_infringably( recorder, dot_2_2, dot_1_2, - FixedSegWeight { + FixedSegWeight(GeneralSegWeight { width: 1.0, layer, maybe_net, - }, + }), poly, ); board.add_poly_fixed_seg_infringably( recorder, dot_1_2, dot_1_1, - FixedSegWeight { + FixedSegWeight(GeneralSegWeight { width: 1.0, layer, maybe_net, - }, + }), poly, ); } @@ -573,14 +573,14 @@ impl SpecctraDesign { let mut prev_pos = Self::pos(place, pin, coords[0].x, coords[0].y); let mut prev_index = board.add_fixed_dot_infringably( recorder, - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle: Circle { pos: prev_pos, r: width / 2.0, }, layer, maybe_net, - }, + }), maybe_pin.clone(), ); @@ -594,14 +594,14 @@ impl SpecctraDesign { let index = board.add_fixed_dot_infringably( recorder, - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle: Circle { pos, r: width / 2.0, }, layer, maybe_net, - }, + }), maybe_pin.clone(), ); @@ -610,11 +610,11 @@ impl SpecctraDesign { recorder, prev_index, index, - FixedSegWeight { + FixedSegWeight(GeneralSegWeight { width, layer, maybe_net, - }, + }), maybe_pin.clone(), ); @@ -643,14 +643,14 @@ impl SpecctraDesign { // add the first coordinate in the wire path as a dot and save its index let mut prev_index = board.add_poly_fixed_dot_infringably( recorder, - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle: Circle { pos: Self::pos(place, pin, coords[0].x, coords[0].y), r: width / 2.0, }, layer, maybe_net, - }, + }), // TODO: This manual retagging shouldn't be necessary, `.into()` should suffice. //GenericIndex::new(poly.petgraph_index()).into(), poly, @@ -660,14 +660,14 @@ impl SpecctraDesign { for coord in coords.iter().skip(1) { let index = board.add_poly_fixed_dot_infringably( recorder, - FixedDotWeight { + FixedDotWeight(GeneralDotWeight { circle: Circle { pos: Self::pos(place, pin, coord.x, coord.y), r: width / 2.0, }, layer, maybe_net, - }, + }), // TODO: This manual retagging shouldn't be necessary, `.into()` should suffice. poly, ); @@ -677,11 +677,11 @@ impl SpecctraDesign { recorder, prev_index, index, - FixedSegWeight { + FixedSegWeight(GeneralSegWeight { width, layer, maybe_net, - }, + }), // TODO: This manual retagging shouldn't be necessary, `.into()` should suffice. poly, );