refactor(drawing): deduplicate code in update_this_and_outward_bows

This commit is contained in:
Ellen Emilia Anna Zscheile 2025-03-29 15:53:19 +01:00
parent c01c8046bb
commit da6b825ee7
1 changed files with 31 additions and 76 deletions

View File

@ -540,95 +540,50 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
let from_head = self.rear_head(joints.1); let from_head = self.rear_head(joints.1);
let to_head = self.rear_head(joints.0); let to_head = self.rear_head(joints.0);
let rail_width = rail_primitive.width();
if let Some(inner) = rail_primitive.inner() { let (from, to, offset) = if let Some(inner) = rail_primitive.inner() {
let from = self let from = self
.head_around_bend_segment( .head_around_bend_segment(&from_head, inner.into(), true, rail_width)?
&from_head,
inner.into(),
true,
self.primitive(rail).width(),
)?
.end_point(); .end_point();
let to = self let to = self
.head_around_bend_segment( .head_around_bend_segment(&to_head, inner.into(), false, rail_width)?
&to_head,
inner.into(),
false,
self.primitive(rail).width(),
)?
.end_point(); .end_point();
let offset = self.head_around_bend_offset( let offset = self.head_around_bend_offset(&from_head, inner.into(), rail_width);
&from_head, (from, to, offset)
inner.into(),
self.primitive(rail).width(),
);
self.move_dot_with_infringables(
recorder,
joints.0.into(),
from,
Some(&self.bend_outer_bows(rail)),
)?;
self.move_dot_with_infringables(
recorder,
joints.1.into(),
to,
Some(&self.bend_outer_bows(rail)),
)?;
self.shift_bend_with_infringables(
recorder,
rail.into(),
offset,
Some(&self.bend_outer_bows(rail)),
)?;
// Update offsets in case the rule conditions changed.
} else { } else {
let core = rail_primitive.core(); let core = rail_primitive.core();
let from = self let from = self
.head_around_dot_segment( .head_around_dot_segment(&from_head, core.into(), true, rail_width)?
&from_head,
core.into(),
true,
self.primitive(rail).width(),
)?
.end_point(); .end_point();
let to = self let to = self
.head_around_dot_segment( .head_around_dot_segment(&to_head, core.into(), false, rail_width)?
&to_head,
core.into(),
false,
self.primitive(rail).width(),
)?
.end_point(); .end_point();
let offset = self.head_around_dot_offset( let offset = self.head_around_dot_offset(&from_head, core.into(), rail_width);
&from_head, (from, to, offset)
core.into(), };
self.primitive(rail).width(),
);
self.move_dot_with_infringables( self.move_dot_with_infringables(
recorder, recorder,
joints.0.into(), joints.0.into(),
from, from,
Some(&self.bend_outer_bows(rail)), Some(&self.bend_outer_bows(rail)),
)?; )?;
self.move_dot_with_infringables( self.move_dot_with_infringables(
recorder, recorder,
joints.1.into(), joints.1.into(),
to, to,
Some(&self.bend_outer_bows(rail)), Some(&self.bend_outer_bows(rail)),
)?; )?;
self.shift_bend_with_infringables( self.shift_bend_with_infringables(
recorder, recorder,
rail.into(), rail.into(),
offset, offset,
Some(&self.bend_outer_bows(rail)), Some(&self.bend_outer_bows(rail)),
)?; )?;
}
// Update offsets in case the rule conditions changed.
maybe_rail = self.primitive(rail).outer(); maybe_rail = self.primitive(rail).outer();
} }