From fd73531687a47439586695b2ef4a878b7a95fa79 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Tue, 6 Feb 2024 05:30:53 +0000 Subject: [PATCH] layout: store rotation direction as joint order instead of in weights --- src/draw.rs | 2 +- src/layout/bend.rs | 2 -- src/layout/guide.rs | 9 ++++++++- src/layout/layout.rs | 30 +++++++++++++++--------------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/draw.rs b/src/draw.rs index 047f1f7..a3d13a6 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -231,8 +231,8 @@ impl<'a, R: RulesTrait> Draw<'a, R> { band: head.band(), width, offset, - cw, }, + cw, )?; Ok::(SegbendHead { face: self.layout.primitive(segbend.bend).other_joint(segbend.dot), diff --git a/src/layout/bend.rs b/src/layout/bend.rs index d0298e7..9720295 100644 --- a/src/layout/bend.rs +++ b/src/layout/bend.rs @@ -80,7 +80,6 @@ pub struct FixedBendWeight { pub component: ComponentIndex, pub width: f64, pub offset: f64, - pub cw: bool, } impl_fixed_weight!(FixedBendWeight, FixedBend, FixedBendIndex); @@ -103,7 +102,6 @@ pub struct LooseBendWeight { pub band: BandIndex, pub width: f64, pub offset: f64, - pub cw: bool, } impl GetOffset for LooseBendWeight { diff --git a/src/layout/guide.rs b/src/layout/guide.rs index a4e4ce4..63a52a0 100644 --- a/src/layout/guide.rs +++ b/src/layout/guide.rs @@ -17,6 +17,7 @@ use crate::{ use super::{ graph::GeometryIndex, + primitive::GetJoints, rules::{Conditions, RulesTrait}, segbend::Segbend, }; @@ -166,7 +167,13 @@ impl<'a, R: RulesTrait> Guide<'a, R> { pub fn head_cw(&self, head: &Head) -> Option { if let Head::Segbend(head) = head { - Some(self.layout.primitive(head.segbend.bend).weight().cw) + let joints = self.layout.primitive(head.segbend.bend).joints(); + + if head.face() == joints.0.into() { + Some(false) + } else { + Some(true) + } } else { None } diff --git a/src/layout/layout.rs b/src/layout/layout.rs index c253602..c823804 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -254,6 +254,7 @@ impl Layout { dot_weight: LooseDotWeight, seg_weight: SeqLooseSegWeight, bend_weight: LooseBendWeight, + cw: bool, ) -> Result { let maybe_wraparound = self.wraparoundable(around).wraparound(); let mut infringables = self.this_and_wraparound_bow(around); @@ -268,6 +269,7 @@ impl Layout { dot_weight, seg_weight, bend_weight, + cw, &infringables, )?; @@ -411,26 +413,18 @@ impl Layout { while let Some(rail) = maybe_rail { let rail_primitive = self.primitive(rail); - let cw = rail_primitive.weight().cw; let ends = rail_primitive.joints(); - let inner_conditions = Conditions::from(if let Some(inner) = rail_primitive.inner() { - self.primitive(inner).conditions() - } else { - self.primitive(rail_primitive.core()).conditions() - }); - let rail_conditions = Conditions::from(rail_primitive.conditions()); - let guide = Guide::new(self); let from_head = guide.rear_head(ends.1); let to_head = guide.rear_head(ends.0); if let Some(inner) = rail_primitive.inner() { let from = guide - .head_around_bend_segment(&from_head.into(), inner.into(), !cw, 6.0)? + .head_around_bend_segment(&from_head.into(), inner.into(), true, 6.0)? .end_point(); let to = guide - .head_around_bend_segment(&to_head.into(), inner.into(), cw, 6.0)? + .head_around_bend_segment(&to_head.into(), inner.into(), false, 6.0)? .end_point(); self.move_dot_infringably( ends.0.into(), @@ -441,10 +435,10 @@ impl Layout { } else { let core = rail_primitive.core(); let from = guide - .head_around_dot_segment(&from_head.into(), core.into(), !cw, 6.0)? + .head_around_dot_segment(&from_head.into(), core.into(), true, 6.0)? .end_point(); let to = guide - .head_around_dot_segment(&to_head.into(), core.into(), cw, 6.0)? + .head_around_dot_segment(&to_head.into(), core.into(), false, 6.0)? .end_point(); self.move_dot_infringably( ends.0.into(), @@ -471,6 +465,7 @@ impl Layout { dot_weight: LooseDotWeight, seg_weight: SeqLooseSegWeight, bend_weight: LooseBendWeight, + cw: bool, ) -> Result { self.add_segbend_infringably( from, @@ -478,6 +473,7 @@ impl Layout { dot_weight, seg_weight, bend_weight, + cw, &self.this_and_wraparound_bow(around), ) } @@ -493,6 +489,7 @@ impl Layout { dot_weight: LooseDotWeight, seg_weight: SeqLooseSegWeight, bend_weight: LooseBendWeight, + cw: bool, infringables: &[GeometryIndex], ) -> Result { let seg_to = self.add_dot_infringably(dot_weight, infringables)?; @@ -503,17 +500,20 @@ impl Layout { err })?; - let bend_to = self + let to = self .add_dot_infringably(dot_weight, infringables) .map_err(|err| { self.geometry_with_rtree.remove_seg(seg.into()); self.geometry_with_rtree.remove_dot(seg_to.into()); err })?; + + let (bend_from, bend_to) = if cw { (to, seg_to) } else { (seg_to, to) }; + let bend = self - .add_loose_bend_infringably(seg_to, bend_to, around, bend_weight, infringables) + .add_loose_bend_infringably(bend_from, bend_to, around, bend_weight, infringables) .map_err(|err| { - self.geometry_with_rtree.remove_dot(bend_to.into()); + self.geometry_with_rtree.remove_dot(to.into()); self.geometry_with_rtree.remove_seg(seg.into()); self.geometry_with_rtree.remove_dot(seg_to.into()); err