layout: store rotation direction as joint order instead of in weights

This commit is contained in:
Mikolaj Wielgus 2024-02-06 05:30:53 +00:00
parent a395da4740
commit fd73531687
4 changed files with 24 additions and 19 deletions

View File

@ -231,8 +231,8 @@ impl<'a, R: RulesTrait> Draw<'a, R> {
band: head.band(), band: head.band(),
width, width,
offset, offset,
cw,
}, },
cw,
)?; )?;
Ok::<SegbendHead, LayoutException>(SegbendHead { Ok::<SegbendHead, LayoutException>(SegbendHead {
face: self.layout.primitive(segbend.bend).other_joint(segbend.dot), face: self.layout.primitive(segbend.bend).other_joint(segbend.dot),

View File

@ -80,7 +80,6 @@ pub struct FixedBendWeight {
pub component: ComponentIndex, pub component: ComponentIndex,
pub width: f64, pub width: f64,
pub offset: f64, pub offset: f64,
pub cw: bool,
} }
impl_fixed_weight!(FixedBendWeight, FixedBend, FixedBendIndex); impl_fixed_weight!(FixedBendWeight, FixedBend, FixedBendIndex);
@ -103,7 +102,6 @@ pub struct LooseBendWeight {
pub band: BandIndex, pub band: BandIndex,
pub width: f64, pub width: f64,
pub offset: f64, pub offset: f64,
pub cw: bool,
} }
impl GetOffset for LooseBendWeight { impl GetOffset for LooseBendWeight {

View File

@ -17,6 +17,7 @@ use crate::{
use super::{ use super::{
graph::GeometryIndex, graph::GeometryIndex,
primitive::GetJoints,
rules::{Conditions, RulesTrait}, rules::{Conditions, RulesTrait},
segbend::Segbend, segbend::Segbend,
}; };
@ -166,7 +167,13 @@ impl<'a, R: RulesTrait> Guide<'a, R> {
pub fn head_cw(&self, head: &Head) -> Option<bool> { pub fn head_cw(&self, head: &Head) -> Option<bool> {
if let Head::Segbend(head) = head { 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 { } else {
None None
} }

View File

@ -254,6 +254,7 @@ impl<R: RulesTrait> Layout<R> {
dot_weight: LooseDotWeight, dot_weight: LooseDotWeight,
seg_weight: SeqLooseSegWeight, seg_weight: SeqLooseSegWeight,
bend_weight: LooseBendWeight, bend_weight: LooseBendWeight,
cw: bool,
) -> Result<Segbend, LayoutException> { ) -> Result<Segbend, LayoutException> {
let maybe_wraparound = self.wraparoundable(around).wraparound(); let maybe_wraparound = self.wraparoundable(around).wraparound();
let mut infringables = self.this_and_wraparound_bow(around); let mut infringables = self.this_and_wraparound_bow(around);
@ -268,6 +269,7 @@ impl<R: RulesTrait> Layout<R> {
dot_weight, dot_weight,
seg_weight, seg_weight,
bend_weight, bend_weight,
cw,
&infringables, &infringables,
)?; )?;
@ -411,26 +413,18 @@ impl<R: RulesTrait> Layout<R> {
while let Some(rail) = maybe_rail { while let Some(rail) = maybe_rail {
let rail_primitive = self.primitive(rail); let rail_primitive = self.primitive(rail);
let cw = rail_primitive.weight().cw;
let ends = rail_primitive.joints(); 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 guide = Guide::new(self);
let from_head = guide.rear_head(ends.1); let from_head = guide.rear_head(ends.1);
let to_head = guide.rear_head(ends.0); let to_head = guide.rear_head(ends.0);
if let Some(inner) = rail_primitive.inner() { if let Some(inner) = rail_primitive.inner() {
let from = guide 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(); .end_point();
let to = guide 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(); .end_point();
self.move_dot_infringably( self.move_dot_infringably(
ends.0.into(), ends.0.into(),
@ -441,10 +435,10 @@ impl<R: RulesTrait> Layout<R> {
} else { } else {
let core = rail_primitive.core(); let core = rail_primitive.core();
let from = guide 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(); .end_point();
let to = guide 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(); .end_point();
self.move_dot_infringably( self.move_dot_infringably(
ends.0.into(), ends.0.into(),
@ -471,6 +465,7 @@ impl<R: RulesTrait> Layout<R> {
dot_weight: LooseDotWeight, dot_weight: LooseDotWeight,
seg_weight: SeqLooseSegWeight, seg_weight: SeqLooseSegWeight,
bend_weight: LooseBendWeight, bend_weight: LooseBendWeight,
cw: bool,
) -> Result<Segbend, LayoutException> { ) -> Result<Segbend, LayoutException> {
self.add_segbend_infringably( self.add_segbend_infringably(
from, from,
@ -478,6 +473,7 @@ impl<R: RulesTrait> Layout<R> {
dot_weight, dot_weight,
seg_weight, seg_weight,
bend_weight, bend_weight,
cw,
&self.this_and_wraparound_bow(around), &self.this_and_wraparound_bow(around),
) )
} }
@ -493,6 +489,7 @@ impl<R: RulesTrait> Layout<R> {
dot_weight: LooseDotWeight, dot_weight: LooseDotWeight,
seg_weight: SeqLooseSegWeight, seg_weight: SeqLooseSegWeight,
bend_weight: LooseBendWeight, bend_weight: LooseBendWeight,
cw: bool,
infringables: &[GeometryIndex], infringables: &[GeometryIndex],
) -> Result<Segbend, LayoutException> { ) -> Result<Segbend, LayoutException> {
let seg_to = self.add_dot_infringably(dot_weight, infringables)?; let seg_to = self.add_dot_infringably(dot_weight, infringables)?;
@ -503,17 +500,20 @@ impl<R: RulesTrait> Layout<R> {
err err
})?; })?;
let bend_to = self let to = self
.add_dot_infringably(dot_weight, infringables) .add_dot_infringably(dot_weight, infringables)
.map_err(|err| { .map_err(|err| {
self.geometry_with_rtree.remove_seg(seg.into()); self.geometry_with_rtree.remove_seg(seg.into());
self.geometry_with_rtree.remove_dot(seg_to.into()); self.geometry_with_rtree.remove_dot(seg_to.into());
err err
})?; })?;
let (bend_from, bend_to) = if cw { (to, seg_to) } else { (seg_to, to) };
let bend = self 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| { .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_seg(seg.into());
self.geometry_with_rtree.remove_dot(seg_to.into()); self.geometry_with_rtree.remove_dot(seg_to.into());
err err