From 177c8abb1829725ad72e0910791e213dd481901a Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Fri, 15 Aug 2025 23:31:23 +0200 Subject: [PATCH] refactor(drawing/guide): Instead of trait, just impl guide methods on `Drawing` --- crates/topola-egui/src/displayer.rs | 1 - src/drawing/drawing.rs | 1 - src/drawing/guide.rs | 113 +++++----------------------- src/router/draw.rs | 1 - 4 files changed, 20 insertions(+), 96 deletions(-) diff --git a/crates/topola-egui/src/displayer.rs b/crates/topola-egui/src/displayer.rs index ae2e091..cafc206 100644 --- a/crates/topola-egui/src/displayer.rs +++ b/crates/topola-egui/src/displayer.rs @@ -14,7 +14,6 @@ use topola::{ bend::BendIndex, dot::DotIndex, graph::{MakePrimitive, PrimitiveIndex}, - guide::Guide, head::GetFace, primitive::MakePrimitiveShape, }, diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index 05a4119..03e219f 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -20,7 +20,6 @@ use crate::{ dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight}, gear::GearIndex, graph::{GetMaybeNet, IsInLayer, MakePrimitive, PrimitiveIndex, PrimitiveWeight}, - guide::Guide, loose::{GetPrevNextLoose, Loose, LooseIndex}, primitive::{ GenericPrimitive, GetCore, GetJoints, GetLimbs, GetOtherJoint, MakePrimitiveShape, diff --git a/src/drawing/guide.rs b/src/drawing/guide.rs index 293f170..c675f2d 100644 --- a/src/drawing/guide.rs +++ b/src/drawing/guide.rs @@ -19,76 +19,8 @@ use super::{ Drawing, }; -pub trait Guide { - fn guide_for_head_into_dot_segment( - &self, - head: &Head, - into: FixedDotIndex, - width: f64, - ) -> Result; - - fn guide_for_head_around_dot_segments( - &self, - head: &Head, - around: DotIndex, - width: f64, - ) -> Result<(Line, Line), NoTangents>; - - fn guide_for_head_around_dot_segment( - &self, - head: &Head, - around: DotIndex, - sense: RotationSense, - width: f64, - ) -> Result; - - fn guide_for_head_around_dot_offset(&self, head: &Head, around: DotIndex, _width: f64) -> f64; - - fn guide_for_head_around_bend_segments( - &self, - head: &Head, - around: BendIndex, - width: f64, - ) -> Result<(Line, Line), NoTangents>; - - fn guide_for_head_around_bend_segment( - &self, - head: &Head, - around: BendIndex, - sense: RotationSense, - width: f64, - ) -> Result; - - fn guide_for_head_around_bend_offset(&self, head: &Head, around: BendIndex, _width: f64) - -> f64; - - fn head_sense(&self, head: &Head) -> Option; - - fn cane_head(&self, face: LooseDotIndex) -> CaneHead; - - fn rear_head(&self, face: LooseDotIndex) -> Head; - - fn head(&self, face: DotIndex) -> Head; - - fn bend_circle( - &self, - bend: BendIndex, - width: f64, - guide_conditions: Option<&Conditions<'_>>, - ) -> Circle; - - fn dot_circle( - &self, - dot: DotIndex, - width: f64, - guide_conditions: Option<&Conditions<'_>>, - ) -> Circle; - - fn conditions(&self, node: PrimitiveIndex) -> Option>; -} - -impl Guide for Drawing { - fn guide_for_head_into_dot_segment( +impl Drawing { + pub fn guide_for_head_into_dot_segment( &self, head: &Head, into: FixedDotIndex, @@ -104,7 +36,7 @@ impl Guide for Drawing { math::tangent_segment(from_circle, from_sense, to_circle, None) } - fn guide_for_head_around_dot_segments( + pub fn guide_for_head_around_dot_segments( &self, head: &Head, around: DotIndex, @@ -120,7 +52,7 @@ impl Guide for Drawing { Ok((tangents[0], tangents[1])) } - fn guide_for_head_around_dot_segment( + pub fn guide_for_head_around_dot_segment( &self, head: &Head, around: DotIndex, @@ -135,14 +67,19 @@ impl Guide for Drawing { math::tangent_segment(from_circle, from_sense, to_circle, Some(sense)) } - fn guide_for_head_around_dot_offset(&self, head: &Head, around: DotIndex, _width: f64) -> f64 { + pub 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 guide_for_head_around_bend_segments( + pub fn guide_for_head_around_bend_segments( &self, head: &Head, around: BendIndex, @@ -158,7 +95,7 @@ impl Guide for Drawing { Ok((tangents[0], tangents[1])) } - fn guide_for_head_around_bend_segment( + pub fn guide_for_head_around_bend_segment( &self, head: &Head, around: BendIndex, @@ -173,7 +110,7 @@ impl Guide for Drawing { math::tangent_segment(from_circle, from_sense, to_circle, Some(sense)) } - fn guide_for_head_around_bend_offset( + pub fn guide_for_head_around_bend_offset( &self, head: &Head, around: BendIndex, @@ -185,7 +122,7 @@ impl Guide for Drawing { ) } - fn head_sense(&self, head: &Head) -> Option { + pub fn head_sense(&self, head: &Head) -> Option { if let Head::Cane(head) = head { let joints = self.primitive(head.cane.bend).joints(); @@ -199,25 +136,25 @@ impl Guide for Drawing { } } - fn cane_head(&self, face: LooseDotIndex) -> CaneHead { + pub fn cane_head(&self, face: LooseDotIndex) -> CaneHead { CaneHead { face, cane: self.cane(face), } } - fn rear_head(&self, face: LooseDotIndex) -> Head { + pub fn rear_head(&self, face: LooseDotIndex) -> Head { self.head(self.rear(self.cane_head(face))) } - fn head(&self, face: DotIndex) -> Head { + pub fn head(&self, face: DotIndex) -> Head { match face { DotIndex::Fixed(dot) => BareHead { face: dot }.into(), DotIndex::Loose(dot) => self.cane_head(dot).into(), } } - fn dot_circle( + pub fn dot_circle( &self, dot: DotIndex, width: f64, @@ -232,7 +169,7 @@ impl Guide for Drawing { } } - fn bend_circle( + pub fn bend_circle( &self, bend: BendIndex, width: f64, @@ -251,20 +188,10 @@ impl Guide for Drawing { } } - fn conditions(&self, node: PrimitiveIndex) -> Option> { + pub fn conditions(&self, node: PrimitiveIndex) -> Option> { node.primitive(self).conditions() } -} -trait GuidePrivate { - fn clearance(&self, lhs: Option<&Conditions<'_>>, rhs: Option<&Conditions<'_>>) -> f64; - - fn head_circle(&self, head: &Head, width: f64) -> Circle; - - fn rear(&self, head: CaneHead) -> DotIndex; -} - -impl GuidePrivate for Drawing { fn clearance(&self, lhs: Option<&Conditions<'_>>, rhs: Option<&Conditions<'_>>) -> f64 { match (lhs, rhs) { (None, _) | (_, None) => 0.0, diff --git a/src/router/draw.rs b/src/router/draw.rs index 547238d..c65a2f6 100644 --- a/src/router/draw.rs +++ b/src/router/draw.rs @@ -15,7 +15,6 @@ use crate::{ dot::{DotIndex, FixedDotIndex, GeneralDotWeight, LooseDotIndex, LooseDotWeight}, gear::GearIndex, graph::{GetMaybeNet, MakePrimitive}, - guide::Guide, head::{CaneHead, GetFace, Head}, primitive::GetOtherJoint, rules::AccessRules,