From 4d5fc25ae3c87a66ec5176f50029412295b36be7 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Thu, 17 Jul 2025 12:28:43 +0200 Subject: [PATCH] refactor(drawing/drawing): Some minor changes to method naming, comments, contracts --- src/drawing/drawing.rs | 21 ++++++++++++++------- src/drawing/guide.rs | 34 ++++++++++++++++++++-------------- src/geometry/edit.rs | 1 - src/router/draw.rs | 16 +++++++++------- 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index c47a18b..915ec57 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -693,6 +693,8 @@ impl Drawing { Ok(cane) } + #[debug_ensures(self.recording_geometry_with_rtree.graph().node_count() == old(self.recording_geometry_with_rtree.graph().node_count()))] + #[debug_ensures(self.recording_geometry_with_rtree.graph().edge_count() == old(self.recording_geometry_with_rtree.graph().edge_count()))] fn update_this_and_outward_bows_intern( &mut self, recorder: &mut DrawingEdit, @@ -710,36 +712,41 @@ impl Drawing { let (from, to, offset) = if let Some(inner) = rail_primitive.inner() { let inner = inner.into(); - let from = self.head_around_bend_segment( + let from = self.guide_for_head_around_bend_segment( &from_head, inner, RotationSense::Counterclockwise, width, )?; - let to = self.head_around_bend_segment( + let to = self.guide_for_head_around_bend_segment( &to_head, inner, RotationSense::Clockwise, width, )?; - let offset = self.head_around_bend_offset(&from_head, inner, width); + let offset = self.guide_for_head_around_bend_offset(&from_head, inner, width); (from, to, offset) } else { let core = rail_primitive.core().into(); - let from = self.head_around_dot_segment( + let from = self.guide_for_head_around_dot_segment( &from_head, core, RotationSense::Counterclockwise, width, )?; - let to = - self.head_around_dot_segment(&to_head, core, RotationSense::Clockwise, width)?; - let offset = self.head_around_dot_offset(&from_head, core, width); + let to = self.guide_for_head_around_dot_segment( + &to_head, + core, + RotationSense::Clockwise, + width, + )?; + let offset = self.guide_for_head_around_dot_offset(&from_head, core, width); (from, to, offset) }; let rail_outer_bows = self.bend_outer_bows(rail); + // Commenting out these two makes the crash go away. self.move_dot_with_infringement_filtering( recorder, joints.0.into(), diff --git a/src/drawing/guide.rs b/src/drawing/guide.rs index 21e78ff..3ce6c4d 100644 --- a/src/drawing/guide.rs +++ b/src/drawing/guide.rs @@ -20,21 +20,21 @@ use super::{ }; pub trait Guide { - fn head_into_dot_segment( + fn guide_for_head_into_dot_segment( &self, head: &Head, into: FixedDotIndex, width: f64, ) -> Result; - fn head_around_dot_segments( + fn guide_for_head_around_dot_segments( &self, head: &Head, around: DotIndex, width: f64, ) -> Result<(Line, Line), NoTangents>; - fn head_around_dot_segment( + fn guide_for_head_around_dot_segment( &self, head: &Head, around: DotIndex, @@ -42,16 +42,16 @@ pub trait Guide { width: f64, ) -> Result; - fn head_around_dot_offset(&self, head: &Head, around: DotIndex, _width: f64) -> f64; + fn guide_for_head_around_dot_offset(&self, head: &Head, around: DotIndex, _width: f64) -> f64; - fn head_around_bend_segments( + fn guide_for_head_around_bend_segments( &self, head: &Head, around: BendIndex, width: f64, ) -> Result<(Line, Line), NoTangents>; - fn head_around_bend_segment( + fn guide_for_head_around_bend_segment( &self, head: &Head, around: BendIndex, @@ -59,7 +59,8 @@ pub trait Guide { width: f64, ) -> Result; - fn head_around_bend_offset(&self, head: &Head, around: BendIndex, _width: f64) -> f64; + fn guide_for_head_around_bend_offset(&self, head: &Head, around: BendIndex, _width: f64) + -> f64; fn head_sense(&self, head: &Head) -> Option; @@ -71,7 +72,7 @@ pub trait Guide { } impl Guide for Drawing { - fn head_into_dot_segment( + fn guide_for_head_into_dot_segment( &self, head: &Head, into: FixedDotIndex, @@ -87,7 +88,7 @@ impl Guide for Drawing { math::tangent_segment(from_circle, from_sense, to_circle, None) } - fn head_around_dot_segments( + fn guide_for_head_around_dot_segments( &self, head: &Head, around: DotIndex, @@ -103,7 +104,7 @@ impl Guide for Drawing { Ok((tangents[0], tangents[1])) } - fn head_around_dot_segment( + fn guide_for_head_around_dot_segment( &self, head: &Head, around: DotIndex, @@ -118,14 +119,14 @@ impl Guide for Drawing { math::tangent_segment(from_circle, from_sense, to_circle, Some(sense)) } - fn head_around_dot_offset(&self, head: &Head, around: DotIndex, _width: f64) -> f64 { + fn guide_for_head_around_dot_offset(&self, head: &Head, around: DotIndex, _width: f64) -> f64 { self.clearance( self.conditions(around.into()).as_ref(), self.conditions(head.face().into()).as_ref(), ) } - fn head_around_bend_segments( + fn guide_for_head_around_bend_segments( &self, head: &Head, around: BendIndex, @@ -141,7 +142,7 @@ impl Guide for Drawing { Ok((tangents[0], tangents[1])) } - fn head_around_bend_segment( + fn guide_for_head_around_bend_segment( &self, head: &Head, around: BendIndex, @@ -156,7 +157,12 @@ impl Guide for Drawing { math::tangent_segment(from_circle, from_sense, to_circle, Some(sense)) } - fn head_around_bend_offset(&self, head: &Head, around: BendIndex, _width: f64) -> f64 { + fn guide_for_head_around_bend_offset( + &self, + head: &Head, + around: BendIndex, + _width: f64, + ) -> f64 { self.clearance( self.conditions(head.face().into()).as_ref(), self.conditions(around.into()).as_ref(), diff --git a/src/geometry/edit.rs b/src/geometry/edit.rs index cd8ca3e..7abfa56 100644 --- a/src/geometry/edit.rs +++ b/src/geometry/edit.rs @@ -71,7 +71,6 @@ impl< edit: &BTreeMap, Option)>, ) { for (index, (old, new)) in edit { - // TODO: Delete `(None, None)`s. match main.entry(*index) { Entry::Vacant(vac) => { vac.insert((old.clone(), new.clone())); diff --git a/src/router/draw.rs b/src/router/draw.rs index bdbd663..314f999 100644 --- a/src/router/draw.rs +++ b/src/router/draw.rs @@ -85,7 +85,7 @@ impl Draw for Layout { ) -> Result { let tangent = self .drawing() - .head_into_dot_segment(&head, into, width) + .guide_for_head_into_dot_segment(&head, into, width) .map_err(Into::::into)?; let (layer, maybe_net) = { @@ -137,12 +137,12 @@ impl Draw for Layout { sense: RotationSense, width: f64, ) -> Result { - let tangent = self - .drawing() - .head_around_dot_segment(&head, around.into(), sense, width)?; + let tangent = + self.drawing() + .guide_for_head_around_dot_segment(&head, around.into(), sense, width)?; let offset = self .drawing() - .head_around_dot_offset(&head, around.into(), width); + .guide_for_head_around_dot_offset(&head, around.into(), width); self.cane_around( recorder, head, @@ -168,8 +168,10 @@ impl Draw for Layout { ) -> Result { let tangent = self .drawing() - .head_around_bend_segment(&head, around, sense, width)?; - let offset = self.drawing().head_around_bend_offset(&head, around, width); + .guide_for_head_around_bend_segment(&head, around, sense, width)?; + let offset = self + .drawing() + .guide_for_head_around_bend_offset(&head, around, width); self.cane_around( recorder,