From 17ea07ab7bf48279607cf574904249eeb7734c3f Mon Sep 17 00:00:00 2001 From: Alain Emilia Anna Zscheile Date: Fri, 3 Jan 2025 01:44:06 +0100 Subject: [PATCH] refactor(geometry): Access*Weight shouldn't take a generic arg; impl automatically --- src/drawing/bend.rs | 4 --- src/drawing/dot.rs | 6 +--- src/drawing/drawing.rs | 10 +++---- src/drawing/seg.rs | 5 ---- src/geometry/edit.rs | 12 ++++---- src/geometry/geometry.rs | 44 +++++++++++++++++----------- src/geometry/recording_with_rtree.rs | 18 ++++++------ src/geometry/with_rtree.rs | 33 +++++++++++---------- 8 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/drawing/bend.rs b/src/drawing/bend.rs index 119d9b3..637ae99 100644 --- a/src/drawing/bend.rs +++ b/src/drawing/bend.rs @@ -73,8 +73,6 @@ impl TryFrom for BendWeight { } } -impl AccessBendWeight for BendWeight {} - #[derive(Debug, Clone, Copy, PartialEq)] pub struct FixedBendWeight { pub width: f64, @@ -84,7 +82,6 @@ pub struct FixedBendWeight { } impl_fixed_weight!(FixedBendWeight, FixedBend, FixedBendIndex); -impl AccessBendWeight for FixedBendWeight {} impl GetOffset for FixedBendWeight { fn offset(&self) -> f64 { @@ -131,4 +128,3 @@ impl GetWidth for LooseBendWeight { } impl_loose_weight!(LooseBendWeight, LooseBend, LooseBendIndex); -impl AccessBendWeight for LooseBendWeight {} diff --git a/src/drawing/dot.rs b/src/drawing/dot.rs index 4e7c393..87ab230 100644 --- a/src/drawing/dot.rs +++ b/src/drawing/dot.rs @@ -14,7 +14,7 @@ use crate::{ rules::AccessRules, Drawing, }, - geometry::{AccessDotWeight, GetSetPos, GetWidth}, + geometry::{GetSetPos, GetWidth}, graph::{GenericIndex, GetPetgraphIndex}, math::Circle, }; @@ -75,8 +75,6 @@ impl TryFrom for DotWeight { } } -impl AccessDotWeight for DotWeight {} - #[derive(Debug, Clone, Copy, PartialEq)] pub struct FixedDotWeight { pub circle: Circle, @@ -85,7 +83,6 @@ pub struct FixedDotWeight { } impl_fixed_weight!(FixedDotWeight, FixedDot, FixedDotIndex); -impl AccessDotWeight for FixedDotWeight {} impl GetSetPos for FixedDotWeight { fn pos(&self) -> Point { @@ -111,7 +108,6 @@ pub struct LooseDotWeight { } impl_loose_weight!(LooseDotWeight, LooseDot, LooseDotIndex); -impl AccessDotWeight for LooseDotWeight {} impl GetSetPos for LooseDotWeight { fn pos(&self) -> Point { diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index e54985c..72fbf86 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -211,7 +211,7 @@ impl Drawing { #[debug_ensures(ret.is_ok() -> self.recording_geometry_with_rtree.graph().node_count() == old(self.recording_geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(ret.is_err() -> self.recording_geometry_with_rtree.graph().node_count() == old(self.recording_geometry_with_rtree.graph().node_count()))] - fn add_dot_with_infringables + GetLayer>( + fn add_dot_with_infringables + GetLayer>( &mut self, recorder: &mut DrawingEdit, weight: W, @@ -286,7 +286,7 @@ impl Drawing { #[debug_ensures(ret.is_ok() -> self.recording_geometry_with_rtree.graph().edge_count() >= old(self.recording_geometry_with_rtree.graph().edge_count() + 2))] #[debug_ensures(ret.is_err() -> self.recording_geometry_with_rtree.graph().node_count() == old(self.recording_geometry_with_rtree.graph().node_count()))] #[debug_ensures(ret.is_err() -> self.recording_geometry_with_rtree.graph().edge_count() == old(self.recording_geometry_with_rtree.graph().edge_count()))] - fn add_seg_with_infringables + GetLayer>( + fn add_seg_with_infringables + GetLayer>( &mut self, recorder: &mut DrawingEdit, from: DotIndex, @@ -373,7 +373,7 @@ impl Drawing { #[debug_ensures(ret.is_err() -> self.recording_geometry_with_rtree.graph().node_count() == old(self.recording_geometry_with_rtree.graph().node_count()))] #[debug_ensures(ret.is_ok() -> self.recording_geometry_with_rtree.graph().edge_count() == old(self.recording_geometry_with_rtree.graph().edge_count() + 3))] #[debug_ensures(ret.is_err() -> self.recording_geometry_with_rtree.graph().edge_count() == old(self.recording_geometry_with_rtree.graph().edge_count()))] - fn add_core_bend_with_infringables + GetLayer>( + fn add_core_bend_with_infringables + GetLayer>( &mut self, recorder: &mut DrawingEdit, from: DotIndex, @@ -848,7 +848,7 @@ impl Drawing { impl Drawing { #[debug_ensures(self.recording_geometry_with_rtree.graph().node_count() == old(self.recording_geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(self.recording_geometry_with_rtree.graph().edge_count() == old(self.recording_geometry_with_rtree.graph().edge_count()))] - fn add_dot_infringably + GetLayer>( + fn add_dot_infringably + GetLayer>( &mut self, recorder: &mut DrawingEdit, weight: W, @@ -861,7 +861,7 @@ impl Drawing { #[debug_ensures(self.recording_geometry_with_rtree.graph().node_count() == old(self.recording_geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(self.recording_geometry_with_rtree.graph().edge_count() == old(self.recording_geometry_with_rtree.graph().edge_count() + 2))] - fn add_seg_infringably + GetLayer>( + fn add_seg_infringably + GetLayer>( &mut self, recorder: &mut DrawingEdit, from: DotIndex, diff --git a/src/drawing/seg.rs b/src/drawing/seg.rs index 5d35507..67f407a 100644 --- a/src/drawing/seg.rs +++ b/src/drawing/seg.rs @@ -79,8 +79,6 @@ impl TryFrom for SegWeight { } } -impl AccessSegWeight for SegWeight {} - #[derive(Debug, Clone, Copy, PartialEq)] pub struct FixedSegWeight { pub width: f64, @@ -89,7 +87,6 @@ pub struct FixedSegWeight { } impl_fixed_weight!(FixedSegWeight, FixedSeg, FixedSegIndex); -impl AccessSegWeight for FixedSegWeight {} impl GetWidth for FixedSegWeight { fn width(&self) -> f64 { @@ -105,7 +102,6 @@ pub struct LoneLooseSegWeight { } impl_loose_weight!(LoneLooseSegWeight, LoneLooseSeg, LoneLooseSegIndex); -impl AccessSegWeight for LoneLooseSegWeight {} impl GetWidth for LoneLooseSegWeight { fn width(&self) -> f64 { @@ -121,7 +117,6 @@ pub struct SeqLooseSegWeight { } impl_loose_weight!(SeqLooseSegWeight, SeqLooseSeg, SeqLooseSegIndex); -impl AccessSegWeight for SeqLooseSegWeight {} impl GetWidth for SeqLooseSegWeight { fn width(&self) -> f64 { diff --git a/src/geometry/edit.rs b/src/geometry/edit.rs index a2013f4..a52e0ce 100644 --- a/src/geometry/edit.rs +++ b/src/geometry/edit.rs @@ -13,9 +13,9 @@ use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetWidth}; pub trait ApplyGeometryEdit< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, + DW: AccessDotWeight + Into + GetLayer, + SW: AccessSegWeight + Into + GetLayer, + BW: AccessBendWeight + Into + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, DI: GetPetgraphIndex + Into + Eq + Ord + Copy, @@ -38,9 +38,9 @@ pub struct GeometryEdit { impl< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, + DW: AccessDotWeight + Into + GetLayer, + SW: AccessSegWeight + Into + GetLayer, + BW: AccessBendWeight + Into + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, DI: GetPetgraphIndex + Into + Eq + Ord + Copy, diff --git a/src/geometry/geometry.rs b/src/geometry/geometry.rs index 5610fe1..e7061c0 100644 --- a/src/geometry/geometry.rs +++ b/src/geometry/geometry.rs @@ -66,9 +66,14 @@ pub enum GenericNode { Compound(C), } -pub trait AccessDotWeight: GetSetPos + GetWidth + Into + Copy {} -pub trait AccessSegWeight: GetWidth + Into + Copy {} -pub trait AccessBendWeight: SetOffset + GetWidth + Into + Copy {} +pub trait AccessDotWeight: GetSetPos + GetWidth + Copy {} +impl AccessDotWeight for T {} + +pub trait AccessSegWeight: GetWidth + Copy {} +impl AccessSegWeight for T {} + +pub trait AccessBendWeight: SetOffset + GetWidth + Copy {} +impl AccessBendWeight for T {} #[derive(Debug, Getters)] pub struct Geometry { @@ -86,9 +91,9 @@ pub struct Geometry { impl< PW: GetWidth + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight, - SW: AccessSegWeight, - BW: AccessBendWeight, + DW: AccessDotWeight + Into, + SW: AccessSegWeight + Into, + BW: AccessBendWeight + Into, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Copy, DI: GetPetgraphIndex + Into + Copy, @@ -111,11 +116,11 @@ impl< } } - pub fn add_dot>(&mut self, weight: W) -> GenericIndex { + pub fn add_dot>(&mut self, weight: W) -> GenericIndex { GenericIndex::::new(self.graph.add_node(GenericNode::Primitive(weight.into()))) } - pub(super) fn add_dot_at_index>( + pub(super) fn add_dot_at_index>( &mut self, dot: GenericIndex, weight: W, @@ -124,7 +129,7 @@ impl< .update_node(dot.petgraph_index(), GenericNode::Primitive(weight.into())); } - pub fn add_seg>( + pub fn add_seg>( &mut self, from: DI, to: DI, @@ -136,7 +141,7 @@ impl< seg } - pub(super) fn add_seg_at_index>( + pub(super) fn add_seg_at_index>( &mut self, seg: GenericIndex, from: DI, @@ -148,7 +153,12 @@ impl< self.init_seg_joints(seg, from, to); } - fn init_seg_joints>(&mut self, seg: GenericIndex, from: DI, to: DI) { + fn init_seg_joints>( + &mut self, + seg: GenericIndex, + from: DI, + to: DI, + ) { self.graph.update_edge( from.petgraph_index(), seg.petgraph_index(), @@ -161,7 +171,7 @@ impl< ); } - pub fn add_bend>( + pub fn add_bend>( &mut self, from: DI, to: DI, @@ -174,7 +184,7 @@ impl< bend } - pub(super) fn add_bend_at_index>( + pub(super) fn add_bend_at_index>( &mut self, bend: GenericIndex, from: DI, @@ -192,7 +202,7 @@ impl< .update_node(compound.petgraph_index(), GenericNode::Compound(weight)); } - fn init_bend_joints_and_core>( + fn init_bend_joints_and_core>( &mut self, bend: GenericIndex, from: DI, @@ -556,9 +566,9 @@ impl< impl< PW: GetWidth + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight, - SW: AccessSegWeight, - BW: AccessBendWeight, + DW: AccessDotWeight + Into, + SW: AccessSegWeight + Into, + BW: AccessBendWeight + Into, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Copy, DI: GetPetgraphIndex + Into + Copy, diff --git a/src/geometry/recording_with_rtree.rs b/src/geometry/recording_with_rtree.rs index ab213ee..35134b6 100644 --- a/src/geometry/recording_with_rtree.rs +++ b/src/geometry/recording_with_rtree.rs @@ -28,9 +28,9 @@ pub struct RecordingGeometryWithRtree { impl< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, + DW: AccessDotWeight + Into + GetLayer, + SW: AccessSegWeight + Into + GetLayer, + BW: AccessBendWeight + Into + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, DI: GetPetgraphIndex + Into + Eq + Ord + Copy, @@ -46,7 +46,7 @@ impl< } } - pub fn add_dot + GetLayer>( + pub fn add_dot + GetLayer>( &mut self, recorder: &mut GeometryEdit, weight: W, @@ -67,7 +67,7 @@ impl< dot } - pub fn add_seg + GetLayer>( + pub fn add_seg + GetLayer>( &mut self, recorder: &mut GeometryEdit, from: DI, @@ -93,7 +93,7 @@ impl< seg } - pub fn add_bend + GetLayer>( + pub fn add_bend + GetLayer>( &mut self, recorder: &mut GeometryEdit, from: DI, @@ -339,9 +339,9 @@ fn edit_remove_from_map( impl< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, + DW: AccessDotWeight + Into + GetLayer, + SW: AccessSegWeight + Into + GetLayer, + BW: AccessBendWeight + Into + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, DI: GetPetgraphIndex + Into + Eq + Ord + Copy, diff --git a/src/geometry/with_rtree.rs b/src/geometry/with_rtree.rs index 6274dde..b0aad4a 100644 --- a/src/geometry/with_rtree.rs +++ b/src/geometry/with_rtree.rs @@ -50,9 +50,9 @@ pub struct GeometryWithRtree { #[debug_invariant(self.geometry.graph().node_count() == self.rtree.size())] impl< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, + DW: AccessDotWeight + Into + GetLayer, + SW: AccessSegWeight + Into + GetLayer, + BW: AccessBendWeight + Into + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + PartialEq + Copy, DI: GetPetgraphIndex + Into + Copy, @@ -68,7 +68,10 @@ impl< } } - pub fn add_dot + GetLayer>(&mut self, weight: W) -> GenericIndex + pub fn add_dot + GetLayer>( + &mut self, + weight: W, + ) -> GenericIndex where GenericIndex: Into, { @@ -77,7 +80,7 @@ impl< dot } - pub(super) fn add_dot_at_index + GetLayer>( + pub(super) fn add_dot_at_index + GetLayer>( &mut self, dot: DI, weight: W, @@ -87,7 +90,7 @@ impl< self.init_dot_bbox(dot); } - pub fn add_seg + GetLayer>( + pub fn add_seg + GetLayer>( &mut self, from: DI, to: DI, @@ -101,7 +104,7 @@ impl< seg } - pub(super) fn add_seg_at_index + GetLayer>( + pub(super) fn add_seg_at_index + GetLayer>( &mut self, seg: SI, from: DI, @@ -117,7 +120,7 @@ impl< self.init_seg_bbox(seg); } - pub fn add_bend + GetLayer>( + pub fn add_bend + GetLayer>( &mut self, from: DI, to: DI, @@ -132,7 +135,7 @@ impl< bend } - pub(super) fn add_bend_at_index + GetLayer>( + pub(super) fn add_bend_at_index + GetLayer>( &mut self, bend: BI, from: DI, @@ -260,9 +263,9 @@ impl< impl< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, + DW: AccessDotWeight + Into + GetLayer, + SW: AccessSegWeight + Into + GetLayer, + BW: AccessBendWeight + Into + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + PartialEq + Copy, DI: GetPetgraphIndex + Into + Copy, @@ -390,9 +393,9 @@ impl< impl< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, + DW: AccessDotWeight + Into + GetLayer, + SW: AccessSegWeight + Into + GetLayer, + BW: AccessBendWeight + Into + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + PartialEq + Copy, DI: GetPetgraphIndex + Into + Copy,