graph: Store the offset from the bend immediately below in bend weight

This commit is contained in:
Mikolaj Wielgus 2023-12-16 00:04:46 +00:00
parent 294e6c4f72
commit 92834c66c8
4 changed files with 33 additions and 15 deletions

View File

@ -255,6 +255,7 @@ impl<'a> Draw<'a> {
LooseSegWeight { band: head.band() },
LooseBendWeight {
band: head.band(),
offset: 3.0,
cw,
},
)?;

View File

@ -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 {}

View File

@ -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,
}
}

View File

@ -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<LooseDotIndex, LooseDotIndex> for LooseBend<'a> {
fn ends(&self) -> (LooseDotIndex, LooseDotIndex) {
let v = self.adjacents();