From 806742736ae6c623463a90b8e5a029676246a9df Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Wed, 3 Jul 2024 13:40:37 +0200 Subject: [PATCH] cleanup: get rid of `*Trait` names for traits, use verbs and sentences --- src/autorouter/autoroute.rs | 6 +- src/autorouter/autorouter.rs | 6 +- src/autorouter/invoker.rs | 12 ++-- src/autorouter/place_via.rs | 4 +- src/autorouter/ratsnest.rs | 6 +- src/autorouter/selection.rs | 14 ++-- src/bin/topola-egui/app.rs | 8 +-- src/bin/topola-egui/layers.rs | 6 +- src/bin/topola-egui/overlay.rs | 17 +++-- src/bin/topola-egui/painter.rs | 4 +- src/bin/topola-egui/viewport.rs | 4 +- src/bin/topola-sdl2-demo/main.rs | 12 ++-- src/bin/topola-sdl2-demo/painter.rs | 4 +- src/board/board.rs | 8 +-- src/board/mesadata.rs | 4 +- src/drawing/bend.rs | 10 +-- src/drawing/cane.rs | 4 +- src/drawing/collect.rs | 6 +- src/drawing/dot.rs | 10 +-- src/drawing/drawing.rs | 28 ++++---- src/drawing/graph.rs | 6 +- src/drawing/guide.rs | 12 ++-- src/drawing/head.rs | 20 +++--- src/drawing/loose.rs | 14 ++-- src/drawing/primitive.rs | 108 ++++++++++++++-------------- src/drawing/rules.rs | 2 +- src/drawing/seg.rs | 12 ++-- src/drawing/wraparoundable.rs | 12 ++-- src/geometry/compound.rs | 2 +- src/geometry/geometry.rs | 36 +++++----- src/geometry/poly.rs | 4 +- src/geometry/primitive.rs | 20 +++--- src/geometry/shape.rs | 4 +- src/geometry/with_rtree.rs | 40 +++++------ src/layout/layout.rs | 8 +-- src/layout/via.rs | 12 ++-- src/layout/zone.rs | 16 ++--- src/router/draw.rs | 8 +-- src/router/navmesh.rs | 6 +- src/router/route.rs | 10 +-- src/router/router.rs | 18 ++--- src/router/trace.rs | 12 ++-- src/router/tracer.rs | 6 +- src/specctra/design.rs | 2 +- src/specctra/mesadata.rs | 8 +-- tests/common/mod.rs | 8 +-- tests/multilayer.rs | 2 +- 47 files changed, 295 insertions(+), 286 deletions(-) diff --git a/src/autorouter/autoroute.rs b/src/autorouter/autoroute.rs index 7ba1543..52e752c 100644 --- a/src/autorouter/autoroute.rs +++ b/src/autorouter/autoroute.rs @@ -5,7 +5,7 @@ use crate::{ invoker::{GetMaybeNavmesh, GetMaybeTrace}, Autorouter, AutorouterError, AutorouterStatus, }, - board::mesadata::MesadataTrait, + board::mesadata::AccessMesadata, router::{navmesh::Navmesh, route::Route, trace::Trace, Router, RouterStatus}, }; @@ -17,7 +17,7 @@ pub struct Autoroute { impl Autoroute { pub fn new( - autorouter: &mut Autorouter, + autorouter: &mut Autorouter, ratlines: impl IntoIterator> + 'static, ) -> Result { let mut ratlines_iter = Box::new(ratlines.into_iter()); @@ -38,7 +38,7 @@ impl Autoroute { Ok(this) } - pub fn step( + pub fn step( &mut self, autorouter: &mut Autorouter, ) -> Result { diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index 012191a..fec2c5a 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -9,7 +9,7 @@ use crate::{ ratsnest::{Ratsnest, RatvertexIndex}, selection::Selection, }, - board::{mesadata::MesadataTrait, Board}, + board::{mesadata::AccessMesadata, Board}, drawing::{dot::FixedDotIndex, Infringement}, layout::via::ViaWeight, router::{navmesh::NavmeshError, RouterError}, @@ -33,12 +33,12 @@ pub enum AutorouterStatus { Finished, } -pub struct Autorouter { +pub struct Autorouter { pub(super) board: Board, pub(super) ratsnest: Ratsnest, } -impl Autorouter { +impl Autorouter { pub fn new(board: Board) -> Result { let ratsnest = Ratsnest::new(board.layout())?; Ok(Self { board, ratsnest }) diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index 985832e..e019da3 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -11,7 +11,7 @@ use crate::{ selection::Selection, Autorouter, AutorouterError, AutorouterStatus, }, - board::mesadata::MesadataTrait, + board::mesadata::AccessMesadata, layout::via::ViaWeight, router::{navmesh::Navmesh, trace::Trace}, }; @@ -53,7 +53,7 @@ pub enum Execute { } impl Execute { - pub fn step( + pub fn step( &mut self, invoker: &mut Invoker, ) -> Result { @@ -73,7 +73,7 @@ impl Execute { } } - fn step_catch_err( + fn step_catch_err( &mut self, invoker: &mut Invoker, ) -> Result { @@ -103,7 +103,7 @@ impl ExecuteWithStatus { } } - pub fn step( + pub fn step( &mut self, invoker: &mut Invoker, ) -> Result { @@ -129,13 +129,13 @@ impl GetMaybeTrace for ExecuteWithStatus { } } -pub struct Invoker { +pub struct Invoker { autorouter: Autorouter, history: History, ongoing_command: Option, } -impl Invoker { +impl Invoker { pub fn new(autorouter: Autorouter) -> Self { Self::new_with_history(autorouter, History::new()) } diff --git a/src/autorouter/place_via.rs b/src/autorouter/place_via.rs index 43db0ea..2f10b59 100644 --- a/src/autorouter/place_via.rs +++ b/src/autorouter/place_via.rs @@ -3,7 +3,7 @@ use crate::{ invoker::{GetMaybeNavmesh, GetMaybeTrace}, Autorouter, AutorouterError, }, - board::mesadata::MesadataTrait, + board::mesadata::AccessMesadata, layout::via::ViaWeight, router::{navmesh::Navmesh, trace::Trace}, }; @@ -20,7 +20,7 @@ impl PlaceVia { pub fn doit( &mut self, - autorouter: &mut Autorouter, + autorouter: &mut Autorouter, ) -> Result<(), AutorouterError> { autorouter.place_via(self.weight) } diff --git a/src/autorouter/ratsnest.rs b/src/autorouter/ratsnest.rs index 059d1f9..5bf9899 100644 --- a/src/autorouter/ratsnest.rs +++ b/src/autorouter/ratsnest.rs @@ -16,9 +16,9 @@ use crate::{ dot::FixedDotIndex, graph::{GetMaybeNet, MakePrimitive, PrimitiveIndex}, primitive::MakePrimitiveShape, - rules::RulesTrait, + rules::AccessRules, }, - geometry::{compound::CompoundManagerTrait, shape::ShapeTrait}, + geometry::{compound::ManageCompounds, shape::AccessShape}, graph::{GenericIndex, GetPetgraphIndex}, layout::{ zone::{MakePolyShape, ZoneWeight}, @@ -72,7 +72,7 @@ pub struct Ratsnest { } impl Ratsnest { - pub fn new(layout: &Layout) -> Result { + pub fn new(layout: &Layout) -> Result { let mut unionfind = UnionFind::new(layout.drawing().geometry().graph().node_bound()); for edge in layout.drawing().geometry().graph().edge_references() { diff --git a/src/autorouter/selection.rs b/src/autorouter/selection.rs index fdf1c99..bae8040 100644 --- a/src/autorouter/selection.rs +++ b/src/autorouter/selection.rs @@ -3,9 +3,9 @@ use std::collections::HashSet; use serde::{Deserialize, Serialize}; use crate::{ - board::{mesadata::MesadataTrait, Board}, + board::{mesadata::AccessMesadata, Board}, drawing::graph::{GetLayer, MakePrimitive}, - geometry::compound::CompoundManagerTrait, + geometry::compound::ManageCompounds, graph::{GenericIndex, GetPetgraphIndex}, layout::{zone::ZoneWeight, CompoundWeight, NodeIndex}, }; @@ -28,7 +28,7 @@ impl Selection { } } - pub fn toggle_at_node(&mut self, board: &Board, node: NodeIndex) { + pub fn toggle_at_node(&mut self, board: &Board, node: NodeIndex) { let Some(selector) = self.node_selector(board, node) else { return; }; @@ -40,15 +40,15 @@ impl Selection { } } - fn select(&mut self, board: &Board, selector: Selector) { + fn select(&mut self, board: &Board, selector: Selector) { self.selectors.insert(selector); } - fn deselect(&mut self, board: &Board, selector: &Selector) { + fn deselect(&mut self, board: &Board, selector: &Selector) { self.selectors.remove(selector); } - pub fn contains_node(&self, board: &Board, node: NodeIndex) -> bool { + pub fn contains_node(&self, board: &Board, node: NodeIndex) -> bool { let Some(selector) = self.node_selector(board, node) else { return false; }; @@ -58,7 +58,7 @@ impl Selection { fn node_selector( &self, - board: &Board, + board: &Board, node: NodeIndex, ) -> Option { let layer = match node { diff --git a/src/bin/topola-egui/app.rs b/src/bin/topola-egui/app.rs index 6c0baa5..ff43094 100644 --- a/src/bin/topola-egui/app.rs +++ b/src/bin/topola-egui/app.rs @@ -20,13 +20,13 @@ use topola::{ dot::FixedDotIndex, graph::{MakePrimitive, PrimitiveIndex}, primitive::MakePrimitiveShape, - rules::RulesTrait, + rules::AccessRules, Drawing, Infringement, LayoutException, }, geometry::{ - compound::CompoundManagerTrait, - primitive::{BendShape, DotShape, PrimitiveShape, PrimitiveShapeTrait, SegShape}, - shape::ShapeTrait, + compound::ManageCompounds, + primitive::{AccessPrimitiveShape, BendShape, DotShape, PrimitiveShape, SegShape}, + shape::AccessShape, GenericNode, }, layout::{via::ViaWeight, zone::MakePolyShape, Layout}, diff --git a/src/bin/topola-egui/layers.rs b/src/bin/topola-egui/layers.rs index 336e0da..c99837d 100644 --- a/src/bin/topola-egui/layers.rs +++ b/src/bin/topola-egui/layers.rs @@ -1,4 +1,4 @@ -use topola::board::{mesadata::MesadataTrait, Board}; +use topola::board::{mesadata::AccessMesadata, Board}; pub struct Layers { // TODO: @@ -10,7 +10,7 @@ pub struct Layers { } impl Layers { - pub fn new(board: &Board) -> Self { + pub fn new(board: &Board) -> Self { let layer_count = board.layout().drawing().layer_count(); let visible = std::iter::repeat(true) .take(layer_count) @@ -65,7 +65,7 @@ impl Layers { } } - pub fn update(&mut self, ctx: &egui::Context, board: &Board) { + pub fn update(&mut self, ctx: &egui::Context, board: &Board) { egui::SidePanel::right("right_side_panel").show(ctx, |ui| { ui.label("Layers"); diff --git a/src/bin/topola-egui/overlay.rs b/src/bin/topola-egui/overlay.rs index b4ca6e3..9dfb0a4 100644 --- a/src/bin/topola-egui/overlay.rs +++ b/src/bin/topola-egui/overlay.rs @@ -6,14 +6,14 @@ use spade::InsertionError; use topola::{ autorouter::{ratsnest::Ratsnest, selection::Selection}, - board::{mesadata::MesadataTrait, Board}, + board::{mesadata::AccessMesadata, Board}, drawing::{ graph::{GetLayer, MakePrimitive}, primitive::MakePrimitiveShape, }, geometry::{ - compound::CompoundManagerTrait, - shape::{Shape, ShapeTrait}, + compound::ManageCompounds, + shape::{AccessShape, Shape}, }, graph::{GenericIndex, GetPetgraphIndex}, layout::{ @@ -30,7 +30,7 @@ pub struct Overlay { } impl Overlay { - pub fn new(board: &Board) -> Result { + pub fn new(board: &Board) -> Result { Ok(Self { ratsnest: Ratsnest::new(board.layout())?, selection: Selection::new(), @@ -38,7 +38,7 @@ impl Overlay { }) } - pub fn click(&mut self, board: &Board, at: Point) { + pub fn click(&mut self, board: &Board, at: Point) { let geoms: Vec<_> = board .layout() .drawing() @@ -60,7 +60,12 @@ impl Overlay { } } - fn contains_point(&self, board: &Board, node: NodeIndex, p: Point) -> bool { + fn contains_point( + &self, + board: &Board, + node: NodeIndex, + p: Point, + ) -> bool { let shape: Shape = match node { NodeIndex::Primitive(primitive) => { primitive.primitive(board.layout().drawing()).shape().into() diff --git a/src/bin/topola-egui/painter.rs b/src/bin/topola-egui/painter.rs index 57d8b4f..e520f08 100644 --- a/src/bin/topola-egui/painter.rs +++ b/src/bin/topola-egui/painter.rs @@ -1,6 +1,6 @@ use geo::{CoordsIter, Point, Polygon}; use topola::{ - geometry::primitive::{PrimitiveShape, PrimitiveShapeTrait}, + geometry::primitive::{AccessPrimitiveShape, PrimitiveShape}, math::{self, Circle}, }; @@ -54,7 +54,7 @@ impl<'a> Painter<'a> { self.ui.painter().add(epaint_shape); - let envelope = PrimitiveShapeTrait::envelope(shape, 0.0); + let envelope = AccessPrimitiveShape::envelope(shape, 0.0); let rect = egui::epaint::Rect { min: [envelope.lower()[0] as f32, -envelope.upper()[1] as f32].into(), max: [envelope.upper()[0] as f32, -envelope.lower()[1] as f32].into(), diff --git a/src/bin/topola-egui/viewport.rs b/src/bin/topola-egui/viewport.rs index 785d42e..6fc83dd 100644 --- a/src/bin/topola-egui/viewport.rs +++ b/src/bin/topola-egui/viewport.rs @@ -5,12 +5,12 @@ use petgraph::{ }; use topola::{ autorouter::invoker::{Command, ExecuteWithStatus, GetMaybeNavmesh, GetMaybeTrace, Invoker}, - board::mesadata::MesadataTrait, + board::mesadata::AccessMesadata, drawing::{ graph::{MakePrimitive, PrimitiveIndex}, primitive::MakePrimitiveShape, }, - geometry::{shape::ShapeTrait, GenericNode}, + geometry::{shape::AccessShape, GenericNode}, layout::{via::ViaWeight, zone::MakePolyShape}, math::Circle, specctra::mesadata::SpecctraMesadata, diff --git a/src/bin/topola-sdl2-demo/main.rs b/src/bin/topola-sdl2-demo/main.rs index 17ef496..0d4d56f 100644 --- a/src/bin/topola-sdl2-demo/main.rs +++ b/src/bin/topola-sdl2-demo/main.rs @@ -18,11 +18,11 @@ use topola::autorouter::{Autorouter, AutorouterStatus}; use topola::drawing::dot::FixedDotWeight; use topola::drawing::graph::{MakePrimitive, PrimitiveIndex}; use topola::drawing::primitive::MakePrimitiveShape; -use topola::drawing::rules::{Conditions, RulesTrait}; +use topola::drawing::rules::{AccessRules, Conditions}; use topola::drawing::seg::FixedSegWeight; use topola::drawing::{Infringement, LayoutException}; -use topola::geometry::primitive::{PrimitiveShape, PrimitiveShapeTrait}; -use topola::geometry::shape::ShapeTrait; +use topola::geometry::primitive::{AccessPrimitiveShape, PrimitiveShape}; +use topola::geometry::shape::AccessShape; use topola::layout::zone::MakePolyShape; use topola::layout::Layout; use topola::router::draw::DrawException; @@ -56,7 +56,7 @@ struct SimpleRules { net_clearances: HashMap<(usize, usize), f64>, } -impl RulesTrait for SimpleRules { +impl AccessRules for SimpleRules { fn clearance(&self, conditions1: &Conditions, conditions2: &Conditions) -> f64 { if let (Some(net1), Some(net2)) = (conditions1.maybe_net, conditions2.maybe_net) { *self.net_clearances.get(&(net1, net2)).unwrap_or(&10.0) @@ -81,7 +81,7 @@ impl RulesTrait for SimpleRules { } // Clunky enum to work around borrow checker. -enum RouterOrLayout<'a, R: RulesTrait> { +enum RouterOrLayout<'a, R: AccessRules> { Router(&'a mut Route<'a, R>), Layout(&'a Layout), } @@ -222,7 +222,7 @@ fn render_times( renderer: &mut Renderer, font_context: &CanvasFontContext, view: &mut View, - mut router_or_layout: RouterOrLayout, + mut router_or_layout: RouterOrLayout, _unused: Option<()>, mut maybe_navmesh: Option, path: &[NodeIndex], diff --git a/src/bin/topola-sdl2-demo/painter.rs b/src/bin/topola-sdl2-demo/painter.rs index f8ec886..ae2f00f 100644 --- a/src/bin/topola-sdl2-demo/painter.rs +++ b/src/bin/topola-sdl2-demo/painter.rs @@ -2,7 +2,7 @@ use geo::{CoordsIter, Point, Polygon}; use pathfinder_canvas::{ vec2f, ArcDirection, Canvas, CanvasRenderingContext2D, ColorU, FillRule, Path2D, RectF, }; -use topola::geometry::primitive::{PrimitiveShape, PrimitiveShapeTrait}; +use topola::geometry::primitive::{AccessPrimitiveShape, PrimitiveShape}; pub struct Painter<'a> { canvas: &'a mut CanvasRenderingContext2D, @@ -56,7 +56,7 @@ impl<'a> Painter<'a> { } } - let envelope = PrimitiveShapeTrait::envelope(shape, 0.0); + let envelope = AccessPrimitiveShape::envelope(shape, 0.0); // XXX: points represented as arrays can't be conveniently converted to vector types let topleft = vec2f(envelope.lower()[0] as f32, -envelope.upper()[1] as f32); let bottomright = vec2f(envelope.upper()[0] as f32, -envelope.lower()[1] as f32); diff --git a/src/board/board.rs b/src/board/board.rs index 681aae4..6beb0a5 100644 --- a/src/board/board.rs +++ b/src/board/board.rs @@ -1,14 +1,14 @@ use std::collections::HashMap; use crate::{ - board::mesadata::MesadataTrait, + board::mesadata::AccessMesadata, drawing::{ band::BandFirstSegIndex, dot::{FixedDotIndex, FixedDotWeight}, graph::{GetLayer, GetMaybeNet}, seg::{FixedSegIndex, FixedSegWeight}, }, - geometry::{shape::ShapeTrait, GenericNode}, + geometry::{shape::AccessShape, GenericNode}, graph::GenericIndex, layout::{ zone::{GetMaybeApex, MakePolyShape, ZoneWeight}, @@ -19,13 +19,13 @@ use crate::{ }; #[derive(Debug)] -pub struct Board { +pub struct Board { layout: Layout, node_to_pinname: HashMap, pinname_pair_to_band: HashMap<(String, String), BandFirstSegIndex>, } -impl Board { +impl Board { pub fn new(layout: Layout) -> Self { Self { layout, diff --git a/src/board/mesadata.rs b/src/board/mesadata.rs index fb6af4e..2c059ac 100644 --- a/src/board/mesadata.rs +++ b/src/board/mesadata.rs @@ -1,6 +1,6 @@ -use crate::drawing::rules::RulesTrait; +use crate::drawing::rules::AccessRules; -pub trait MesadataTrait: RulesTrait { +pub trait AccessMesadata: AccessRules { fn bename_layer(&mut self, layer: usize, layername: String); fn layer_layername(&self, layer: usize) -> Option<&str>; fn layername_layer(&self, layername: &str) -> Option; diff --git a/src/drawing/bend.rs b/src/drawing/bend.rs index aaad578..141b655 100644 --- a/src/drawing/bend.rs +++ b/src/drawing/bend.rs @@ -4,10 +4,10 @@ use crate::{ drawing::{ graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag}, primitive::{GenericPrimitive, Primitive}, - rules::RulesTrait, + rules::AccessRules, Drawing, }, - geometry::{BendWeightTrait, GetOffset, GetWidth, SetOffset}, + geometry::{AccessBendWeight, GetOffset, GetWidth, SetOffset}, graph::{GenericIndex, GetPetgraphIndex}, }; @@ -69,7 +69,7 @@ impl TryFrom for BendWeight { } } -impl BendWeightTrait for BendWeight {} +impl AccessBendWeight for BendWeight {} #[derive(Debug, Clone, Copy, PartialEq)] pub struct FixedBendWeight { @@ -80,7 +80,7 @@ pub struct FixedBendWeight { } impl_fixed_weight!(FixedBendWeight, FixedBend, FixedBendIndex); -impl BendWeightTrait for FixedBendWeight {} +impl AccessBendWeight for FixedBendWeight {} impl GetOffset for FixedBendWeight { fn offset(&self) -> f64 { @@ -127,4 +127,4 @@ impl GetWidth for LooseBendWeight { } impl_loose_weight!(LooseBendWeight, LooseBend, LooseBendIndex); -impl BendWeightTrait for LooseBendWeight {} +impl AccessBendWeight for LooseBendWeight {} diff --git a/src/drawing/cane.rs b/src/drawing/cane.rs index 65b7099..587ef96 100644 --- a/src/drawing/cane.rs +++ b/src/drawing/cane.rs @@ -7,7 +7,7 @@ use crate::drawing::{ Drawing, }; -use super::rules::RulesTrait; +use super::rules::AccessRules; #[derive(Debug, Clone, Copy)] pub struct Cane { @@ -17,7 +17,7 @@ pub struct Cane { } impl Cane { - pub fn from_dot(dot: LooseDotIndex, drawing: &Drawing) -> Self { + pub fn from_dot(dot: LooseDotIndex, drawing: &Drawing) -> Self { let bend = LooseDot::new(dot, drawing).bend(); let dot = LooseBend::new(bend, drawing).other_joint(dot); let seg = LooseDot::new(dot, drawing).seg().unwrap(); diff --git a/src/drawing/collect.rs b/src/drawing/collect.rs index 14e8da0..cc217d2 100644 --- a/src/drawing/collect.rs +++ b/src/drawing/collect.rs @@ -2,17 +2,17 @@ use crate::drawing::{ bend::LooseBendIndex, graph::PrimitiveIndex, primitive::{GetInnerOuter, GetJoints}, - rules::RulesTrait, + rules::AccessRules, wraparoundable::{GetWraparound, WraparoundableIndex}, Drawing, }; #[derive(Debug)] -pub struct Collect<'a, CW: Copy, R: RulesTrait> { +pub struct Collect<'a, CW: Copy, R: AccessRules> { drawing: &'a Drawing, } -impl<'a, CW: Copy, R: RulesTrait> Collect<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> Collect<'a, CW, R> { pub fn new(drawing: &'a Drawing) -> Self { Self { drawing } } diff --git a/src/drawing/dot.rs b/src/drawing/dot.rs index bede8d7..152fa7d 100644 --- a/src/drawing/dot.rs +++ b/src/drawing/dot.rs @@ -7,10 +7,10 @@ use crate::{ drawing::{ graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag}, primitive::{GenericPrimitive, Primitive}, - rules::RulesTrait, + rules::AccessRules, Drawing, }, - geometry::{DotWeightTrait, GetPos, GetWidth, SetPos}, + geometry::{AccessDotWeight, GetPos, GetWidth, SetPos}, graph::{GenericIndex, GetPetgraphIndex}, math::Circle, }; @@ -71,7 +71,7 @@ impl TryFrom for DotWeight { } } -impl DotWeightTrait for DotWeight {} +impl AccessDotWeight for DotWeight {} #[derive(Debug, Clone, Copy, PartialEq)] pub struct FixedDotWeight { @@ -81,7 +81,7 @@ pub struct FixedDotWeight { } impl_fixed_weight!(FixedDotWeight, FixedDot, FixedDotIndex); -impl DotWeightTrait for FixedDotWeight {} +impl AccessDotWeight for FixedDotWeight {} impl GetPos for FixedDotWeight { fn pos(&self) -> Point { @@ -109,7 +109,7 @@ pub struct LooseDotWeight { } impl_loose_weight!(LooseDotWeight, LooseDot, LooseDotIndex); -impl DotWeightTrait for LooseDotWeight {} +impl AccessDotWeight for LooseDotWeight {} impl GetPos for LooseDotWeight { fn pos(&self) -> Point { diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index 611149e..3ee3430 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -18,7 +18,7 @@ use crate::drawing::{ GenericPrimitive, GetCore, GetInnerOuter, GetJoints, GetLimbs, GetOtherJoint, MakePrimitiveShape, }, - rules::{GetConditions, RulesTrait}, + rules::{AccessRules, GetConditions}, seg::{ FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SegIndex, SegWeight, SeqLooseSegIndex, SeqLooseSegWeight, @@ -26,11 +26,11 @@ use crate::drawing::{ wraparoundable::{GetWraparound, Wraparoundable, WraparoundableIndex}, }; use crate::geometry::{ - compound::CompoundManagerTrait, - primitive::{PrimitiveShape, PrimitiveShapeTrait}, + compound::ManageCompounds, + primitive::{AccessPrimitiveShape, PrimitiveShape}, with_rtree::{BboxedIndex, GeometryWithRtree}, - BendWeightTrait, DotWeightTrait, GenericNode, Geometry, GeometryLabel, GetOffset, GetPos, - GetWidth, SegWeightTrait, + AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel, + GetOffset, GetPos, GetWidth, }; use crate::graph::{GenericIndex, GetPetgraphIndex}; use crate::math::NoTangents; @@ -64,7 +64,7 @@ pub struct Collision(pub PrimitiveShape, pub PrimitiveIndex); pub struct AlreadyConnected(pub usize, pub PrimitiveIndex); #[derive(Debug)] -pub struct Drawing { +pub struct Drawing { geometry_with_rtree: GeometryWithRtree< PrimitiveWeight, DotWeight, @@ -80,7 +80,7 @@ pub struct Drawing { } #[debug_invariant(self.test_if_looses_dont_infringe_each_other())] -impl Drawing { +impl Drawing { pub fn new(rules: R, layer_count: usize) -> Self { Self { geometry_with_rtree: GeometryWithRtree::new(layer_count), @@ -172,7 +172,7 @@ impl Drawing { #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))] - fn add_dot_with_infringables + GetLayer>( + fn add_dot_with_infringables + GetLayer>( &mut self, weight: W, infringables: Option<&[PrimitiveIndex]>, @@ -241,7 +241,7 @@ impl Drawing { #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() >= old(self.geometry_with_rtree.graph().edge_count() + 2))] #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))] #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))] - fn add_seg_with_infringables + GetLayer>( + fn add_seg_with_infringables + GetLayer>( &mut self, from: DotIndex, to: DotIndex, @@ -305,7 +305,7 @@ impl Drawing { #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))] #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 3))] #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))] - fn add_core_bend_with_infringables + GetLayer>( + fn add_core_bend_with_infringables + GetLayer>( &mut self, from: DotIndex, to: DotIndex, @@ -719,10 +719,10 @@ impl Drawing { } } -impl Drawing { +impl Drawing { #[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))] - fn add_dot_infringably + GetLayer>( + fn add_dot_infringably + GetLayer>( &mut self, weight: W, ) -> GenericIndex @@ -734,7 +734,7 @@ impl Drawing { #[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 2))] - fn add_seg_infringably + GetLayer>( + fn add_seg_infringably + GetLayer>( &mut self, from: DotIndex, to: DotIndex, @@ -967,7 +967,7 @@ impl Drawing { } } -impl CompoundManagerTrait> for Drawing { +impl ManageCompounds> for Drawing { fn add_compound(&mut self, weight: CW) -> GenericIndex { self.geometry_with_rtree.add_compound(weight) } diff --git a/src/drawing/graph.rs b/src/drawing/graph.rs index 0902a9c..1217145 100644 --- a/src/drawing/graph.rs +++ b/src/drawing/graph.rs @@ -8,7 +8,7 @@ use super::{ bend::{FixedBendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight}, dot::{FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight}, primitive::Primitive, - rules::RulesTrait, + rules::AccessRules, seg::{ FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex, SeqLooseSegWeight, @@ -32,7 +32,7 @@ pub trait GetMaybeNet { #[enum_dispatch] pub trait MakePrimitive { - fn primitive<'a, CW: Copy, R: RulesTrait>( + fn primitive<'a, CW: Copy, R: AccessRules>( &self, drawing: &'a Drawing, ) -> Primitive<'a, CW, R>; @@ -61,7 +61,7 @@ macro_rules! impl_weight { pub type $index_struct = GenericIndex<$weight_struct>; impl MakePrimitive for $index_struct { - fn primitive<'a, CW: Copy, R: RulesTrait>( + fn primitive<'a, CW: Copy, R: AccessRules>( &self, drawing: &'a Drawing, ) -> Primitive<'a, CW, R> { diff --git a/src/drawing/guide.rs b/src/drawing/guide.rs index 2eef697..ed8506b 100644 --- a/src/drawing/guide.rs +++ b/src/drawing/guide.rs @@ -2,8 +2,8 @@ use geo::Line; use crate::{ geometry::{ - primitive::{PrimitiveShape, PrimitiveShapeTrait}, - shape::ShapeTrait, + primitive::{AccessPrimitiveShape, PrimitiveShape}, + shape::AccessShape, }, math::{self, Circle, NoTangents}, }; @@ -12,17 +12,17 @@ use super::{ bend::BendIndex, dot::{DotIndex, FixedDotIndex, LooseDotIndex}, graph::{MakePrimitive, PrimitiveIndex}, - head::{BareHead, CaneHead, Head, HeadTrait}, + head::{BareHead, CaneHead, GetFace, Head}, primitive::{GetCore, GetInnerOuter, GetJoints, GetOtherJoint, GetWeight, MakePrimitiveShape}, - rules::{Conditions, GetConditions, RulesTrait}, + rules::{AccessRules, Conditions, GetConditions}, Drawing, }; -pub struct Guide<'a, CW: Copy, R: RulesTrait> { +pub struct Guide<'a, CW: Copy, R: AccessRules> { drawing: &'a Drawing, } -impl<'a, CW: Copy, R: RulesTrait> Guide<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> Guide<'a, CW, R> { pub fn new(drawing: &'a Drawing) -> Self { Self { drawing } } diff --git a/src/drawing/head.rs b/src/drawing/head.rs index 7c635ae..1572d85 100644 --- a/src/drawing/head.rs +++ b/src/drawing/head.rs @@ -6,16 +6,16 @@ use super::{ cane::Cane, dot::{DotIndex, FixedDotIndex, LooseDotIndex}, primitive::MakePrimitiveShape, - rules::RulesTrait, + rules::AccessRules, Drawing, }; #[enum_dispatch] -pub trait HeadTrait { +pub trait GetFace { fn face(&self) -> DotIndex; } -#[enum_dispatch(HeadTrait)] +#[enum_dispatch(GetFace)] #[derive(Debug, Clone, Copy)] pub enum Head { Bare(BareHead), @@ -23,7 +23,7 @@ pub enum Head { } impl Head { - pub fn ref_<'a, CW: Copy, R: RulesTrait>( + pub fn ref_<'a, CW: Copy, R: AccessRules>( &self, drawing: &'a Drawing, ) -> HeadRef<'a, CW, R> { @@ -36,7 +36,7 @@ pub struct BareHead { pub face: FixedDotIndex, } -impl HeadTrait for BareHead { +impl GetFace for BareHead { fn face(&self) -> DotIndex { self.face.into() } @@ -48,30 +48,30 @@ pub struct CaneHead { pub cane: Cane, } -impl HeadTrait for CaneHead { +impl GetFace for CaneHead { fn face(&self) -> DotIndex { self.face.into() } } -pub struct HeadRef<'a, CW: Copy, R: RulesTrait> { +pub struct HeadRef<'a, CW: Copy, R: AccessRules> { head: Head, drawing: &'a Drawing, } -impl<'a, CW: Copy, R: RulesTrait> HeadRef<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> HeadRef<'a, CW, R> { pub fn new(head: Head, drawing: &'a Drawing) -> Self { Self { drawing, head } } } -impl<'a, CW: Copy, R: RulesTrait> HeadTrait for HeadRef<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetFace for HeadRef<'a, CW, R> { fn face(&self) -> DotIndex { self.head.face() } } -impl<'a, CW: Copy, R: RulesTrait> MeasureLength for HeadRef<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> MeasureLength for HeadRef<'a, CW, R> { fn length(&self) -> f64 { match self.head { Head::Bare(..) => 0.0, diff --git a/src/drawing/loose.rs b/src/drawing/loose.rs index 564e88c..1e2e04a 100644 --- a/src/drawing/loose.rs +++ b/src/drawing/loose.rs @@ -13,7 +13,7 @@ use crate::{ graph::GetPetgraphIndex, }; -use super::rules::RulesTrait; +use super::rules::AccessRules; #[enum_dispatch] pub trait GetNextLoose { @@ -41,14 +41,14 @@ impl From for PrimitiveIndex { } #[enum_dispatch(GetNextLoose, GetDrawing, GetPetgraphIndex)] -pub enum Loose<'a, CW: Copy, R: RulesTrait> { +pub enum Loose<'a, CW: Copy, R: AccessRules> { Dot(LooseDot<'a, CW, R>), LoneSeg(LoneLooseSeg<'a, CW, R>), SeqSeg(SeqLooseSeg<'a, CW, R>), Bend(LooseBend<'a, CW, R>), } -impl<'a, CW: Copy, R: RulesTrait> Loose<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> Loose<'a, CW, R> { pub fn new(index: LooseIndex, drawing: &'a Drawing) -> Self { match index { LooseIndex::Dot(dot) => drawing.primitive(dot).into(), @@ -59,7 +59,7 @@ impl<'a, CW: Copy, R: RulesTrait> Loose<'a, CW, R> { } } -impl<'a, CW: Copy, R: RulesTrait> GetNextLoose for LooseDot<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetNextLoose for LooseDot<'a, CW, R> { fn next_loose(&self, maybe_prev: Option) -> Option { let bend = self.bend(); let Some(prev) = maybe_prev else { @@ -74,13 +74,13 @@ impl<'a, CW: Copy, R: RulesTrait> GetNextLoose for LooseDot<'a, CW, R> { } } -impl<'a, CW: Copy, R: RulesTrait> GetNextLoose for LoneLooseSeg<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetNextLoose for LoneLooseSeg<'a, CW, R> { fn next_loose(&self, _maybe_prev: Option) -> Option { None } } -impl<'a, CW: Copy, R: RulesTrait> GetNextLoose for SeqLooseSeg<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetNextLoose for SeqLooseSeg<'a, CW, R> { fn next_loose(&self, maybe_prev: Option) -> Option { let ends = self.joints(); let Some(prev) = maybe_prev else { @@ -98,7 +98,7 @@ impl<'a, CW: Copy, R: RulesTrait> GetNextLoose for SeqLooseSeg<'a, CW, R> { } } -impl<'a, CW: Copy, R: RulesTrait> GetNextLoose for LooseBend<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetNextLoose for LooseBend<'a, CW, R> { fn next_loose(&self, maybe_prev: Option) -> Option { let ends = self.joints(); let Some(prev) = maybe_prev else { diff --git a/src/drawing/primitive.rs b/src/drawing/primitive.rs index 8d0eb66..953bc4b 100644 --- a/src/drawing/primitive.rs +++ b/src/drawing/primitive.rs @@ -2,7 +2,7 @@ use enum_dispatch::enum_dispatch; use petgraph::stable_graph::NodeIndex; use crate::geometry::{ - primitive::{PrimitiveShape, PrimitiveShapeTrait}, + primitive::{AccessPrimitiveShape, PrimitiveShape}, GetOffset, GetWidth, }; use crate::{ @@ -10,7 +10,7 @@ use crate::{ bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight}, dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight}, graph::{GetLayer, GetMaybeNet, PrimitiveIndex, PrimitiveWeight, Retag}, - rules::{Conditions, GetConditions, RulesTrait}, + rules::{AccessRules, Conditions, GetConditions}, seg::{FixedSegWeight, LoneLooseSegWeight, SegIndex, SeqLooseSegIndex, SeqLooseSegWeight}, Drawing, }, @@ -19,7 +19,7 @@ use crate::{ }; #[enum_dispatch] -pub trait GetDrawing<'a, R: RulesTrait> { +pub trait GetDrawing<'a, R: AccessRules> { fn drawing(&self) -> &Drawing; } @@ -72,7 +72,7 @@ pub trait GetJoints { fn joints(&self) -> (F, T); } -pub trait GetFirstRail<'a, R: RulesTrait>: GetDrawing<'a, R> + GetPetgraphIndex { +pub trait GetFirstRail<'a, R: AccessRules>: GetDrawing<'a, R> + GetPetgraphIndex { fn first_rail(&self) -> Option { self.drawing() .geometry() @@ -85,7 +85,7 @@ pub trait GetBendIndex { fn bend_index(&self) -> BendIndex; } -pub trait GetCore<'a, R: RulesTrait>: GetDrawing<'a, R> + GetBendIndex { +pub trait GetCore<'a, R: AccessRules>: GetDrawing<'a, R> + GetBendIndex { fn core(&self) -> FixedDotIndex { FixedDotIndex::new( self.drawing() @@ -96,7 +96,7 @@ pub trait GetCore<'a, R: RulesTrait>: GetDrawing<'a, R> + GetBendIndex { } } -pub trait GetInnerOuter<'a, R: RulesTrait>: GetDrawing<'a, R> + GetBendIndex { +pub trait GetInnerOuter<'a, R: AccessRules>: GetDrawing<'a, R> + GetBendIndex { fn inner(&self) -> Option { self.drawing() .geometry() @@ -114,7 +114,7 @@ pub trait GetInnerOuter<'a, R: RulesTrait>: GetDrawing<'a, R> + GetBendIndex { macro_rules! impl_primitive { ($primitive_struct:ident, $weight_struct:ident) => { - impl<'a, CW: Copy, R: RulesTrait> GetWeight<$weight_struct> + impl<'a, CW: Copy, R: AccessRules> GetWeight<$weight_struct> for $primitive_struct<'a, CW, R> { fn weight(&self) -> $weight_struct { @@ -126,13 +126,13 @@ macro_rules! impl_primitive { } } - impl<'a, CW: Copy, R: RulesTrait> GetLayer for $primitive_struct<'a, CW, R> { + impl<'a, CW: Copy, R: AccessRules> GetLayer for $primitive_struct<'a, CW, R> { fn layer(&self) -> usize { self.weight().layer() } } - impl<'a, CW: Copy, R: RulesTrait> GetMaybeNet for $primitive_struct<'a, CW, R> { + impl<'a, CW: Copy, R: AccessRules> GetMaybeNet for $primitive_struct<'a, CW, R> { fn maybe_net(&self) -> Option { self.weight().maybe_net() } @@ -161,7 +161,7 @@ macro_rules! impl_loose_primitive { GetLimbs, GetConditions )] -pub enum Primitive<'a, CW: Copy, R: RulesTrait> { +pub enum Primitive<'a, CW: Copy, R: AccessRules> { FixedDot(FixedDot<'a, CW, R>), LooseDot(LooseDot<'a, CW, R>), FixedSeg(FixedSeg<'a, CW, R>), @@ -172,12 +172,12 @@ pub enum Primitive<'a, CW: Copy, R: RulesTrait> { } #[derive(Debug)] -pub struct GenericPrimitive<'a, W, CW: Copy, R: RulesTrait> { +pub struct GenericPrimitive<'a, W, CW: Copy, R: AccessRules> { pub index: GenericIndex, drawing: &'a Drawing, } -impl<'a, W, CW: Copy, R: RulesTrait> GenericPrimitive<'a, W, CW, R> { +impl<'a, W, CW: Copy, R: AccessRules> GenericPrimitive<'a, W, CW, R> { pub fn new(index: GenericIndex, drawing: &'a Drawing) -> Self { Self { index, drawing } } @@ -201,7 +201,7 @@ impl<'a, W, CW: Copy, R: RulesTrait> GenericPrimitive<'a, W, CW, R> { } } -impl<'a, W, CW: Copy, R: RulesTrait> GetInterior +impl<'a, W, CW: Copy, R: AccessRules> GetInterior for GenericPrimitive<'a, W, CW, R> { fn interior(&self) -> Vec { @@ -209,19 +209,19 @@ impl<'a, W, CW: Copy, R: RulesTrait> GetInterior } } -impl<'a, W, CW: Copy, R: RulesTrait> GetDrawing<'a, R> for GenericPrimitive<'a, W, CW, R> { +impl<'a, W, CW: Copy, R: AccessRules> GetDrawing<'a, R> for GenericPrimitive<'a, W, CW, R> { fn drawing(&self) -> &Drawing { self.drawing } } -impl<'a, W, CW: Copy, R: RulesTrait> GetPetgraphIndex for GenericPrimitive<'a, W, CW, R> { +impl<'a, W, CW: Copy, R: AccessRules> GetPetgraphIndex for GenericPrimitive<'a, W, CW, R> { fn petgraph_index(&self) -> NodeIndex { self.index.petgraph_index() } } -impl<'a, W: GetWidth, CW: Copy, R: RulesTrait> GetWidth for GenericPrimitive<'a, W, CW, R> +impl<'a, W: GetWidth, CW: Copy, R: AccessRules> GetWidth for GenericPrimitive<'a, W, CW, R> where GenericPrimitive<'a, W, CW, R>: GetWeight, { @@ -230,7 +230,7 @@ where } } -impl<'a, W, CW: Copy, R: RulesTrait> GetConditions for GenericPrimitive<'a, W, CW, R> +impl<'a, W, CW: Copy, R: AccessRules> GetConditions for GenericPrimitive<'a, W, CW, R> where GenericPrimitive<'a, W, CW, R>: GetMaybeNet, { @@ -246,13 +246,13 @@ where pub type FixedDot<'a, CW, R> = GenericPrimitive<'a, FixedDotWeight, CW, R>; impl_fixed_primitive!(FixedDot, FixedDotWeight); -impl<'a, CW: Copy, R: RulesTrait> MakePrimitiveShape for FixedDot<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> MakePrimitiveShape for FixedDot<'a, CW, R> { fn shape(&self) -> PrimitiveShape { self.drawing.geometry().dot_shape(self.index.into()) } } -impl<'a, CW: Copy, R: RulesTrait> GetLimbs for FixedDot<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetLimbs for FixedDot<'a, CW, R> { fn segs(&self) -> Vec { self.drawing .geometry() @@ -268,12 +268,12 @@ impl<'a, CW: Copy, R: RulesTrait> GetLimbs for FixedDot<'a, CW, R> { } } -impl<'a, CW: Copy, R: RulesTrait> GetFirstRail<'a, R> for FixedDot<'a, CW, R> {} +impl<'a, CW: Copy, R: AccessRules> GetFirstRail<'a, R> for FixedDot<'a, CW, R> {} pub type LooseDot<'a, CW, R> = GenericPrimitive<'a, LooseDotWeight, CW, R>; impl_loose_primitive!(LooseDot, LooseDotWeight); -impl<'a, CW: Copy, R: RulesTrait> LooseDot<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> LooseDot<'a, CW, R> { pub fn seg(&self) -> Option { self.drawing .geometry() @@ -292,13 +292,13 @@ impl<'a, CW: Copy, R: RulesTrait> LooseDot<'a, CW, R> { } } -impl<'a, CW: Copy, R: RulesTrait> MakePrimitiveShape for LooseDot<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> MakePrimitiveShape for LooseDot<'a, CW, R> { fn shape(&self) -> PrimitiveShape { self.drawing.geometry().dot_shape(self.index.into()) } } -impl<'a, CW: Copy, R: RulesTrait> GetLimbs for LooseDot<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetLimbs for LooseDot<'a, CW, R> { fn segs(&self) -> Vec { if let Some(seg) = self.seg() { vec![seg.into()] @@ -315,15 +315,15 @@ impl<'a, CW: Copy, R: RulesTrait> GetLimbs for LooseDot<'a, CW, R> { pub type FixedSeg<'a, CW, R> = GenericPrimitive<'a, FixedSegWeight, CW, R>; impl_fixed_primitive!(FixedSeg, FixedSegWeight); -impl<'a, CW: Copy, R: RulesTrait> MakePrimitiveShape for FixedSeg<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> MakePrimitiveShape for FixedSeg<'a, CW, R> { fn shape(&self) -> PrimitiveShape { self.drawing.geometry().seg_shape(self.index.into()) } } -impl<'a, CW: Copy, R: RulesTrait> GetLimbs for FixedSeg<'a, CW, R> {} +impl<'a, CW: Copy, R: AccessRules> GetLimbs for FixedSeg<'a, CW, R> {} -impl<'a, CW: Copy, R: RulesTrait> GetJoints for FixedSeg<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetJoints for FixedSeg<'a, CW, R> { fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { let (from, to) = self.drawing.geometry().seg_joints(self.index.into()); ( @@ -333,7 +333,7 @@ impl<'a, CW: Copy, R: RulesTrait> GetJoints for Fi } } -impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint +impl<'a, CW: Copy, R: AccessRules> GetOtherJoint for FixedSeg<'a, CW, R> { } @@ -341,15 +341,15 @@ impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint pub type LoneLooseSeg<'a, CW, R> = GenericPrimitive<'a, LoneLooseSegWeight, CW, R>; impl_loose_primitive!(LoneLooseSeg, LoneLooseSegWeight); -impl<'a, CW: Copy, R: RulesTrait> MakePrimitiveShape for LoneLooseSeg<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> MakePrimitiveShape for LoneLooseSeg<'a, CW, R> { fn shape(&self) -> PrimitiveShape { self.drawing.geometry().seg_shape(self.index.into()) } } -impl<'a, CW: Copy, R: RulesTrait> GetLimbs for LoneLooseSeg<'a, CW, R> {} +impl<'a, CW: Copy, R: AccessRules> GetLimbs for LoneLooseSeg<'a, CW, R> {} -impl<'a, CW: Copy, R: RulesTrait> GetJoints +impl<'a, CW: Copy, R: AccessRules> GetJoints for LoneLooseSeg<'a, CW, R> { fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { @@ -361,7 +361,7 @@ impl<'a, CW: Copy, R: RulesTrait> GetJoints } } -impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint +impl<'a, CW: Copy, R: AccessRules> GetOtherJoint for LoneLooseSeg<'a, CW, R> { } @@ -369,15 +369,15 @@ impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint pub type SeqLooseSeg<'a, CW, R> = GenericPrimitive<'a, SeqLooseSegWeight, CW, R>; impl_loose_primitive!(SeqLooseSeg, SeqLooseSegWeight); -impl<'a, CW: Copy, R: RulesTrait> MakePrimitiveShape for SeqLooseSeg<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> MakePrimitiveShape for SeqLooseSeg<'a, CW, R> { fn shape(&self) -> PrimitiveShape { self.drawing.geometry().seg_shape(self.index.into()) } } -impl<'a, CW: Copy, R: RulesTrait> GetLimbs for SeqLooseSeg<'a, CW, R> {} +impl<'a, CW: Copy, R: AccessRules> GetLimbs for SeqLooseSeg<'a, CW, R> {} -impl<'a, CW: Copy, R: RulesTrait> GetJoints for SeqLooseSeg<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetJoints for SeqLooseSeg<'a, CW, R> { fn joints(&self) -> (DotIndex, LooseDotIndex) { let joints = self.drawing.geometry().seg_joints(self.index.into()); if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.0) { @@ -399,7 +399,7 @@ impl<'a, CW: Copy, R: RulesTrait> GetJoints for SeqLoos } } -impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint +impl<'a, CW: Copy, R: AccessRules> GetOtherJoint for SeqLooseSeg<'a, CW, R> { } @@ -407,21 +407,23 @@ impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint pub type FixedBend<'a, CW, R> = GenericPrimitive<'a, FixedBendWeight, CW, R>; impl_fixed_primitive!(FixedBend, FixedBendWeight); -impl<'a, CW: Copy, R: RulesTrait> GetBendIndex for FixedBend<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetBendIndex for FixedBend<'a, CW, R> { fn bend_index(&self) -> BendIndex { self.index.into() } } -impl<'a, CW: Copy, R: RulesTrait> MakePrimitiveShape for FixedBend<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> MakePrimitiveShape for FixedBend<'a, CW, R> { fn shape(&self) -> PrimitiveShape { self.drawing.geometry().bend_shape(self.index.into()) } } -impl<'a, CW: Copy, R: RulesTrait> GetLimbs for FixedBend<'a, CW, R> {} +impl<'a, CW: Copy, R: AccessRules> GetLimbs for FixedBend<'a, CW, R> {} -impl<'a, CW: Copy, R: RulesTrait> GetJoints for FixedBend<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetJoints + for FixedBend<'a, CW, R> +{ fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { let (from, to) = self.drawing.geometry().bend_joints(self.index.into()); ( @@ -431,44 +433,46 @@ impl<'a, CW: Copy, R: RulesTrait> GetJoints for Fi } } -impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint +impl<'a, CW: Copy, R: AccessRules> GetOtherJoint for FixedBend<'a, CW, R> { } -impl<'a, CW: Copy, R: RulesTrait> GetFirstRail<'a, R> for FixedBend<'a, CW, R> {} -impl<'a, CW: Copy, R: RulesTrait> GetCore<'a, R> for FixedBend<'a, CW, R> {} // TODO: Fixed bends don't have cores actually. - //impl<'a, R: QueryRules> GetInnerOuter for FixedBend<'a, CW, R> {} +impl<'a, CW: Copy, R: AccessRules> GetFirstRail<'a, R> for FixedBend<'a, CW, R> {} +impl<'a, CW: Copy, R: AccessRules> GetCore<'a, R> for FixedBend<'a, CW, R> {} // TODO: Fixed bends don't have cores actually. + //impl<'a, R: QueryRules> GetInnerOuter for FixedBend<'a, CW, R> {} pub type LooseBend<'a, CW, R> = GenericPrimitive<'a, LooseBendWeight, CW, R>; impl_loose_primitive!(LooseBend, LooseBendWeight); -impl<'a, CW: Copy, R: RulesTrait> GetBendIndex for LooseBend<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetBendIndex for LooseBend<'a, CW, R> { fn bend_index(&self) -> BendIndex { self.index.into() } } -impl<'a, CW: Copy, R: RulesTrait> From> for BendIndex { +impl<'a, CW: Copy, R: AccessRules> From> for BendIndex { fn from(bend: LooseBend<'a, CW, R>) -> BendIndex { bend.index.into() } } -impl<'a, CW: Copy, R: RulesTrait> MakePrimitiveShape for LooseBend<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> MakePrimitiveShape for LooseBend<'a, CW, R> { fn shape(&self) -> PrimitiveShape { self.drawing.geometry().bend_shape(self.index.into()) } } -impl<'a, CW: Copy, R: RulesTrait> GetLimbs for LooseBend<'a, CW, R> {} +impl<'a, CW: Copy, R: AccessRules> GetLimbs for LooseBend<'a, CW, R> {} -impl<'a, CW: Copy, R: RulesTrait> GetOffset for LooseBend<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetOffset for LooseBend<'a, CW, R> { fn offset(&self) -> f64 { self.weight().offset } } -impl<'a, CW: Copy, R: RulesTrait> GetJoints for LooseBend<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetJoints + for LooseBend<'a, CW, R> +{ fn joints(&self) -> (LooseDotIndex, LooseDotIndex) { let (from, to) = self.drawing.geometry().bend_joints(self.index.into()); ( @@ -478,9 +482,9 @@ impl<'a, CW: Copy, R: RulesTrait> GetJoints for Lo } } -impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint +impl<'a, CW: Copy, R: AccessRules> GetOtherJoint for LooseBend<'a, CW, R> { } -impl<'a, CW: Copy, R: RulesTrait> GetCore<'a, R> for LooseBend<'a, CW, R> {} -impl<'a, CW: Copy, R: RulesTrait> GetInnerOuter<'a, R> for LooseBend<'a, CW, R> {} +impl<'a, CW: Copy, R: AccessRules> GetCore<'a, R> for LooseBend<'a, CW, R> {} +impl<'a, CW: Copy, R: AccessRules> GetInnerOuter<'a, R> for LooseBend<'a, CW, R> {} diff --git a/src/drawing/rules.rs b/src/drawing/rules.rs index ecc2c4b..0a617bb 100644 --- a/src/drawing/rules.rs +++ b/src/drawing/rules.rs @@ -14,7 +14,7 @@ pub struct Conditions { pub maybe_layer: Option, } -pub trait RulesTrait { +pub trait AccessRules { fn clearance(&self, conditions1: &Conditions, conditions2: &Conditions) -> f64; fn largest_clearance(&self, net: Option) -> f64; } diff --git a/src/drawing/seg.rs b/src/drawing/seg.rs index dcd8640..a353f8c 100644 --- a/src/drawing/seg.rs +++ b/src/drawing/seg.rs @@ -4,10 +4,10 @@ use crate::{ drawing::{ graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag}, primitive::{GenericPrimitive, Primitive}, - rules::RulesTrait, + rules::AccessRules, Drawing, }, - geometry::{GetWidth, SegWeightTrait}, + geometry::{AccessSegWeight, GetWidth}, graph::{GenericIndex, GetPetgraphIndex}, }; @@ -75,7 +75,7 @@ impl TryFrom for SegWeight { } } -impl SegWeightTrait for SegWeight {} +impl AccessSegWeight for SegWeight {} #[derive(Debug, Clone, Copy, PartialEq)] pub struct FixedSegWeight { @@ -85,7 +85,7 @@ pub struct FixedSegWeight { } impl_fixed_weight!(FixedSegWeight, FixedSeg, FixedSegIndex); -impl SegWeightTrait for FixedSegWeight {} +impl AccessSegWeight for FixedSegWeight {} impl GetWidth for FixedSegWeight { fn width(&self) -> f64 { @@ -101,7 +101,7 @@ pub struct LoneLooseSegWeight { } impl_loose_weight!(LoneLooseSegWeight, LoneLooseSeg, LoneLooseSegIndex); -impl SegWeightTrait for LoneLooseSegWeight {} +impl AccessSegWeight for LoneLooseSegWeight {} impl GetWidth for LoneLooseSegWeight { fn width(&self) -> f64 { @@ -117,7 +117,7 @@ pub struct SeqLooseSegWeight { } impl_loose_weight!(SeqLooseSegWeight, SeqLooseSeg, SeqLooseSegIndex); -impl SegWeightTrait for SeqLooseSegWeight {} +impl AccessSegWeight for SeqLooseSegWeight {} impl GetWidth for SeqLooseSegWeight { fn width(&self) -> f64 { diff --git a/src/drawing/wraparoundable.rs b/src/drawing/wraparoundable.rs index 6087d21..06f8224 100644 --- a/src/drawing/wraparoundable.rs +++ b/src/drawing/wraparoundable.rs @@ -7,7 +7,7 @@ use crate::{ dot::FixedDotIndex, graph::{MakePrimitive, PrimitiveIndex}, primitive::{FixedBend, FixedDot, GetFirstRail, GetInnerOuter, LooseBend, Primitive}, - rules::RulesTrait, + rules::AccessRules, Drawing, }, graph::GetPetgraphIndex, @@ -46,13 +46,13 @@ impl From for WraparoundableIndex { } #[enum_dispatch(GetWraparound, GetDrawing, GetPetgraphIndex)] -pub enum Wraparoundable<'a, CW: Copy, R: RulesTrait> { +pub enum Wraparoundable<'a, CW: Copy, R: AccessRules> { FixedDot(FixedDot<'a, CW, R>), FixedBend(FixedBend<'a, CW, R>), LooseBend(LooseBend<'a, CW, R>), } -impl<'a, CW: Copy, R: RulesTrait> Wraparoundable<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> Wraparoundable<'a, CW, R> { pub fn new(index: WraparoundableIndex, drawing: &'a Drawing) -> Self { match index { WraparoundableIndex::FixedDot(dot) => drawing.primitive(dot).into(), @@ -62,19 +62,19 @@ impl<'a, CW: Copy, R: RulesTrait> Wraparoundable<'a, CW, R> { } } -impl<'a, CW: Copy, R: RulesTrait> GetWraparound for FixedDot<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetWraparound for FixedDot<'a, CW, R> { fn wraparound(&self) -> Option { self.first_rail() } } -impl<'a, CW: Copy, R: RulesTrait> GetWraparound for LooseBend<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetWraparound for LooseBend<'a, CW, R> { fn wraparound(&self) -> Option { self.outer() } } -impl<'a, CW: Copy, R: RulesTrait> GetWraparound for FixedBend<'a, CW, R> { +impl<'a, CW: Copy, R: AccessRules> GetWraparound for FixedBend<'a, CW, R> { fn wraparound(&self) -> Option { self.first_rail() } diff --git a/src/geometry/compound.rs b/src/geometry/compound.rs index 0be1fff..b5113c4 100644 --- a/src/geometry/compound.rs +++ b/src/geometry/compound.rs @@ -1,6 +1,6 @@ use crate::graph::{GenericIndex, GetPetgraphIndex}; -pub trait CompoundManagerTrait { +pub trait ManageCompounds { fn add_compound(&mut self, weight: CW) -> GenericIndex; fn remove_compound(&mut self, compound: GenericIndex); fn add_to_compound(&mut self, node: GenericIndex, compound: GenericIndex); diff --git a/src/geometry/geometry.rs b/src/geometry/geometry.rs index bfed0f6..0556286 100644 --- a/src/geometry/geometry.rs +++ b/src/geometry/geometry.rs @@ -14,11 +14,11 @@ use crate::{ dot::DotWeight, graph::{PrimitiveWeight, Retag}, primitive::Primitive, - rules::RulesTrait, + rules::AccessRules, seg::SegWeight, }, geometry::{ - compound::CompoundManagerTrait, + compound::ManageCompounds, primitive::{BendShape, DotShape, PrimitiveShape, SegShape}, }, graph::{GenericIndex, GetPetgraphIndex}, @@ -64,16 +64,16 @@ pub enum GenericNode { Compound(C), } -pub trait DotWeightTrait: GetPos + SetPos + GetWidth + Into + Copy {} -pub trait SegWeightTrait: GetWidth + Into + Copy {} -pub trait BendWeightTrait: GetOffset + SetOffset + GetWidth + Into + Copy {} +pub trait AccessDotWeight: GetPos + SetPos + GetWidth + Into + Copy {} +pub trait AccessSegWeight: GetWidth + Into + Copy {} +pub trait AccessBendWeight: GetOffset + SetOffset + GetWidth + Into + Copy {} #[derive(Debug)] pub struct Geometry< PW: GetWidth + TryInto + TryInto + TryInto + Retag + Copy, - DW: DotWeightTrait, - SW: SegWeightTrait, - BW: BendWeightTrait, + DW: AccessDotWeight, + SW: AccessSegWeight, + BW: AccessBendWeight, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Copy, DI: GetPetgraphIndex + Into + Copy, @@ -94,9 +94,9 @@ pub struct Geometry< impl< PW: GetWidth + TryInto + TryInto + TryInto + Retag + Copy, - DW: DotWeightTrait, - SW: SegWeightTrait, - BW: BendWeightTrait, + DW: AccessDotWeight, + SW: AccessSegWeight, + BW: AccessBendWeight, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Copy, DI: GetPetgraphIndex + Into + Copy, @@ -119,11 +119,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 fn add_seg>( + pub fn add_seg>( &mut self, from: DI, to: DI, @@ -146,7 +146,7 @@ impl< seg } - pub fn add_bend>( + pub fn add_bend>( &mut self, from: DI, to: DI, @@ -500,15 +500,15 @@ impl< impl< PW: GetWidth + TryInto + TryInto + TryInto + Retag + Copy, - DW: DotWeightTrait, - SW: SegWeightTrait, - BW: BendWeightTrait, + DW: AccessDotWeight, + SW: AccessSegWeight, + BW: AccessBendWeight, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Copy, DI: GetPetgraphIndex + Into + Copy, SI: GetPetgraphIndex + Into + Copy, BI: GetPetgraphIndex + Into + Copy, - > CompoundManagerTrait> for Geometry + > ManageCompounds> for Geometry { fn add_compound(&mut self, weight: CW) -> GenericIndex { GenericIndex::::new(self.graph.add_node(GenericNode::Compound(weight))) diff --git a/src/geometry/poly.rs b/src/geometry/poly.rs index 98caaf0..828e389 100644 --- a/src/geometry/poly.rs +++ b/src/geometry/poly.rs @@ -1,6 +1,6 @@ use geo::{Centroid, Contains, EuclideanLength, Point, Polygon}; -use crate::geometry::shape::{MeasureLength, ShapeTrait}; +use crate::geometry::shape::{AccessShape, MeasureLength}; #[derive(Debug, Clone, PartialEq)] pub struct PolyShape { @@ -19,7 +19,7 @@ impl MeasureLength for PolyShape { } } -impl ShapeTrait for PolyShape { +impl AccessShape for PolyShape { fn center(&self) -> Point { self.polygon.centroid().unwrap() } diff --git a/src/geometry/primitive.rs b/src/geometry/primitive.rs index fc402ff..35479d7 100644 --- a/src/geometry/primitive.rs +++ b/src/geometry/primitive.rs @@ -3,12 +3,12 @@ use geo::{point, polygon, Contains, EuclideanDistance, Intersects, Point, Polygo use rstar::{RTreeObject, AABB}; use crate::{ - geometry::shape::{MeasureLength, ShapeTrait}, + geometry::shape::{AccessShape, MeasureLength}, math::{self, Circle}, }; #[enum_dispatch] -pub trait PrimitiveShapeTrait: ShapeTrait { +pub trait AccessPrimitiveShape: AccessShape { fn priority(&self) -> usize; fn inflate(&self, margin: f64) -> PrimitiveShape; fn intersects(&self, other: &PrimitiveShape) -> bool; @@ -36,7 +36,7 @@ pub trait PrimitiveShapeTrait: ShapeTrait { } } -#[enum_dispatch(MeasureLength, ShapeTrait, PrimitiveShapeTrait)] +#[enum_dispatch(MeasureLength, AccessShape, AccessPrimitiveShape)] #[derive(Debug, Clone, Copy, PartialEq)] pub enum PrimitiveShape { // Intentionally in different order to reorder `self.intersects(...)` properly. @@ -56,7 +56,7 @@ impl MeasureLength for DotShape { } } -impl ShapeTrait for DotShape { +impl AccessShape for DotShape { fn center(&self) -> Point { self.circle.pos } @@ -66,7 +66,7 @@ impl ShapeTrait for DotShape { } } -impl PrimitiveShapeTrait for DotShape { +impl AccessPrimitiveShape for DotShape { fn priority(&self) -> usize { 3 } @@ -159,7 +159,7 @@ impl MeasureLength for SegShape { } } -impl ShapeTrait for SegShape { +impl AccessShape for SegShape { fn center(&self) -> Point { (self.from + self.to) / 2.0 } @@ -169,7 +169,7 @@ impl ShapeTrait for SegShape { } } -impl PrimitiveShapeTrait for SegShape { +impl AccessPrimitiveShape for SegShape { fn priority(&self) -> usize { 2 } @@ -286,7 +286,7 @@ impl MeasureLength for BendShape { } } -impl ShapeTrait for BendShape { +impl AccessShape for BendShape { fn center(&self) -> Point { let sum = (self.from - self.inner_circle.pos) + (self.to - self.inner_circle.pos); self.inner_circle.pos @@ -299,7 +299,7 @@ impl ShapeTrait for BendShape { } } -impl PrimitiveShapeTrait for BendShape { +impl AccessPrimitiveShape for BendShape { fn priority(&self) -> usize { 1 } @@ -375,6 +375,6 @@ impl PrimitiveShapeTrait for BendShape { impl RTreeObject for PrimitiveShape { type Envelope = AABB<[f64; 2]>; fn envelope(&self) -> Self::Envelope { - PrimitiveShapeTrait::envelope(self, 0.0) + AccessPrimitiveShape::envelope(self, 0.0) } } diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs index 79faf39..786c52d 100644 --- a/src/geometry/shape.rs +++ b/src/geometry/shape.rs @@ -12,12 +12,12 @@ pub trait MeasureLength { } #[enum_dispatch] -pub trait ShapeTrait: MeasureLength { +pub trait AccessShape: MeasureLength { fn center(&self) -> Point; fn contains_point(&self, p: Point) -> bool; } -#[enum_dispatch(MeasureLength, ShapeTrait)] +#[enum_dispatch(MeasureLength, AccessShape)] #[derive(Debug, Clone, PartialEq)] pub enum Shape { Dot(DotShape), diff --git a/src/geometry/with_rtree.rs b/src/geometry/with_rtree.rs index 041ad2a..4cd6c41 100644 --- a/src/geometry/with_rtree.rs +++ b/src/geometry/with_rtree.rs @@ -8,10 +8,10 @@ use rstar::{primitives::GeomWithData, Envelope, RTree, RTreeObject, AABB}; use crate::{ drawing::graph::{GetLayer, Retag}, geometry::{ - compound::CompoundManagerTrait, - primitive::{PrimitiveShape, PrimitiveShapeTrait}, - BendWeightTrait, DotWeightTrait, GenericNode, Geometry, GeometryLabel, GetWidth, - SegWeightTrait, + compound::ManageCompounds, + primitive::{AccessPrimitiveShape, PrimitiveShape}, + AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel, + GetWidth, }, graph::{GenericIndex, GetPetgraphIndex}, }; @@ -39,9 +39,9 @@ pub type BboxedIndex = GeomWithData; #[derive(Debug)] pub struct GeometryWithRtree< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: DotWeightTrait + GetLayer, - SW: SegWeightTrait + GetLayer, - BW: BendWeightTrait + GetLayer, + DW: AccessDotWeight + GetLayer, + SW: AccessSegWeight + GetLayer, + BW: AccessBendWeight + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Copy, DI: GetPetgraphIndex + Into + Copy, @@ -65,9 +65,9 @@ pub struct GeometryWithRtree< #[debug_invariant(self.geometry.graph().node_count() == self.rtree.size())] impl< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: DotWeightTrait + GetLayer, - SW: SegWeightTrait + GetLayer, - BW: BendWeightTrait + GetLayer, + DW: AccessDotWeight + GetLayer, + SW: AccessSegWeight + GetLayer, + BW: AccessBendWeight + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + PartialEq + Copy, DI: GetPetgraphIndex + Into + Copy, @@ -91,7 +91,7 @@ impl< } } - pub fn add_dot + GetLayer>(&mut self, weight: W) -> GenericIndex + pub fn add_dot + GetLayer>(&mut self, weight: W) -> GenericIndex where GenericIndex: Into, { @@ -107,7 +107,7 @@ impl< dot } - pub fn add_seg + GetLayer>( + pub fn add_seg + GetLayer>( &mut self, from: DI, to: DI, @@ -128,7 +128,7 @@ impl< seg } - pub fn add_bend + GetLayer>( + pub fn add_bend + GetLayer>( &mut self, from: DI, to: DI, @@ -255,9 +255,9 @@ impl< impl< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: DotWeightTrait + GetLayer, - SW: SegWeightTrait + GetLayer, - BW: BendWeightTrait + GetLayer, + DW: AccessDotWeight + GetLayer, + SW: AccessSegWeight + GetLayer, + BW: AccessBendWeight + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + PartialEq + Copy, DI: GetPetgraphIndex + Into + Copy, @@ -386,15 +386,15 @@ impl< impl< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: DotWeightTrait + GetLayer, - SW: SegWeightTrait + GetLayer, - BW: BendWeightTrait + GetLayer, + DW: AccessDotWeight + GetLayer, + SW: AccessSegWeight + GetLayer, + BW: AccessBendWeight + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + PartialEq + Copy, DI: GetPetgraphIndex + Into + Copy, SI: GetPetgraphIndex + Into + Copy, BI: GetPetgraphIndex + Into + Copy, - > CompoundManagerTrait> + > ManageCompounds> for GeometryWithRtree { fn add_compound(&mut self, weight: CW) -> GenericIndex { diff --git a/src/layout/layout.rs b/src/layout/layout.rs index 3f2efba..85268ed 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -11,7 +11,7 @@ use crate::{ dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight}, graph::{GetMaybeNet, PrimitiveIndex}, primitive::{GetJoints, GetOtherJoint}, - rules::RulesTrait, + rules::AccessRules, seg::{ FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex, SeqLooseSegWeight, @@ -20,7 +20,7 @@ use crate::{ Drawing, Infringement, LayoutException, }, geometry::{ - compound::CompoundManagerTrait, primitive::PrimitiveShapeTrait, shape::MeasureLength, + compound::ManageCompounds, primitive::AccessPrimitiveShape, shape::MeasureLength, GenericNode, }, graph::{GenericIndex, GetPetgraphIndex}, @@ -40,11 +40,11 @@ pub enum CompoundWeight { pub type NodeIndex = GenericNode>; #[derive(Debug)] -pub struct Layout { +pub struct Layout { drawing: Drawing, } -impl Layout { +impl Layout { pub fn new(drawing: Drawing) -> Self { Self { drawing } } diff --git a/src/layout/via.rs b/src/layout/via.rs index 446509b..f6338dd 100644 --- a/src/layout/via.rs +++ b/src/layout/via.rs @@ -1,9 +1,9 @@ use serde::{Deserialize, Serialize}; use crate::{ - drawing::{graph::GetMaybeNet, primitive::MakePrimitiveShape, rules::RulesTrait}, + drawing::{graph::GetMaybeNet, primitive::MakePrimitiveShape, rules::AccessRules}, geometry::{ - compound::CompoundManagerTrait, + compound::ManageCompounds, primitive::{DotShape, PrimitiveShape}, }, graph::{GenericIndex, GetPetgraphIndex}, @@ -12,18 +12,18 @@ use crate::{ }; #[derive(Debug)] -pub struct Via<'a, R: RulesTrait> { +pub struct Via<'a, R: AccessRules> { pub index: GenericIndex, layout: &'a Layout, } -impl<'a, R: RulesTrait> Via<'a, R> { +impl<'a, R: AccessRules> Via<'a, R> { pub fn new(index: GenericIndex, layout: &'a Layout) -> Self { Self { index, layout } } } -impl<'a, R: RulesTrait> GetMaybeNet for Via<'a, R> { +impl<'a, R: AccessRules> GetMaybeNet for Via<'a, R> { fn maybe_net(&self) -> Option { self.layout .drawing() @@ -32,7 +32,7 @@ impl<'a, R: RulesTrait> GetMaybeNet for Via<'a, R> { } } -impl<'a, R: RulesTrait> MakePrimitiveShape for Via<'a, R> { +impl<'a, R: AccessRules> MakePrimitiveShape for Via<'a, R> { fn shape(&self) -> PrimitiveShape { if let CompoundWeight::Via(weight) = self.layout.drawing().compound_weight(self.index.into()) diff --git a/src/layout/zone.rs b/src/layout/zone.rs index 44ec117..f2c9fbd 100644 --- a/src/layout/zone.rs +++ b/src/layout/zone.rs @@ -7,10 +7,10 @@ use crate::{ dot::FixedDotIndex, graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex}, primitive::GetLimbs, - rules::RulesTrait, + rules::AccessRules, seg::SegIndex, }, - geometry::{compound::CompoundManagerTrait, poly::PolyShape, GetPos}, + geometry::{compound::ManageCompounds, poly::PolyShape, GetPos}, graph::{GenericIndex, GetPetgraphIndex}, layout::{CompoundWeight, Layout}, }; @@ -26,12 +26,12 @@ pub trait GetMaybeApex { } #[derive(Debug)] -pub struct Zone<'a, R: RulesTrait> { +pub struct Zone<'a, R: AccessRules> { pub index: GenericIndex, layout: &'a Layout, } -impl<'a, R: RulesTrait> Zone<'a, R> { +impl<'a, R: AccessRules> Zone<'a, R> { pub fn new(index: GenericIndex, layout: &'a Layout) -> Self { Self { index, layout } } @@ -48,7 +48,7 @@ impl<'a, R: RulesTrait> Zone<'a, R> { } } -impl<'a, R: RulesTrait> GetLayer for Zone<'a, R> { +impl<'a, R: AccessRules> GetLayer for Zone<'a, R> { fn layer(&self) -> usize { if let CompoundWeight::Zone(weight) = self.layout.drawing().compound_weight(self.index.into()) @@ -60,7 +60,7 @@ impl<'a, R: RulesTrait> GetLayer for Zone<'a, R> { } } -impl<'a, R: RulesTrait> GetMaybeNet for Zone<'a, R> { +impl<'a, R: AccessRules> GetMaybeNet for Zone<'a, R> { fn maybe_net(&self) -> Option { self.layout .drawing() @@ -69,7 +69,7 @@ impl<'a, R: RulesTrait> GetMaybeNet for Zone<'a, R> { } } -impl<'a, R: RulesTrait> MakePolyShape for Zone<'a, R> { +impl<'a, R: AccessRules> MakePolyShape for Zone<'a, R> { fn shape(&self) -> PolyShape { PolyShape { polygon: Polygon::new( @@ -103,7 +103,7 @@ impl<'a, R: RulesTrait> MakePolyShape for Zone<'a, R> { } } -impl<'a, R: RulesTrait> GetMaybeApex for Zone<'a, R> { +impl<'a, R: AccessRules> GetMaybeApex for Zone<'a, R> { fn maybe_apex(&self) -> Option { self.layout .drawing() diff --git a/src/router/draw.rs b/src/router/draw.rs index dcbc16e..72317bc 100644 --- a/src/router/draw.rs +++ b/src/router/draw.rs @@ -9,9 +9,9 @@ use crate::{ dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight}, graph::{GetLayer, GetMaybeNet, MakePrimitive}, guide::Guide, - head::{CaneHead, Head, HeadTrait}, + head::{CaneHead, GetFace, Head}, primitive::GetOtherJoint, - rules::RulesTrait, + rules::AccessRules, seg::{LoneLooseSegWeight, SeqLooseSegWeight}, wraparoundable::WraparoundableIndex, Infringement, LayoutException, @@ -31,11 +31,11 @@ pub enum DrawException { CannotWrapAround(WraparoundableIndex, #[source] LayoutException), } -pub struct Draw<'a, R: RulesTrait> { +pub struct Draw<'a, R: AccessRules> { layout: &'a mut Layout, } -impl<'a, R: RulesTrait> Draw<'a, R> { +impl<'a, R: AccessRules> Draw<'a, R> { pub fn new(layout: &'a mut Layout) -> Self { Self { layout } } diff --git a/src/router/navmesh.rs b/src/router/navmesh.rs index f1146e1..ae79b9a 100644 --- a/src/router/navmesh.rs +++ b/src/router/navmesh.rs @@ -20,10 +20,10 @@ use crate::{ dot::FixedDotIndex, graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex}, primitive::{MakePrimitiveShape, Primitive}, - rules::RulesTrait, + rules::AccessRules, Drawing, }, - geometry::shape::ShapeTrait, + geometry::shape::AccessShape, graph::GetPetgraphIndex, layout::Layout, router::astar::MakeEdgeRef, @@ -115,7 +115,7 @@ pub struct Navmesh { impl Navmesh { pub fn new( - layout: &Layout, + layout: &Layout, source: FixedDotIndex, target: FixedDotIndex, ) -> Result { diff --git a/src/router/route.rs b/src/router/route.rs index b15d657..802b816 100644 --- a/src/router/route.rs +++ b/src/router/route.rs @@ -12,9 +12,9 @@ use crate::{ dot::{DotIndex, FixedDotIndex}, graph::{MakePrimitive, PrimitiveIndex}, primitive::MakePrimitiveShape, - rules::RulesTrait, + rules::AccessRules, }, - geometry::{primitive::PrimitiveShapeTrait, shape::ShapeTrait}, + geometry::{primitive::AccessPrimitiveShape, shape::AccessShape}, graph::GetPetgraphIndex, layout::Layout, router::{ @@ -37,7 +37,7 @@ pub struct Route { impl Route { pub fn new( - router: &mut Router, + router: &mut Router, from: FixedDotIndex, to: FixedDotIndex, width: f64, @@ -47,7 +47,7 @@ impl Route { } pub fn new_from_navmesh( - router: &mut Router, + router: &mut Router, navmesh: Navmesh, width: f64, ) -> Self { @@ -66,7 +66,7 @@ impl Route { pub fn step( &mut self, - router: &mut Router, + router: &mut Router, ) -> Result { let tracer = Tracer::new(router.layout_mut()); let target = self.astar.graph.destination(); diff --git a/src/router/router.rs b/src/router/router.rs index 91b0e3f..890502b 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -7,13 +7,13 @@ use crate::{ band::BandFirstSegIndex, dot::{DotIndex, FixedDotIndex}, graph::{MakePrimitive, PrimitiveIndex}, - head::{Head, HeadTrait}, + head::{GetFace, Head}, primitive::MakePrimitiveShape, - rules::RulesTrait, + rules::AccessRules, }, geometry::{ - primitive::PrimitiveShapeTrait, - shape::{MeasureLength, ShapeTrait}, + primitive::AccessPrimitiveShape, + shape::{AccessShape, MeasureLength}, }, graph::GetPetgraphIndex, layout::Layout, @@ -40,13 +40,13 @@ pub enum RouterStatus { } #[derive(Debug)] -pub struct RouterAstarStrategy<'a, R: RulesTrait> { +pub struct RouterAstarStrategy<'a, R: AccessRules> { pub tracer: Tracer<'a, R>, pub trace: &'a mut Trace, pub target: FixedDotIndex, } -impl<'a, R: RulesTrait> RouterAstarStrategy<'a, R> { +impl<'a, R: AccessRules> RouterAstarStrategy<'a, R> { pub fn new(tracer: Tracer<'a, R>, trace: &'a mut Trace, target: FixedDotIndex) -> Self { Self { tracer, @@ -71,7 +71,7 @@ impl<'a, R: RulesTrait> RouterAstarStrategy<'a, R> { } } -impl<'a, R: RulesTrait> AstarStrategy +impl<'a, R: AccessRules> AstarStrategy for RouterAstarStrategy<'a, R> { fn is_goal( @@ -132,11 +132,11 @@ impl<'a, R: RulesTrait> AstarStrategy } #[derive(Debug)] -pub struct Router<'a, R: RulesTrait> { +pub struct Router<'a, R: AccessRules> { layout: &'a mut Layout, } -impl<'a, R: RulesTrait> Router<'a, R> { +impl<'a, R: AccessRules> Router<'a, R> { pub fn new(layout: &'a mut Layout) -> Self { Self { layout } } diff --git a/src/router/trace.rs b/src/router/trace.rs index d60ac82..126cd82 100644 --- a/src/router/trace.rs +++ b/src/router/trace.rs @@ -7,7 +7,7 @@ use crate::{ dot::FixedDotIndex, graph::PrimitiveIndex, head::{BareHead, CaneHead, Head}, - rules::RulesTrait, + rules::AccessRules, }, router::{ draw::Draw, @@ -37,7 +37,7 @@ impl Trace { #[debug_ensures(ret.is_err() -> self.path.len() == old(self.path.len()))] pub fn step( &mut self, - tracer: &mut Tracer, + tracer: &mut Tracer, navmesh: &Navmesh, to: NavvertexIndex, width: f64, @@ -49,7 +49,7 @@ impl Trace { } #[debug_ensures(self.path.len() == old(self.path.len() - 1))] - pub fn undo_step(&mut self, tracer: &mut Tracer) { + pub fn undo_step(&mut self, tracer: &mut Tracer) { if let Head::Cane(head) = self.head { self.head = Draw::new(tracer.layout).undo_cane(head).unwrap(); } else { @@ -61,7 +61,7 @@ impl Trace { fn wrap( &mut self, - tracer: &mut Tracer, + tracer: &mut Tracer, navmesh: &Navmesh, head: Head, around: NavvertexIndex, @@ -84,7 +84,7 @@ impl Trace { fn wrap_around_fixed_dot( &mut self, - tracer: &mut Tracer, + tracer: &mut Tracer, head: Head, around: FixedDotIndex, cw: bool, @@ -95,7 +95,7 @@ impl Trace { fn wrap_around_loose_bend( &mut self, - tracer: &mut Tracer, + tracer: &mut Tracer, head: Head, around: LooseBendIndex, cw: bool, diff --git a/src/router/tracer.rs b/src/router/tracer.rs index ffdcb6d..de4ad28 100644 --- a/src/router/tracer.rs +++ b/src/router/tracer.rs @@ -8,7 +8,7 @@ use thiserror::Error; use crate::{ drawing::{ band::BandFirstSegIndex, bend::LooseBendIndex, dot::FixedDotIndex, graph::PrimitiveIndex, - rules::RulesTrait, + rules::AccessRules, }, layout::Layout, router::{ @@ -27,11 +27,11 @@ pub enum TracerException { } #[derive(Debug)] -pub struct Tracer<'a, R: RulesTrait> { +pub struct Tracer<'a, R: AccessRules> { pub layout: &'a mut Layout, } -impl<'a, R: RulesTrait> Tracer<'a, R> { +impl<'a, R: AccessRules> Tracer<'a, R> { pub fn new(layout: &mut Layout) -> Tracer { Tracer { layout } } diff --git a/src/specctra/design.rs b/src/specctra/design.rs index 2958db2..121980f 100644 --- a/src/specctra/design.rs +++ b/src/specctra/design.rs @@ -4,7 +4,7 @@ use geo::{point, Point, Rotate}; use thiserror::Error; use crate::{ - board::{mesadata::MesadataTrait, Board}, + board::{mesadata::AccessMesadata, Board}, drawing::{dot::FixedDotWeight, seg::FixedSegWeight, Drawing}, layout::{zone::SolidZoneWeight, Layout}, math::Circle, diff --git a/src/specctra/mesadata.rs b/src/specctra/mesadata.rs index aa9f0f1..c53c35e 100644 --- a/src/specctra/mesadata.rs +++ b/src/specctra/mesadata.rs @@ -3,8 +3,8 @@ use std::collections::HashMap; use bimap::BiHashMap; use crate::{ - board::mesadata::MesadataTrait, - drawing::rules::{Conditions, RulesTrait}, + board::mesadata::AccessMesadata, + drawing::rules::{AccessRules, Conditions}, specctra::structure::Pcb, }; @@ -92,7 +92,7 @@ impl SpecctraMesadata { } } -impl RulesTrait for SpecctraMesadata { +impl AccessRules for SpecctraMesadata { fn clearance(&self, conditions1: &Conditions, conditions2: &Conditions) -> f64 { let (Some(net1), Some(net2)) = (conditions1.maybe_net, conditions2.maybe_net) else { return 0.0; @@ -121,7 +121,7 @@ impl RulesTrait for SpecctraMesadata { } } -impl MesadataTrait for SpecctraMesadata { +impl AccessMesadata for SpecctraMesadata { fn bename_layer(&mut self, layer: usize, layername: String) { self.layer_layername.insert(layer, layername); } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 3753566..7f31658 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -7,7 +7,7 @@ use topola::{ invoker::{Invoker, InvokerError}, Autorouter, }, - board::{mesadata::MesadataTrait, Board}, + board::{mesadata::AccessMesadata, Board}, drawing::graph::{GetLayer, GetMaybeNet}, graph::GetPetgraphIndex, specctra::{design::SpecctraDesign, mesadata::SpecctraMesadata}, @@ -56,7 +56,7 @@ pub fn replay_and_assert(invoker: &mut Invoker, filename: &str } pub fn assert_single_layer_groundless_autoroute( - autorouter: &mut Autorouter, + autorouter: &mut Autorouter, layername: &str, ) { let unionfind = unionfind(autorouter); @@ -139,7 +139,7 @@ pub fn assert_single_layer_groundless_autoroute( }*/ pub fn assert_band_length( - board: &Board, + board: &Board, source: &str, target: &str, length: f64, @@ -150,7 +150,7 @@ pub fn assert_band_length( assert!((band_length - length).abs() < epsilon); } -fn unionfind(autorouter: &mut Autorouter) -> UnionFind> { +fn unionfind(autorouter: &mut Autorouter) -> UnionFind> { for ratline in autorouter.ratsnest().graph().edge_indices() { // Accessing endpoints may create new dots because apex construction is lazy, so we access // tem all before starting unionfind, as it requires a constant index bound. diff --git a/tests/multilayer.rs b/tests/multilayer.rs index e9bc68b..87509c2 100644 --- a/tests/multilayer.rs +++ b/tests/multilayer.rs @@ -3,7 +3,7 @@ use topola::{ invoker::{Command, InvokerError}, AutorouterError, }, - board::mesadata::MesadataTrait, + board::mesadata::AccessMesadata, layout::via::ViaWeight, math::Circle, };