diff --git a/src/draw.rs b/src/draw.rs index dc8a0a4..0707fc7 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -5,13 +5,13 @@ use thiserror::Error; use crate::{ geometry::GetWidth, layout::{ - bend::{BendIndex, LooseBendWeight}, - dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight}, + bend::{BendGeodata, BendIndex, LooseBendWeight}, + dot::{DotGeodata, DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight}, graph::{GetBandIndex, MakePrimitive}, guide::{Guide, Head, HeadTrait, SegbendHead}, primitive::GetOtherJoint, rules::RulesTrait, - seg::{LoneLooseSegWeight, SeqLooseSegWeight}, + seg::{LoneLooseSegWeight, SegGeodata, SeqLooseSegWeight}, Infringement, Layout, LayoutException, }, math::{Circle, NoTangents}, @@ -67,7 +67,9 @@ impl<'a, R: RulesTrait> Draw<'a, R> { into.into(), LoneLooseSegWeight { band: head.band(), - width: self.layout.band(head.band()).width(), + geodata: SegGeodata { + width: self.layout.band(head.band()).width(), + }, }, ) .map_err(|err| DrawException::CannotFinishIn(into, err.into()))?; @@ -79,7 +81,9 @@ impl<'a, R: RulesTrait> Draw<'a, R> { dot, SeqLooseSegWeight { band: head.band(), - width: self.layout.band(head.band()).width(), + geodata: SegGeodata { + width: self.layout.band(head.band()).width(), + }, }, ) .map_err(|err| DrawException::CannotFinishIn(into, err.into()))?; @@ -220,19 +224,20 @@ impl<'a, R: RulesTrait> Draw<'a, R> { around, LooseDotWeight { band: head.band(), - circle: Circle { - pos: to, - r: width / 2.0, + geodata: DotGeodata { + circle: Circle { + pos: to, + r: width / 2.0, + }, }, }, SeqLooseSegWeight { band: head.band(), - width, + geodata: SegGeodata { width }, }, LooseBendWeight { band: head.band(), - width, - offset, + geodata: BendGeodata { width, offset }, }, cw, )?; diff --git a/src/dsn/design.rs b/src/dsn/design.rs index 80a44ac..03ae632 100644 --- a/src/dsn/design.rs +++ b/src/dsn/design.rs @@ -1,7 +1,11 @@ use std::collections::HashMap; use crate::{ - layout::{dot::FixedDotWeight, seg::FixedSegWeight, Layout}, + layout::{ + dot::{DotGeodata, FixedDotWeight}, + seg::{FixedSegWeight, SegGeodata}, + Layout, + }, math::Circle, }; @@ -80,7 +84,7 @@ impl DsnDesign { layout .add_fixed_dot(FixedDotWeight { continent: continent100, - circle, + geodata: DotGeodata { circle }, }) .unwrap(); } @@ -115,7 +119,10 @@ impl DsnDesign { }; layout - .add_fixed_dot(FixedDotWeight { continent, circle }) + .add_fixed_dot(FixedDotWeight { + continent, + geodata: DotGeodata { circle }, + }) .unwrap() }) .collect(); @@ -128,13 +135,15 @@ impl DsnDesign { let mut prev_index = layout .add_fixed_dot(FixedDotWeight { continent, - circle: Circle { - pos: ( - wire.path.coords[0].x as f64 / 100.0, - -wire.path.coords[0].y as f64 / 100.0, - ) - .into(), - r: wire.path.width as f64 / 100.0, + geodata: DotGeodata { + circle: Circle { + pos: ( + wire.path.coords[0].x as f64 / 100.0, + -wire.path.coords[0].y as f64 / 100.0, + ) + .into(), + r: wire.path.width as f64 / 100.0, + }, }, }) .unwrap(); @@ -144,9 +153,11 @@ impl DsnDesign { let index = layout .add_fixed_dot(FixedDotWeight { continent, - circle: Circle { - pos: (coord.x as f64 / 100.0, -coord.y as f64 / 100.0).into(), - r: wire.path.width as f64 / 100.0, + geodata: DotGeodata { + circle: Circle { + pos: (coord.x as f64 / 100.0, -coord.y as f64 / 100.0).into(), + r: wire.path.width as f64 / 100.0, + }, }, }) .unwrap(); @@ -158,7 +169,9 @@ impl DsnDesign { index, FixedSegWeight { continent, - width: wire.path.width as f64 / 100.0, + geodata: SegGeodata { + width: wire.path.width as f64 / 100.0, + }, }, ) .unwrap(); diff --git a/src/layout/bend.rs b/src/layout/bend.rs index bef35bf..ad8d6fe 100644 --- a/src/layout/bend.rs +++ b/src/layout/bend.rs @@ -45,6 +45,12 @@ impl TryFrom for BendIndex { } } +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct BendGeodata { + pub width: f64, + pub offset: f64, +} + #[enum_dispatch(GetOffset, SetOffset, GetWidth)] #[derive(Debug, Clone, Copy, PartialEq)] pub enum BendWeight { @@ -78,8 +84,7 @@ impl BendWeightTrait for BendWeight {} #[derive(Debug, Clone, Copy, PartialEq)] pub struct FixedBendWeight { pub continent: ContinentIndex, - pub width: f64, - pub offset: f64, + pub geodata: BendGeodata, } impl_fixed_weight!(FixedBendWeight, FixedBend, FixedBendIndex); @@ -87,44 +92,43 @@ impl BendWeightTrait for FixedBendWeight {} impl GetOffset for FixedBendWeight { fn offset(&self) -> f64 { - self.offset + self.geodata.offset } } impl SetOffset for FixedBendWeight { fn set_offset(&mut self, offset: f64) { - self.offset = offset + self.geodata.offset = offset } } impl GetWidth for FixedBendWeight { fn width(&self) -> f64 { - self.width + self.geodata.width } } #[derive(Debug, Clone, Copy, PartialEq)] pub struct LooseBendWeight { pub band: BandIndex, - pub width: f64, - pub offset: f64, + pub geodata: BendGeodata, } impl GetOffset for LooseBendWeight { fn offset(&self) -> f64 { - self.offset + self.geodata.offset } } impl SetOffset for LooseBendWeight { fn set_offset(&mut self, offset: f64) { - self.offset = offset + self.geodata.offset = offset } } impl GetWidth for LooseBendWeight { fn width(&self) -> f64 { - self.width + self.geodata.width } } diff --git a/src/layout/dot.rs b/src/layout/dot.rs index 0136c2d..d5149d0 100644 --- a/src/layout/dot.rs +++ b/src/layout/dot.rs @@ -47,6 +47,11 @@ impl TryFrom for DotIndex { } } +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct DotGeodata { + pub circle: Circle, +} + #[enum_dispatch(GetPos, SetPos, GetWidth)] #[derive(Debug, Clone, Copy, PartialEq)] pub enum DotWeight { @@ -80,7 +85,7 @@ impl DotWeightTrait for DotWeight {} #[derive(Debug, Clone, Copy, PartialEq)] pub struct FixedDotWeight { pub continent: ContinentIndex, - pub circle: Circle, + pub geodata: DotGeodata, } impl_fixed_weight!(FixedDotWeight, FixedDot, FixedDotIndex); @@ -88,26 +93,26 @@ impl DotWeightTrait for FixedDotWeight {} impl GetPos for FixedDotWeight { fn pos(&self) -> Point { - self.circle.pos + self.geodata.circle.pos } } impl SetPos for FixedDotWeight { fn set_pos(&mut self, pos: Point) { - self.circle.pos = pos + self.geodata.circle.pos = pos } } impl GetWidth for FixedDotWeight { fn width(&self) -> f64 { - self.circle.r * 2.0 + self.geodata.circle.r * 2.0 } } #[derive(Debug, Clone, Copy, PartialEq)] pub struct LooseDotWeight { pub band: BandIndex, - pub circle: Circle, + pub geodata: DotGeodata, } impl_loose_weight!(LooseDotWeight, LooseDot, LooseDotIndex); @@ -115,18 +120,18 @@ impl DotWeightTrait for LooseDotWeight {} impl GetPos for LooseDotWeight { fn pos(&self) -> Point { - self.circle.pos + self.geodata.circle.pos } } impl SetPos for LooseDotWeight { fn set_pos(&mut self, pos: Point) { - self.circle.pos = pos + self.geodata.circle.pos = pos } } impl GetWidth for LooseDotWeight { fn width(&self) -> f64 { - self.circle.r * 2.0 + self.geodata.circle.r * 2.0 } } diff --git a/src/layout/guide.rs b/src/layout/guide.rs index f545c26..86d6c32 100644 --- a/src/layout/guide.rs +++ b/src/layout/guide.rs @@ -85,7 +85,7 @@ impl<'a, R: RulesTrait> Guide<'a, R> { ) -> Result { let from_circle = self.head_circle(head, width); let to_circle = Circle { - pos: self.layout.primitive(into).weight().circle.pos, + pos: self.layout.primitive(into).weight().geodata.circle.pos, r: 0.0, }; diff --git a/src/layout/primitive.rs b/src/layout/primitive.rs index 4c7a97b..022d324 100644 --- a/src/layout/primitive.rs +++ b/src/layout/primitive.rs @@ -474,7 +474,7 @@ impl<'a, R: RulesTrait> GetLimbs for LooseBend<'a, R> {} impl<'a, R: RulesTrait> GetOffset for LooseBend<'a, R> { fn offset(&self) -> f64 { - self.weight().offset + self.weight().offset() } } diff --git a/src/layout/seg.rs b/src/layout/seg.rs index 0478fa1..072aceb 100644 --- a/src/layout/seg.rs +++ b/src/layout/seg.rs @@ -48,6 +48,11 @@ impl TryFrom for SegIndex { } } +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct SegGeodata { + pub width: f64, +} + #[enum_dispatch(GetWidth)] #[derive(Debug, Clone, Copy, PartialEq)] pub enum SegWeight { @@ -84,7 +89,7 @@ impl SegWeightTrait for SegWeight {} #[derive(Debug, Clone, Copy, PartialEq)] pub struct FixedSegWeight { pub continent: ContinentIndex, - pub width: f64, + pub geodata: SegGeodata, } impl_fixed_weight!(FixedSegWeight, FixedSeg, FixedSegIndex); @@ -92,14 +97,14 @@ impl SegWeightTrait for FixedSegWeight {} impl GetWidth for FixedSegWeight { fn width(&self) -> f64 { - self.width + self.geodata.width } } #[derive(Debug, Clone, Copy, PartialEq)] pub struct LoneLooseSegWeight { pub band: BandIndex, - pub width: f64, + pub geodata: SegGeodata, } impl_loose_weight!(LoneLooseSegWeight, LoneLooseSeg, LoneLooseSegIndex); @@ -107,14 +112,14 @@ impl SegWeightTrait for LoneLooseSegWeight {} impl GetWidth for LoneLooseSegWeight { fn width(&self) -> f64 { - self.width + self.geodata.width } } #[derive(Debug, Clone, Copy, PartialEq)] pub struct SeqLooseSegWeight { pub band: BandIndex, - pub width: f64, + pub geodata: SegGeodata, } impl_loose_weight!(SeqLooseSegWeight, SeqLooseSeg, SeqLooseSegIndex); @@ -122,6 +127,6 @@ impl SegWeightTrait for SeqLooseSegWeight {} impl GetWidth for SeqLooseSegWeight { fn width(&self) -> f64 { - self.width + self.geodata.width } }