diff --git a/src/draw.rs b/src/draw.rs index e991042..dbeed5d 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -255,6 +255,7 @@ impl<'a> Draw<'a> { LooseSegWeight { band: head.band() }, LooseBendWeight { band: head.band(), + offset: 3.0, cw, }, )?; diff --git a/src/graph.rs b/src/graph.rs index 5e527f7..8d88c27 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -29,12 +29,10 @@ pub trait GetNet { fn net(&self) -> i64; } -#[enum_dispatch] pub trait GetNetMut { fn net_mut(&mut self) -> &mut i64; } -#[enum_dispatch] pub trait GetBand { fn band(&self) -> usize; } @@ -44,6 +42,10 @@ pub trait GetWidth { fn width(&self) -> f64; } +pub trait GetOffset { + fn offset(&self) -> f64; +} + macro_rules! impl_weight { ($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => { impl Retag for $weight_struct { @@ -243,9 +245,16 @@ impl GetWidth for FixedBendWeight { #[derive(Debug, Clone, Copy, PartialEq)] pub struct LooseBendWeight { pub band: usize, + pub offset: f64, pub cw: bool, } +impl GetOffset for LooseBendWeight { + fn offset(&self) -> f64 { + self.offset + } +} + impl_loose_weight!(LooseBendWeight, LooseBend, LooseBendIndex); impl BendWeight for LooseBendWeight {} diff --git a/src/guide.rs b/src/guide.rs index 9d02588..dbb77dd 100644 --- a/src/guide.rs +++ b/src/guide.rs @@ -7,7 +7,7 @@ use crate::{ math::{self, Circle}, primitive::{GetCore, GetInnerOuter, GetWeight, MakeShape}, rules::{Conditions, Rules}, - shape::ShapeTrait, + shape::{Shape, ShapeTrait}, }; pub struct Guide<'a, 'b> { @@ -134,13 +134,14 @@ impl<'a, 'b> Guide<'a, 'b> { } fn bend_circle(&self, bend: BendIndex, width: f64) -> Circle { - let shape = bend.primitive(self.layout).shape(); + let outer_circle = match bend.primitive(self.layout).shape() { + Shape::Bend(shape) => shape.outer_circle(), + _ => unreachable!(), + }; + Circle { - pos: shape.center(), - r: shape.width() / 2.0 - + width - + 6.0 - + self.rules.ruleset(self.conditions).clearance.min, + pos: outer_circle.pos, + r: outer_circle.r + width, } } diff --git a/src/primitive.rs b/src/primitive.rs index e52a6b4..b5b87c1 100644 --- a/src/primitive.rs +++ b/src/primitive.rs @@ -6,9 +6,9 @@ use petgraph::Direction::{Incoming, Outgoing}; use crate::graph::{ DotIndex, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegWeight, - GenericIndex, GetBand, GetEnds, GetNet, GetNodeIndex, GetWidth, Index, Interior, Label, - LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight, - MakePrimitive, Retag, Weight, + GenericIndex, GetBand, GetEnds, GetNet, GetNodeIndex, GetOffset, GetWidth, Index, Interior, + Label, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, + LooseSegWeight, MakePrimitive, Retag, Weight, }; use crate::layout::Layout; use crate::math::{self, Circle}; @@ -484,11 +484,12 @@ impl_loose_primitive!(LooseBend, LooseBendWeight); impl<'a> LooseBend<'a> { fn inner_radius(&self) -> f64 { - let mut r = 0.0; + let mut r = self.offset(); let mut rail = LooseBendIndex::new(self.index.node_index()); while let Some(inner) = self.primitive(rail).inner() { - r += self.primitive(inner).width(); + let primitive = self.primitive(inner); + r += primitive.width() + primitive.offset(); rail = inner; } @@ -500,7 +501,7 @@ impl<'a> LooseBend<'a> { .weight() .circle; - core_circle.r + r + 3.0 + core_circle.r + r } } @@ -531,6 +532,12 @@ impl<'a> GetWidth for LooseBend<'a> { } } +impl<'a> GetOffset for LooseBend<'a> { + fn offset(&self) -> f64 { + self.weight().offset + } +} + impl<'a> GetEnds for LooseBend<'a> { fn ends(&self) -> (LooseDotIndex, LooseDotIndex) { let v = self.adjacents();