refactor(drawing/primitive): Rename Primitive<...> to PrimitiveRef<...> with its variants

This commit is contained in:
Mikolaj Wielgus 2025-09-12 13:55:26 +02:00
parent 3b520b56c6
commit 7c4bc87301
31 changed files with 220 additions and 207 deletions

View File

@ -14,7 +14,7 @@ use topola::{
drawing::{ drawing::{
bend::BendIndex, bend::BendIndex,
dot::DotIndex, dot::DotIndex,
graph::{MakePrimitive, PrimitiveIndex}, graph::{MakePrimitiveRef, PrimitiveIndex},
head::GetFace, head::GetFace,
primitive::MakePrimitiveShape, primitive::MakePrimitiveShape,
}, },
@ -91,7 +91,7 @@ impl<'a> Displayer<'a> {
for i in (0..self.workspace.appearance_panel.visible.len()).rev() { for i in (0..self.workspace.appearance_panel.visible.len()).rev() {
if self.workspace.appearance_panel.visible[i] { if self.workspace.appearance_panel.visible[i] {
for primitive in board.layout().drawing().layer_primitive_nodes(i) { for primitive in board.layout().drawing().layer_primitive_nodes(i) {
let shape = primitive.primitive(board.layout().drawing()).shape(); let shape = primitive.primitive_ref(board.layout().drawing()).shape();
let color = if self let color = if self
.workspace .workspace
@ -181,12 +181,12 @@ impl<'a> Displayer<'a> {
for edge in navmesh.edge_references() { for edge in navmesh.edge_references() {
let mut from = let mut from =
PrimitiveIndex::from(navmesh.node_weight(edge.source()).unwrap().binavnode) PrimitiveIndex::from(navmesh.node_weight(edge.source()).unwrap().binavnode)
.primitive(board.layout().drawing()) .primitive_ref(board.layout().drawing())
.shape() .shape()
.center(); .center();
let mut to = let mut to =
PrimitiveIndex::from(navmesh.node_weight(edge.target()).unwrap().binavnode) PrimitiveIndex::from(navmesh.node_weight(edge.target()).unwrap().binavnode)
.primitive(board.layout().drawing()) .primitive_ref(board.layout().drawing())
.shape() .shape()
.center(); .center();
@ -280,7 +280,7 @@ impl<'a> Displayer<'a> {
let primitive = let primitive =
PrimitiveIndex::from(navmesh.node_weight(navnode).unwrap().binavnode); PrimitiveIndex::from(navmesh.node_weight(navnode).unwrap().binavnode);
let mut pos = primitive let mut pos = primitive
.primitive(board.layout().drawing()) .primitive_ref(board.layout().drawing())
.shape() .shape()
.center(); .center();
@ -349,11 +349,11 @@ impl<'a> Displayer<'a> {
for edge in navmesh.prenavmesh().triangulation().edge_references() { for edge in navmesh.prenavmesh().triangulation().edge_references() {
let from = PrimitiveIndex::from(BinavnodeNodeIndex::from(edge.source())) let from = PrimitiveIndex::from(BinavnodeNodeIndex::from(edge.source()))
.primitive(board.layout().drawing()) .primitive_ref(board.layout().drawing())
.shape() .shape()
.center(); .center();
let to = PrimitiveIndex::from(BinavnodeNodeIndex::from(edge.target())) let to = PrimitiveIndex::from(BinavnodeNodeIndex::from(edge.target()))
.primitive(board.layout().drawing()) .primitive_ref(board.layout().drawing())
.shape() .shape()
.center(); .center();
@ -411,7 +411,9 @@ impl<'a> Displayer<'a> {
use topola::router::ng::pie::NavmeshIndex; use topola::router::ng::pie::NavmeshIndex;
let mut map = BTreeMap::new(); let mut map = BTreeMap::new();
let resolve_primal = |p: &topola::drawing::dot::FixedDotIndex| { let resolve_primal = |p: &topola::drawing::dot::FixedDotIndex| {
(*p).primitive(board.layout().drawing()).shape().center() (*p).primitive_ref(board.layout().drawing())
.shape()
.center()
}; };
for (nidx, node) in &*navmesh.nodes { for (nidx, node) in &*navmesh.nodes {

View File

@ -14,7 +14,7 @@ use crate::{
autoroute::AutorouteExecutionStepper, presorter::SccIntersectionsAndLengthPresorter, autoroute::AutorouteExecutionStepper, presorter::SccIntersectionsAndLengthPresorter,
ratline::RatlineIndex, Autorouter, AutorouterOptions, ratline::RatlineIndex, Autorouter, AutorouterOptions,
}, },
drawing::graph::MakePrimitive, drawing::graph::MakePrimitiveRef,
geometry::{GenericNode, GetLayer}, geometry::{GenericNode, GetLayer},
graph::MakeRef, graph::MakeRef,
}; };
@ -141,7 +141,7 @@ impl PermuteRatlines for RatlineCutsRatlinePermuter {
.bands_between_nodes( .bands_between_nodes(
endpoint_dots endpoint_dots
.0 .0
.primitive(autorouter.board().layout().drawing()) .primitive_ref(autorouter.board().layout().drawing())
.layer(), .layer(),
GenericNode::Primitive(endpoint_dots.0.into()), GenericNode::Primitive(endpoint_dots.0.into()),
GenericNode::Primitive(endpoint_dots.1.into()), GenericNode::Primitive(endpoint_dots.1.into()),

View File

@ -10,7 +10,7 @@ use crate::{
drawing::{ drawing::{
band::BandTermsegIndex, band::BandTermsegIndex,
dot::FixedDotIndex, dot::FixedDotIndex,
graph::{GetMaybeNet, MakePrimitive, PrimitiveIndex}, graph::{GetMaybeNet, MakePrimitiveRef, PrimitiveIndex},
}, },
geometry::{shape::MeasureLength, GetLayer}, geometry::{shape::MeasureLength, GetLayer},
graph::MakeRef, graph::MakeRef,
@ -91,14 +91,14 @@ impl<'a, M: AccessMesadata> RatlineRef<'a, M> {
pub fn layer(&self) -> usize { pub fn layer(&self) -> usize {
self.endpoint_dots() self.endpoint_dots()
.0 .0
.primitive(self.autorouter.board().layout().drawing()) .primitive_ref(self.autorouter.board().layout().drawing())
.layer() .layer()
} }
pub fn net(&self) -> usize { pub fn net(&self) -> usize {
self.endpoint_dots() self.endpoint_dots()
.0 .0
.primitive(self.autorouter.board().layout().drawing()) .primitive_ref(self.autorouter.board().layout().drawing())
.maybe_net() .maybe_net()
.unwrap() .unwrap()
} }
@ -114,7 +114,7 @@ impl<'a, M: AccessMesadata> RatlineRef<'a, M> {
pub fn cut_other_net_primitives(&self) -> impl Iterator<Item = PrimitiveIndex> + '_ { pub fn cut_other_net_primitives(&self) -> impl Iterator<Item = PrimitiveIndex> + '_ {
self.cut_primitives().filter(|primitive_node| { self.cut_primitives().filter(|primitive_node| {
primitive_node primitive_node
.primitive(self.autorouter.board().layout().drawing()) .primitive_ref(self.autorouter.board().layout().drawing())
.maybe_net() .maybe_net()
.map(|net| net != self.net()) .map(|net| net != self.net())
.unwrap_or(true) .unwrap_or(true)

View File

@ -19,7 +19,7 @@ use crate::{
drawing::{ drawing::{
band::BandTermsegIndex, band::BandTermsegIndex,
dot::FixedDotIndex, dot::FixedDotIndex,
graph::{GetMaybeNet, MakePrimitive, PrimitiveIndex}, graph::{GetMaybeNet, MakePrimitiveRef, PrimitiveIndex},
primitive::MakePrimitiveShape, primitive::MakePrimitiveShape,
rules::AccessRules, rules::AccessRules,
}, },
@ -108,7 +108,7 @@ impl Ratsnest {
handle_ratvertex_weight( handle_ratvertex_weight(
layout.drawing().primitive(dot).maybe_net(), layout.drawing().primitive(dot).maybe_net(),
RatvertexIndex::FixedDot(dot), RatvertexIndex::FixedDot(dot),
node.primitive(layout.drawing()).shape().center(), node.primitive_ref(layout.drawing()).shape().center(),
)?; )?;
} }
} }

View File

@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
use crate::{ use crate::{
board::{AccessMesadata, BandName, Board, ResolvedSelector}, board::{AccessMesadata, BandName, Board, ResolvedSelector},
drawing::graph::{MakePrimitive, PrimitiveIndex}, drawing::graph::{MakePrimitiveRef, PrimitiveIndex},
geometry::{ geometry::{
shape::{AccessShape, Shape}, shape::{AccessShape, Shape},
GenericNode, GetLayer, GenericNode, GetLayer,
@ -31,7 +31,7 @@ impl PinSelector {
) -> Option<PinSelector> { ) -> Option<PinSelector> {
let layer = match node { let layer = match node {
NodeIndex::Primitive(primitive) => { NodeIndex::Primitive(primitive) => {
primitive.primitive(board.layout().drawing()).layer() primitive.primitive_ref(board.layout().drawing()).layer()
} }
NodeIndex::Compound(compound) => { NodeIndex::Compound(compound) => {
if let CompoundWeight::Poly(..) = board.layout().drawing().compound_weight(compound) if let CompoundWeight::Poly(..) = board.layout().drawing().compound_weight(compound)

View File

@ -40,11 +40,11 @@ pub enum ResolvedSelector<'a> {
impl<'a> ResolvedSelector<'a> { impl<'a> ResolvedSelector<'a> {
pub fn try_from_node(board: &'a Board<impl AccessMesadata>, node: NodeIndex) -> Option<Self> { pub fn try_from_node(board: &'a Board<impl AccessMesadata>, node: NodeIndex) -> Option<Self> {
use crate::{drawing::graph::MakePrimitive, graph::GetPetgraphIndex}; use crate::{drawing::graph::MakePrimitiveRef, graph::GetPetgraphIndex};
let (layer, loose) = match node { let (layer, loose) = match node {
NodeIndex::Primitive(primitive) => ( NodeIndex::Primitive(primitive) => (
primitive.primitive(board.layout().drawing()).layer(), primitive.primitive_ref(board.layout().drawing()).layer(),
primitive.try_into().ok(), primitive.try_into().ok(),
), ),
NodeIndex::Compound(compound) => { NodeIndex::Compound(compound) => {

View File

@ -8,7 +8,7 @@ use crate::{
}; };
use super::{ use super::{
graph::MakePrimitive, graph::MakePrimitiveRef,
loose::{GetPrevNextLoose, LooseIndex}, loose::{GetPrevNextLoose, LooseIndex},
primitive::MakePrimitiveShape, primitive::MakePrimitiveShape,
rules::AccessRules, rules::AccessRules,
@ -42,7 +42,7 @@ impl<'a, CW: 'a, Cel: 'a, R: 'a> BandRef<'a, CW, Cel, R> {
impl<CW: Clone, Cel: Copy, R: AccessRules> GetLayer for BandRef<'_, CW, Cel, R> { impl<CW: Clone, Cel: Copy, R: AccessRules> GetLayer for BandRef<'_, CW, Cel, R> {
fn layer(&self) -> usize { fn layer(&self) -> usize {
self.first_seg.primitive(self.drawing).layer() self.first_seg.primitive_ref(self.drawing).layer()
} }
} }
@ -59,7 +59,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> MeasureLength for BandRef<'_, CW, Cel
let mut length = 0.0; let mut length = 0.0;
while let Some(loose) = maybe_loose { while let Some(loose) = maybe_loose {
length += loose.primitive(self.drawing).shape().length(); length += loose.primitive_ref(self.drawing).shape().length();
let prev_prev = prev; let prev_prev = prev;
prev = maybe_loose; prev = maybe_loose;

View File

@ -6,8 +6,8 @@ use enum_dispatch::enum_dispatch;
use crate::{ use crate::{
drawing::{ drawing::{
graph::{GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight}, graph::{GetMaybeNet, MakePrimitiveRef, PrimitiveIndex, PrimitiveWeight},
primitive::{GenericPrimitive, Primitive}, primitive::{GenericPrimitive, PrimitiveRef},
rules::AccessRules, rules::AccessRules,
Drawing, Drawing,
}, },
@ -17,7 +17,7 @@ use crate::{
use petgraph::stable_graph::NodeIndex; use petgraph::stable_graph::NodeIndex;
#[enum_dispatch(GetPetgraphIndex, MakePrimitive)] #[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum BendIndex { pub enum BendIndex {
Fixed(FixedBendIndex), Fixed(FixedBendIndex),

View File

@ -6,7 +6,7 @@ use super::{
bend::LooseBendIndex, bend::LooseBendIndex,
dot::LooseDotIndex, dot::LooseDotIndex,
graph::PrimitiveIndex, graph::PrimitiveIndex,
primitive::{GetInterior, GetJoints, GetOtherJoint, LooseBend, LooseDot}, primitive::{GetInterior, GetJoints, GetOtherJoint, LooseBendRef, LooseDotRef},
rules::AccessRules, rules::AccessRules,
seg::SeqLooseSegIndex, seg::SeqLooseSegIndex,
Drawing, Drawing,
@ -30,9 +30,9 @@ impl Cane {
dot: LooseDotIndex, dot: LooseDotIndex,
drawing: &Drawing<impl Clone, impl Copy, impl AccessRules>, drawing: &Drawing<impl Clone, impl Copy, impl AccessRules>,
) -> Self { ) -> Self {
let bend = LooseDot::new(dot, drawing).bend(); let bend = LooseDotRef::new(dot, drawing).bend();
let dot = LooseBend::new(bend, drawing).other_joint(dot); let dot = LooseBendRef::new(bend, drawing).other_joint(dot);
let seg = LooseDot::new(dot, drawing).seg().unwrap(); let seg = LooseDotRef::new(dot, drawing).seg().unwrap();
Self { bend, dot, seg } Self { bend, dot, seg }
} }
} }

View File

@ -9,8 +9,8 @@ use petgraph::stable_graph::NodeIndex;
use crate::{ use crate::{
drawing::{ drawing::{
graph::{GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight}, graph::{GetMaybeNet, MakePrimitiveRef, PrimitiveIndex, PrimitiveWeight},
primitive::{GenericPrimitive, Primitive}, primitive::{GenericPrimitive, PrimitiveRef},
rules::AccessRules, rules::AccessRules,
Drawing, Drawing,
}, },
@ -19,7 +19,7 @@ use crate::{
math::Circle, math::Circle,
}; };
#[enum_dispatch(GetPetgraphIndex, MakePrimitive)] #[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum DotIndex { pub enum DotIndex {
Fixed(FixedDotIndex), Fixed(FixedDotIndex),

View File

@ -18,7 +18,7 @@ use crate::{
cane::Cane, cane::Cane,
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight}, dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
gear::GearIndex, gear::GearIndex,
graph::{GetMaybeNet, IsInLayer, MakePrimitive, PrimitiveIndex, PrimitiveWeight}, graph::{GetMaybeNet, IsInLayer, MakePrimitiveRef, PrimitiveIndex, PrimitiveWeight},
loose::{GetPrevNextLoose, Loose, LooseIndex}, loose::{GetPrevNextLoose, Loose, LooseIndex},
primitive::{ primitive::{
GenericPrimitive, GetCore, GetJoints, GetLimbs, GetOtherJoint, MakePrimitiveShape, GenericPrimitive, GetCore, GetJoints, GetLimbs, GetOtherJoint, MakePrimitiveShape,
@ -467,8 +467,8 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
// Check whether the the seg is terminal, that is, whether at // Check whether the the seg is terminal, that is, whether at
// least one of its two joints is a fixed dot. // least one of its two joints is a fixed dot.
if matches!(from, DotIndex::Fixed(..)) || matches!(to, DotIndex::Fixed(..)) { if matches!(from, DotIndex::Fixed(..)) || matches!(to, DotIndex::Fixed(..)) {
collider.primitive(drawing).maybe_net() collider.primitive_ref(drawing).maybe_net()
!= collidee.primitive(drawing).maybe_net() != collidee.primitive_ref(drawing).maybe_net()
} else { } else {
// Cane is non-initial. // Cane is non-initial.
true true
@ -501,7 +501,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
// It makes no sense to wrap something around or under one of its connectables. // It makes no sense to wrap something around or under one of its connectables.
// //
if let Some(net) = weight.maybe_net() { if let Some(net) = weight.maybe_net() {
if let Some(around_net) = around.primitive(self).maybe_net() { if let Some(around_net) = around.primitive_ref(self).maybe_net() {
if net == around_net { if net == around_net {
return Err(AlreadyConnected(net, around.into()).into()); return Err(AlreadyConnected(net, around.into()).into());
} }
@ -509,7 +509,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
// //
let mut outwards = around.ref_(self).outwards(); let mut outwards = around.ref_(self).outwards();
while let Some(gear) = outwards.walk_next(self) { while let Some(gear) = outwards.walk_next(self) {
if let Some(next_gear_net) = gear.primitive(self).maybe_net() { if let Some(next_gear_net) = gear.primitive_ref(self).maybe_net() {
if net == next_gear_net { if net == next_gear_net {
return Err(AlreadyConnected(net, gear.into()).into()); return Err(AlreadyConnected(net, gear.into()).into());
} }
@ -780,7 +780,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
filter(drawing, infringer, infringee) filter(drawing, infringer, infringee)
// Don't infringe upon limbs of the current wraparound. // Don't infringe upon limbs of the current wraparound.
&& !PrimitiveIndex::from(around) && !PrimitiveIndex::from(around)
.primitive(drawing) .primitive_ref(drawing)
.limbs() .limbs()
.contains(&infringee) .contains(&infringee)
}, },
@ -811,7 +811,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
use crate::geometry::shape::MeasureLength; use crate::geometry::shape::MeasureLength;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
approx::assert_abs_diff_eq!(bend.primitive(self).shape().length(), 0.0); approx::assert_abs_diff_eq!(bend.primitive_ref(self).shape().length(), 0.0);
Ok(Cane { Ok(Cane {
seg, seg,
@ -897,7 +897,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
self.recording_geometry_with_rtree self.recording_geometry_with_rtree
.move_dot(recorder, dot, to); .move_dot(recorder, dot, to);
for limb in dot.primitive(self).limbs() { for limb in dot.primitive_ref(self).limbs() {
if let Some(infringement) = self.find_infringement_except(limb, filter) { if let Some(infringement) = self.find_infringement_except(limb, filter) {
// Restore previous state. // Restore previous state.
self.recording_geometry_with_rtree self.recording_geometry_with_rtree
@ -1068,7 +1068,9 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
CW: super::graph::IsInLayer, CW: super::graph::IsInLayer,
{ {
match index { match index {
GenericNode::Primitive(primitive) => primitive.primitive(self).layer() == active_layer, GenericNode::Primitive(primitive) => {
primitive.primitive_ref(self).layer() == active_layer
}
GenericNode::Compound(compound) => { GenericNode::Compound(compound) => {
self.compound_weight(compound).is_in_layer(active_layer) self.compound_weight(compound).is_in_layer(active_layer)
} }
@ -1085,7 +1087,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
{ {
match index { match index {
GenericNode::Primitive(primitive) => { GenericNode::Primitive(primitive) => {
primitive.primitive(self).is_in_any_layer_of(layers) primitive.primitive_ref(self).is_in_any_layer_of(layers)
} }
GenericNode::Compound(compound) => { GenericNode::Compound(compound) => {
self.compound_weight(compound).is_in_any_layer_of(layers) self.compound_weight(compound).is_in_any_layer_of(layers)

View File

@ -11,15 +11,15 @@ use crate::{
drawing::{ drawing::{
bend::{BendIndex, FixedBendIndex, LooseBendIndex}, bend::{BendIndex, FixedBendIndex, LooseBendIndex},
dot::FixedDotIndex, dot::FixedDotIndex,
graph::{MakePrimitive, PrimitiveIndex}, graph::{MakePrimitiveRef, PrimitiveIndex},
primitive::{FixedBend, FixedDot, LooseBend, Primitive}, primitive::{FixedBendRef, FixedDotRef, LooseBendRef, PrimitiveRef},
rules::AccessRules, rules::AccessRules,
Drawing, Drawing,
}, },
graph::{GetPetgraphIndex, MakeRef}, graph::{GetPetgraphIndex, MakeRef},
}; };
#[enum_dispatch(GetPetgraphIndex, MakePrimitive)] #[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)]
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum GearIndex { pub enum GearIndex {
FixedDot(FixedDotIndex), FixedDot(FixedDotIndex),
@ -55,9 +55,9 @@ impl From<BendIndex> for GearIndex {
#[enum_dispatch(GetOuterGears, WalkOutwards, GetDrawing, GetPetgraphIndex)] #[enum_dispatch(GetOuterGears, WalkOutwards, GetDrawing, GetPetgraphIndex)]
pub enum GearRef<'a, CW, Cel, R> { pub enum GearRef<'a, CW, Cel, R> {
FixedDot(FixedDot<'a, CW, Cel, R>), FixedDot(FixedDotRef<'a, CW, Cel, R>),
FixedBend(FixedBend<'a, CW, Cel, R>), FixedBend(FixedBendRef<'a, CW, Cel, R>),
LooseBend(LooseBend<'a, CW, Cel, R>), LooseBend(LooseBendRef<'a, CW, Cel, R>),
} }
impl<'a, CW, Cel, R> GearRef<'a, CW, Cel, R> { impl<'a, CW, Cel, R> GearRef<'a, CW, Cel, R> {

View File

@ -13,7 +13,7 @@ use crate::{
use super::{ use super::{
bend::{FixedBendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight}, bend::{FixedBendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
dot::{FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight}, dot::{FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
primitive::Primitive, primitive::PrimitiveRef,
rules::AccessRules, rules::AccessRules,
seg::{ seg::{
FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex, FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex,
@ -46,11 +46,11 @@ pub trait GetMaybeNet {
} }
#[enum_dispatch] #[enum_dispatch]
pub trait MakePrimitive { pub trait MakePrimitiveRef {
fn primitive<'a, CW: Clone, Cel: Copy, R: AccessRules>( fn primitive_ref<'a, CW: Clone, Cel: Copy, R: AccessRules>(
&self, &self,
drawing: &'a Drawing<CW, Cel, R>, drawing: &'a Drawing<CW, Cel, R>,
) -> Primitive<'a, CW, Cel, R>; ) -> PrimitiveRef<'a, CW, Cel, R>;
} }
macro_rules! impl_weight_forward { macro_rules! impl_weight_forward {
@ -75,12 +75,12 @@ macro_rules! impl_weight_forward {
pub type $index_struct = GenericIndex<$weight_struct>; pub type $index_struct = GenericIndex<$weight_struct>;
impl MakePrimitive for $index_struct { impl MakePrimitiveRef for $index_struct {
fn primitive<'a, CW: Clone, Cel: Copy, R: AccessRules>( fn primitive_ref<'a, CW: Clone, Cel: Copy, R: AccessRules>(
&self, &self,
drawing: &'a crate::drawing::Drawing<CW, Cel, R>, drawing: &'a crate::drawing::Drawing<CW, Cel, R>,
) -> Primitive<'a, CW, Cel, R> { ) -> PrimitiveRef<'a, CW, Cel, R> {
Primitive::$weight_variant(GenericPrimitive::new(*self, drawing)) PrimitiveRef::$weight_variant(GenericPrimitive::new(*self, drawing))
} }
} }
}; };
@ -88,7 +88,7 @@ macro_rules! impl_weight_forward {
// TODO: This enum shouldn't exist: we shouldn't be carrying the tag around like this. Instead we // TODO: This enum shouldn't exist: we shouldn't be carrying the tag around like this. Instead we
// should be getting it from the graph when it's needed. // should be getting it from the graph when it's needed.
#[enum_dispatch(GetPetgraphIndex, MakePrimitive)] #[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum PrimitiveIndex { pub enum PrimitiveIndex {
FixedDot(FixedDotIndex), FixedDot(FixedDotIndex),

View File

@ -12,7 +12,7 @@ use crate::{
use super::{ use super::{
bend::BendIndex, bend::BendIndex,
dot::{DotIndex, FixedDotIndex, LooseDotIndex}, dot::{DotIndex, FixedDotIndex, LooseDotIndex},
graph::{MakePrimitive, PrimitiveIndex}, graph::{MakePrimitiveRef, PrimitiveIndex},
head::{BareHead, CaneHead, GetFace, Head}, head::{BareHead, CaneHead, GetFace, Head},
primitive::{GetCore, GetJoints, GetOtherJoint, GetWeight, MakePrimitiveShape}, primitive::{GetCore, GetJoints, GetOtherJoint, GetWeight, MakePrimitiveShape},
rules::{AccessRules, Conditions, GetConditions}, rules::{AccessRules, Conditions, GetConditions},
@ -160,7 +160,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
width: f64, width: f64,
guide_conditions: Option<&Conditions<'_>>, guide_conditions: Option<&Conditions<'_>>,
) -> Circle { ) -> Circle {
let shape = dot.primitive(self).shape(); let shape = dot.primitive_ref(self).shape();
Circle { Circle {
pos: shape.center(), pos: shape.center(),
r: shape.width() / 2.0 r: shape.width() / 2.0
@ -175,7 +175,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
width: f64, width: f64,
guide_conditions: Option<&Conditions<'_>>, guide_conditions: Option<&Conditions<'_>>,
) -> Circle { ) -> Circle {
let outer_circle = match bend.primitive(self).shape() { let outer_circle = match bend.primitive_ref(self).shape() {
PrimitiveShape::Bend(shape) => shape.outer_circle(), PrimitiveShape::Bend(shape) => shape.outer_circle(),
_ => unreachable!(), _ => unreachable!(),
}; };
@ -189,7 +189,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
} }
pub fn conditions(&self, node: PrimitiveIndex) -> Option<Conditions<'_>> { pub fn conditions(&self, node: PrimitiveIndex) -> Option<Conditions<'_>> {
node.primitive(self).conditions() node.primitive_ref(self).conditions()
} }
fn clearance(&self, lhs: Option<&Conditions<'_>>, rhs: Option<&Conditions<'_>>) -> f64 { fn clearance(&self, lhs: Option<&Conditions<'_>>, rhs: Option<&Conditions<'_>>) -> f64 {
@ -202,7 +202,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
fn head_circle(&self, head: &Head, width: f64) -> Circle { fn head_circle(&self, head: &Head, width: f64) -> Circle {
match *head { match *head {
Head::Bare(head) => Circle { Head::Bare(head) => Circle {
pos: head.face().primitive(self).shape().center(), // TODO. pos: head.face().primitive_ref(self).shape().center(), // TODO.
r: 0.0, r: 0.0,
}, },
Head::Cane(head) => { Head::Cane(head) => {

View File

@ -10,8 +10,10 @@ use crate::{
drawing::{ drawing::{
bend::LooseBendIndex, bend::LooseBendIndex,
dot::{DotIndex, LooseDotIndex}, dot::{DotIndex, LooseDotIndex},
graph::{MakePrimitive, PrimitiveIndex}, graph::{MakePrimitiveRef, PrimitiveIndex},
primitive::{GetJoints, LoneLooseSeg, LooseBend, LooseDot, Primitive, SeqLooseSeg}, primitive::{
GetJoints, LoneLooseSegRef, LooseBendRef, LooseDotRef, PrimitiveRef, SeqLooseSegRef,
},
rules::AccessRules, rules::AccessRules,
seg::{LoneLooseSegIndex, SeqLooseSegIndex}, seg::{LoneLooseSegIndex, SeqLooseSegIndex},
}, },
@ -36,7 +38,7 @@ pub trait GetPrevNextLoose {
} }
} }
#[enum_dispatch(GetPetgraphIndex, MakePrimitive)] #[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)]
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum LooseIndex { pub enum LooseIndex {
Dot(LooseDotIndex), Dot(LooseDotIndex),
@ -71,10 +73,10 @@ impl TryFrom<PrimitiveIndex> for LooseIndex {
#[enum_dispatch(GetPrevNextLoose, GetDrawing, GetPetgraphIndex)] #[enum_dispatch(GetPrevNextLoose, GetDrawing, GetPetgraphIndex)]
pub enum Loose<'a, CW, Cel, R> { pub enum Loose<'a, CW, Cel, R> {
Dot(LooseDot<'a, CW, Cel, R>), Dot(LooseDotRef<'a, CW, Cel, R>),
LoneSeg(LoneLooseSeg<'a, CW, Cel, R>), LoneSeg(LoneLooseSegRef<'a, CW, Cel, R>),
SeqSeg(SeqLooseSeg<'a, CW, Cel, R>), SeqSeg(SeqLooseSegRef<'a, CW, Cel, R>),
Bend(LooseBend<'a, CW, Cel, R>), Bend(LooseBendRef<'a, CW, Cel, R>),
} }
impl<'a, CW, Cel, R> Loose<'a, CW, Cel, R> { impl<'a, CW, Cel, R> Loose<'a, CW, Cel, R> {
@ -88,7 +90,7 @@ impl<'a, CW, Cel, R> Loose<'a, CW, Cel, R> {
} }
} }
impl<CW, Cel, R> GetPrevNextLoose for LooseDot<'_, CW, Cel, R> { impl<CW, Cel, R> GetPrevNextLoose for LooseDotRef<'_, CW, Cel, R> {
fn next_loose(&self, maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> { fn next_loose(&self, maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> {
let bend = self.bend(); let bend = self.bend();
@ -104,13 +106,13 @@ impl<CW, Cel, R> GetPrevNextLoose for LooseDot<'_, CW, Cel, R> {
} }
} }
impl<CW, Cel, R> GetPrevNextLoose for LoneLooseSeg<'_, CW, Cel, R> { impl<CW, Cel, R> GetPrevNextLoose for LoneLooseSegRef<'_, CW, Cel, R> {
fn next_loose(&self, _maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> { fn next_loose(&self, _maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> {
None None
} }
} }
impl<CW, Cel, R> GetPrevNextLoose for SeqLooseSeg<'_, CW, Cel, R> { impl<CW, Cel, R> GetPrevNextLoose for SeqLooseSegRef<'_, CW, Cel, R> {
fn next_loose(&self, maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> { fn next_loose(&self, maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> {
let joints = self.joints(); let joints = self.joints();
let Some(prev) = maybe_prev else { let Some(prev) = maybe_prev else {
@ -128,7 +130,7 @@ impl<CW, Cel, R> GetPrevNextLoose for SeqLooseSeg<'_, CW, Cel, R> {
} }
} }
impl<CW, Cel, R> GetPrevNextLoose for LooseBend<'_, CW, Cel, R> { impl<CW, Cel, R> GetPrevNextLoose for LooseBendRef<'_, CW, Cel, R> {
fn next_loose(&self, maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> { fn next_loose(&self, maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> {
let joints = self.joints(); let joints = self.joints();

View File

@ -119,11 +119,11 @@ impl<S: GetDrawing + GetBendIndex> GetCore for S {
} }
macro_rules! impl_primitive { macro_rules! impl_primitive {
($primitive_struct:ident, $weight_struct:ident) => { ($primitive_variant:ident, $primitive_refstruct:ident, $weight_struct:ident) => {
impl<CW, Cel, R> GetWeight for $primitive_struct<'_, CW, Cel, R> { impl<CW, Cel, R> GetWeight for $primitive_refstruct<'_, CW, Cel, R> {
type Weight = $weight_struct; type Weight = $weight_struct;
fn weight(&self) -> $weight_struct { fn weight(&self) -> $weight_struct {
if let PrimitiveWeight::$primitive_struct(weight) = self.tagged_weight() { if let PrimitiveWeight::$primitive_variant(weight) = self.tagged_weight() {
weight weight
} else { } else {
unreachable!() unreachable!()
@ -131,13 +131,13 @@ macro_rules! impl_primitive {
} }
} }
impl<CW, Cel, R> GetLayer for $primitive_struct<'_, CW, Cel, R> { impl<CW, Cel, R> GetLayer for $primitive_refstruct<'_, CW, Cel, R> {
fn layer(&self) -> usize { fn layer(&self) -> usize {
self.weight().layer() self.weight().layer()
} }
} }
impl<CW, Cel, R> GetMaybeNet for $primitive_struct<'_, CW, Cel, R> { impl<CW, Cel, R> GetMaybeNet for $primitive_refstruct<'_, CW, Cel, R> {
fn maybe_net(&self) -> Option<usize> { fn maybe_net(&self) -> Option<usize> {
self.weight().maybe_net() self.weight().maybe_net()
} }
@ -146,14 +146,14 @@ macro_rules! impl_primitive {
} }
macro_rules! impl_fixed_primitive { macro_rules! impl_fixed_primitive {
($primitive_struct:ident, $weight_struct:ident) => { ($primitive_variant:ident, $primitive_struct:ident, $weight_struct:ident) => {
impl_primitive!($primitive_struct, $weight_struct); impl_primitive!($primitive_variant, $primitive_struct, $weight_struct);
}; };
} }
macro_rules! impl_loose_primitive { macro_rules! impl_loose_primitive {
($primitive_struct:ident, $weight_struct:ident) => { ($primitive_variant:ident, $primitive_struct:ident, $weight_struct:ident) => {
impl_primitive!($primitive_struct, $weight_struct); impl_primitive!($primitive_variant, $primitive_struct, $weight_struct);
}; };
} }
@ -165,26 +165,26 @@ macro_rules! impl_loose_primitive {
MakePrimitiveShape, MakePrimitiveShape,
GetLimbs GetLimbs
)] )]
pub enum Primitive<'a, CW, Cel, R> { pub enum PrimitiveRef<'a, CW, Cel, R> {
FixedDot(FixedDot<'a, CW, Cel, R>), FixedDot(FixedDotRef<'a, CW, Cel, R>),
LooseDot(LooseDot<'a, CW, Cel, R>), LooseDot(LooseDotRef<'a, CW, Cel, R>),
FixedSeg(FixedSeg<'a, CW, Cel, R>), FixedSeg(FixedSegRef<'a, CW, Cel, R>),
LoneLooseSeg(LoneLooseSeg<'a, CW, Cel, R>), LoneLooseSeg(LoneLooseSegRef<'a, CW, Cel, R>),
SeqLooseSeg(SeqLooseSeg<'a, CW, Cel, R>), SeqLooseSeg(SeqLooseSegRef<'a, CW, Cel, R>),
FixedBend(FixedBend<'a, CW, Cel, R>), FixedBend(FixedBendRef<'a, CW, Cel, R>),
LooseBend(LooseBend<'a, CW, Cel, R>), LooseBend(LooseBendRef<'a, CW, Cel, R>),
} }
impl<'a, CW, Cel, R: AccessRules> GetConditions<'a> for &Primitive<'a, CW, Cel, R> { impl<'a, CW, Cel, R: AccessRules> GetConditions<'a> for &PrimitiveRef<'a, CW, Cel, R> {
fn conditions(self) -> Option<Conditions<'a>> { fn conditions(self) -> Option<Conditions<'a>> {
match self { match self {
Primitive::FixedDot(x) => x.conditions(), PrimitiveRef::FixedDot(x) => x.conditions(),
Primitive::LooseDot(x) => x.conditions(), PrimitiveRef::LooseDot(x) => x.conditions(),
Primitive::FixedSeg(x) => x.conditions(), PrimitiveRef::FixedSeg(x) => x.conditions(),
Primitive::LoneLooseSeg(x) => x.conditions(), PrimitiveRef::LoneLooseSeg(x) => x.conditions(),
Primitive::SeqLooseSeg(x) => x.conditions(), PrimitiveRef::SeqLooseSeg(x) => x.conditions(),
Primitive::FixedBend(x) => x.conditions(), PrimitiveRef::FixedBend(x) => x.conditions(),
Primitive::LooseBend(x) => x.conditions(), PrimitiveRef::LooseBend(x) => x.conditions(),
} }
} }
} }
@ -258,16 +258,16 @@ where
} }
} }
pub type FixedDot<'a, CW, Cel, R> = GenericPrimitive<'a, FixedDotWeight, CW, Cel, R>; pub type FixedDotRef<'a, CW, Cel, R> = GenericPrimitive<'a, FixedDotWeight, CW, Cel, R>;
impl_fixed_primitive!(FixedDot, FixedDotWeight); impl_fixed_primitive!(FixedDot, FixedDotRef, FixedDotWeight);
impl<CW, Cel, R> MakePrimitiveShape for FixedDot<'_, CW, Cel, R> { impl<CW, Cel, R> MakePrimitiveShape for FixedDotRef<'_, CW, Cel, R> {
fn shape(&self) -> PrimitiveShape { fn shape(&self) -> PrimitiveShape {
self.drawing.geometry().dot_shape(self.index.into()) self.drawing.geometry().dot_shape(self.index.into())
} }
} }
impl<CW, Cel, R> GetLimbs for FixedDot<'_, CW, Cel, R> { impl<CW, Cel, R> GetLimbs for FixedDotRef<'_, CW, Cel, R> {
fn segs(&self) -> Vec<SegIndex> { fn segs(&self) -> Vec<SegIndex> {
self.drawing self.drawing
.geometry() .geometry()
@ -283,24 +283,24 @@ impl<CW, Cel, R> GetLimbs for FixedDot<'_, CW, Cel, R> {
} }
} }
impl<CW, Cel, R> GetLowestGears for FixedDot<'_, CW, Cel, R> {} impl<CW, Cel, R> GetLowestGears for FixedDotRef<'_, CW, Cel, R> {}
impl<CW, Cel, R> GetOuterGears for FixedDot<'_, CW, Cel, R> { impl<CW, Cel, R> GetOuterGears for FixedDotRef<'_, CW, Cel, R> {
fn outer_gears(&self) -> Vec<LooseBendIndex> { fn outer_gears(&self) -> Vec<LooseBendIndex> {
self.lowest_gears() self.lowest_gears()
} }
} }
impl<CW, Cel, R> WalkOutwards for FixedDot<'_, CW, Cel, R> { impl<CW, Cel, R> WalkOutwards for FixedDotRef<'_, CW, Cel, R> {
fn outwards(&self) -> DrawingOutwardWalker { fn outwards(&self) -> DrawingOutwardWalker {
DrawingOutwardWalker::new(self.lowest_gears().into_iter()) DrawingOutwardWalker::new(self.lowest_gears().into_iter())
} }
} }
pub type LooseDot<'a, CW, Cel, R> = GenericPrimitive<'a, LooseDotWeight, CW, Cel, R>; pub type LooseDotRef<'a, CW, Cel, R> = GenericPrimitive<'a, LooseDotWeight, CW, Cel, R>;
impl_loose_primitive!(LooseDot, LooseDotWeight); impl_loose_primitive!(LooseDot, LooseDotRef, LooseDotWeight);
impl<CW, Cel, R> LooseDot<'_, CW, Cel, R> { impl<CW, Cel, R> LooseDotRef<'_, CW, Cel, R> {
pub fn seg(&self) -> Option<SeqLooseSegIndex> { pub fn seg(&self) -> Option<SeqLooseSegIndex> {
self.drawing self.drawing
.geometry() .geometry()
@ -319,13 +319,13 @@ impl<CW, Cel, R> LooseDot<'_, CW, Cel, R> {
} }
} }
impl<CW, Cel, R> MakePrimitiveShape for LooseDot<'_, CW, Cel, R> { impl<CW, Cel, R> MakePrimitiveShape for LooseDotRef<'_, CW, Cel, R> {
fn shape(&self) -> PrimitiveShape { fn shape(&self) -> PrimitiveShape {
self.drawing.geometry().dot_shape(self.index.into()) self.drawing.geometry().dot_shape(self.index.into())
} }
} }
impl<CW, Cel, R> GetLimbs for LooseDot<'_, CW, Cel, R> { impl<CW, Cel, R> GetLimbs for LooseDotRef<'_, CW, Cel, R> {
fn segs(&self) -> Vec<SegIndex> { fn segs(&self) -> Vec<SegIndex> {
if let Some(seg) = self.seg() { if let Some(seg) = self.seg() {
vec![seg.into()] vec![seg.into()]
@ -339,18 +339,18 @@ impl<CW, Cel, R> GetLimbs for LooseDot<'_, CW, Cel, R> {
} }
} }
pub type FixedSeg<'a, CW, Cel, R> = GenericPrimitive<'a, FixedSegWeight, CW, Cel, R>; pub type FixedSegRef<'a, CW, Cel, R> = GenericPrimitive<'a, FixedSegWeight, CW, Cel, R>;
impl_fixed_primitive!(FixedSeg, FixedSegWeight); impl_fixed_primitive!(FixedSeg, FixedSegRef, FixedSegWeight);
impl<CW, Cel, R> MakePrimitiveShape for FixedSeg<'_, CW, Cel, R> { impl<CW, Cel, R> MakePrimitiveShape for FixedSegRef<'_, CW, Cel, R> {
fn shape(&self) -> PrimitiveShape { fn shape(&self) -> PrimitiveShape {
self.drawing.geometry().seg_shape(self.index.into()) self.drawing.geometry().seg_shape(self.index.into())
} }
} }
impl<CW, Cel, R> GetLimbs for FixedSeg<'_, CW, Cel, R> {} impl<CW, Cel, R> GetLimbs for FixedSegRef<'_, CW, Cel, R> {}
impl<CW, Cel, R> GetJoints for FixedSeg<'_, CW, Cel, R> { impl<CW, Cel, R> GetJoints for FixedSegRef<'_, CW, Cel, R> {
type F = FixedDotIndex; type F = FixedDotIndex;
type T = FixedDotIndex; type T = FixedDotIndex;
fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { fn joints(&self) -> (FixedDotIndex, FixedDotIndex) {
@ -362,18 +362,18 @@ impl<CW, Cel, R> GetJoints for FixedSeg<'_, CW, Cel, R> {
} }
} }
pub type LoneLooseSeg<'a, CW, Cel, R> = GenericPrimitive<'a, LoneLooseSegWeight, CW, Cel, R>; pub type LoneLooseSegRef<'a, CW, Cel, R> = GenericPrimitive<'a, LoneLooseSegWeight, CW, Cel, R>;
impl_loose_primitive!(LoneLooseSeg, LoneLooseSegWeight); impl_loose_primitive!(LoneLooseSeg, LoneLooseSegRef, LoneLooseSegWeight);
impl<CW, Cel, R> MakePrimitiveShape for LoneLooseSeg<'_, CW, Cel, R> { impl<CW, Cel, R> MakePrimitiveShape for LoneLooseSegRef<'_, CW, Cel, R> {
fn shape(&self) -> PrimitiveShape { fn shape(&self) -> PrimitiveShape {
self.drawing.geometry().seg_shape(self.index.into()) self.drawing.geometry().seg_shape(self.index.into())
} }
} }
impl<CW, Cel, R> GetLimbs for LoneLooseSeg<'_, CW, Cel, R> {} impl<CW, Cel, R> GetLimbs for LoneLooseSegRef<'_, CW, Cel, R> {}
impl<CW, Cel, R> GetJoints for LoneLooseSeg<'_, CW, Cel, R> { impl<CW, Cel, R> GetJoints for LoneLooseSegRef<'_, CW, Cel, R> {
type F = FixedDotIndex; type F = FixedDotIndex;
type T = FixedDotIndex; type T = FixedDotIndex;
fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { fn joints(&self) -> (FixedDotIndex, FixedDotIndex) {
@ -385,18 +385,18 @@ impl<CW, Cel, R> GetJoints for LoneLooseSeg<'_, CW, Cel, R> {
} }
} }
pub type SeqLooseSeg<'a, CW, Cel, R> = GenericPrimitive<'a, SeqLooseSegWeight, CW, Cel, R>; pub type SeqLooseSegRef<'a, CW, Cel, R> = GenericPrimitive<'a, SeqLooseSegWeight, CW, Cel, R>;
impl_loose_primitive!(SeqLooseSeg, SeqLooseSegWeight); impl_loose_primitive!(SeqLooseSeg, SeqLooseSegRef, SeqLooseSegWeight);
impl<CW, Cel, R> MakePrimitiveShape for SeqLooseSeg<'_, CW, Cel, R> { impl<CW, Cel, R> MakePrimitiveShape for SeqLooseSegRef<'_, CW, Cel, R> {
fn shape(&self) -> PrimitiveShape { fn shape(&self) -> PrimitiveShape {
self.drawing.geometry().seg_shape(self.index.into()) self.drawing.geometry().seg_shape(self.index.into())
} }
} }
impl<CW, Cel, R> GetLimbs for SeqLooseSeg<'_, CW, Cel, R> {} impl<CW, Cel, R> GetLimbs for SeqLooseSegRef<'_, CW, Cel, R> {}
impl<CW, Cel, R> GetJoints for SeqLooseSeg<'_, CW, Cel, R> { impl<CW, Cel, R> GetJoints for SeqLooseSegRef<'_, CW, Cel, R> {
type F = DotIndex; type F = DotIndex;
type T = LooseDotIndex; type T = LooseDotIndex;
fn joints(&self) -> (DotIndex, LooseDotIndex) { fn joints(&self) -> (DotIndex, LooseDotIndex) {
@ -420,24 +420,24 @@ impl<CW, Cel, R> GetJoints for SeqLooseSeg<'_, CW, Cel, R> {
} }
} }
pub type FixedBend<'a, CW, Cel, R> = GenericPrimitive<'a, FixedBendWeight, CW, Cel, R>; pub type FixedBendRef<'a, CW, Cel, R> = GenericPrimitive<'a, FixedBendWeight, CW, Cel, R>;
impl_fixed_primitive!(FixedBend, FixedBendWeight); impl_fixed_primitive!(FixedBend, FixedBendRef, FixedBendWeight);
impl<CW, Cel, R> GetBendIndex for FixedBend<'_, CW, Cel, R> { impl<CW, Cel, R> GetBendIndex for FixedBendRef<'_, CW, Cel, R> {
fn bend_index(&self) -> BendIndex { fn bend_index(&self) -> BendIndex {
self.index.into() self.index.into()
} }
} }
impl<CW, Cel, R> MakePrimitiveShape for FixedBend<'_, CW, Cel, R> { impl<CW, Cel, R> MakePrimitiveShape for FixedBendRef<'_, CW, Cel, R> {
fn shape(&self) -> PrimitiveShape { fn shape(&self) -> PrimitiveShape {
self.drawing.geometry().bend_shape(self.index.into()) self.drawing.geometry().bend_shape(self.index.into())
} }
} }
impl<CW, Cel, R> GetLimbs for FixedBend<'_, CW, Cel, R> {} impl<CW, Cel, R> GetLimbs for FixedBendRef<'_, CW, Cel, R> {}
impl<CW, Cel, R> GetJoints for FixedBend<'_, CW, Cel, R> { impl<CW, Cel, R> GetJoints for FixedBendRef<'_, CW, Cel, R> {
type F = FixedDotIndex; type F = FixedDotIndex;
type T = FixedDotIndex; type T = FixedDotIndex;
fn joints(&self) -> (FixedDotIndex, FixedDotIndex) { fn joints(&self) -> (FixedDotIndex, FixedDotIndex) {
@ -449,50 +449,50 @@ impl<CW, Cel, R> GetJoints for FixedBend<'_, CW, Cel, R> {
} }
} }
impl<CW, Cel, R> GetLowestGears for FixedBend<'_, CW, Cel, R> {} impl<CW, Cel, R> GetLowestGears for FixedBendRef<'_, CW, Cel, R> {}
impl<CW, Cel, R> GetOuterGears for FixedBend<'_, CW, Cel, R> { impl<CW, Cel, R> GetOuterGears for FixedBendRef<'_, CW, Cel, R> {
fn outer_gears(&self) -> Vec<LooseBendIndex> { fn outer_gears(&self) -> Vec<LooseBendIndex> {
self.lowest_gears() self.lowest_gears()
} }
} }
impl<CW, Cel, R> WalkOutwards for FixedBend<'_, CW, Cel, R> { impl<CW, Cel, R> WalkOutwards for FixedBendRef<'_, CW, Cel, R> {
fn outwards(&self) -> DrawingOutwardWalker { fn outwards(&self) -> DrawingOutwardWalker {
DrawingOutwardWalker::new(self.lowest_gears().into_iter()) DrawingOutwardWalker::new(self.lowest_gears().into_iter())
} }
} }
pub type LooseBend<'a, CW, Cel, R> = GenericPrimitive<'a, LooseBendWeight, CW, Cel, R>; pub type LooseBendRef<'a, CW, Cel, R> = GenericPrimitive<'a, LooseBendWeight, CW, Cel, R>;
impl_loose_primitive!(LooseBend, LooseBendWeight); impl_loose_primitive!(LooseBend, LooseBendRef, LooseBendWeight);
impl<CW, Cel, R> GetBendIndex for LooseBend<'_, CW, Cel, R> { impl<CW, Cel, R> GetBendIndex for LooseBendRef<'_, CW, Cel, R> {
fn bend_index(&self) -> BendIndex { fn bend_index(&self) -> BendIndex {
self.index.into() self.index.into()
} }
} }
impl<'a, CW: Clone, Cel: Copy, R: AccessRules> From<LooseBend<'a, CW, Cel, R>> for BendIndex { impl<'a, CW: Clone, Cel: Copy, R: AccessRules> From<LooseBendRef<'a, CW, Cel, R>> for BendIndex {
fn from(bend: LooseBend<'a, CW, Cel, R>) -> BendIndex { fn from(bend: LooseBendRef<'a, CW, Cel, R>) -> BendIndex {
bend.index.into() bend.index.into()
} }
} }
impl<CW, Cel, R> MakePrimitiveShape for LooseBend<'_, CW, Cel, R> { impl<CW, Cel, R> MakePrimitiveShape for LooseBendRef<'_, CW, Cel, R> {
fn shape(&self) -> PrimitiveShape { fn shape(&self) -> PrimitiveShape {
self.drawing.geometry().bend_shape(self.index.into()) self.drawing.geometry().bend_shape(self.index.into())
} }
} }
impl<CW, Cel, R> GetLimbs for LooseBend<'_, CW, Cel, R> {} impl<CW, Cel, R> GetLimbs for LooseBendRef<'_, CW, Cel, R> {}
impl<CW, Cel, R> GetOffset for LooseBend<'_, CW, Cel, R> { impl<CW, Cel, R> GetOffset for LooseBendRef<'_, CW, Cel, R> {
fn offset(&self) -> f64 { fn offset(&self) -> f64 {
self.weight().offset() self.weight().offset()
} }
} }
impl<CW, Cel, R> GetJoints for LooseBend<'_, CW, Cel, R> { impl<CW, Cel, R> GetJoints for LooseBendRef<'_, CW, Cel, R> {
type F = LooseDotIndex; type F = LooseDotIndex;
type T = LooseDotIndex; type T = LooseDotIndex;
fn joints(&self) -> (LooseDotIndex, LooseDotIndex) { fn joints(&self) -> (LooseDotIndex, LooseDotIndex) {
@ -504,19 +504,19 @@ impl<CW, Cel, R> GetJoints for LooseBend<'_, CW, Cel, R> {
} }
} }
impl<CW, Cel, R> GetOuterGears for LooseBend<'_, CW, Cel, R> { impl<CW, Cel, R> GetOuterGears for LooseBendRef<'_, CW, Cel, R> {
fn outer_gears(&self) -> Vec<LooseBendIndex> { fn outer_gears(&self) -> Vec<LooseBendIndex> {
self.outers().collect() self.outers().collect()
} }
} }
impl<CW, Cel, R> WalkOutwards for LooseBend<'_, CW, Cel, R> { impl<CW, Cel, R> WalkOutwards for LooseBendRef<'_, CW, Cel, R> {
fn outwards(&self) -> DrawingOutwardWalker { fn outwards(&self) -> DrawingOutwardWalker {
DrawingOutwardWalker::new(self.outers()) DrawingOutwardWalker::new(self.outers())
} }
} }
impl<CW, Cel, R> LooseBend<'_, CW, Cel, R> { impl<CW, Cel, R> LooseBendRef<'_, CW, Cel, R> {
pub fn inner(&self) -> Option<LooseBendIndex> { pub fn inner(&self) -> Option<LooseBendIndex> {
self.drawing() self.drawing()
.geometry() .geometry()

View File

@ -8,7 +8,7 @@ use specctra_core::rules::GetConditions;
use crate::{ use crate::{
drawing::{ drawing::{
graph::{GetMaybeNet, MakePrimitive}, graph::{GetMaybeNet, MakePrimitiveRef},
primitive::MakePrimitiveShape, primitive::MakePrimitiveShape,
Collision, Infringement, Collision, Infringement,
}, },
@ -141,7 +141,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
}) })
.filter_map(move |primitive_node| { .filter_map(move |primitive_node| {
limiting_shape limiting_shape
.intersects(&primitive_node.primitive(self).shape()) .intersects(&primitive_node.primitive_ref(self).shape())
.then_some(primitive_node) .then_some(primitive_node)
}) })
} }
@ -218,13 +218,13 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
intersector: PrimitiveIndex, intersector: PrimitiveIndex,
it: impl Iterator<Item = PrimitiveIndex> + 'a, it: impl Iterator<Item = PrimitiveIndex> + 'a,
) -> impl Iterator<Item = Infringement> + 'a { ) -> impl Iterator<Item = Infringement> + 'a {
let conditions = intersector.primitive(self).conditions(); let conditions = intersector.primitive_ref(self).conditions();
it.filter_map(move |primitive_node| { it.filter_map(move |primitive_node| {
let infringee_conditions = primitive_node.primitive(self).conditions(); let infringee_conditions = primitive_node.primitive_ref(self).conditions();
let epsilon = 1.0; let epsilon = 1.0;
let inflated_shape = intersector.primitive(self).shape().inflate( let inflated_shape = intersector.primitive_ref(self).shape().inflate(
match (&conditions, infringee_conditions) { match (&conditions, infringee_conditions) {
(None, _) | (_, None) => 0.0, (None, _) | (_, None) => 0.0,
(Some(lhs), Some(rhs)) => { (Some(lhs), Some(rhs)) => {
@ -237,7 +237,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
); );
inflated_shape inflated_shape
.intersects(&primitive_node.primitive(self).shape()) .intersects(&primitive_node.primitive_ref(self).shape())
.then_some(Infringement(inflated_shape, primitive_node)) .then_some(Infringement(inflated_shape, primitive_node))
}) })
} }
@ -246,8 +246,8 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
&self, &self,
node: PrimitiveIndex, node: PrimitiveIndex,
) -> impl Iterator<Item = GenericNode<PrimitiveIndex, GenericIndex<CW>>> + '_ { ) -> impl Iterator<Item = GenericNode<PrimitiveIndex, GenericIndex<CW>>> + '_ {
let limiting_shape = node.primitive(self).shape().inflate( let limiting_shape = node.primitive_ref(self).shape().inflate(
node.primitive(self) node.primitive_ref(self)
.maybe_net() .maybe_net()
.map(|net| self.rules().largest_clearance(Some(net))) .map(|net| self.rules().largest_clearance(Some(net)))
.unwrap_or(0.0), .unwrap_or(0.0),
@ -256,7 +256,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
self.recording_geometry_with_rtree() self.recording_geometry_with_rtree()
.rtree() .rtree()
.locate_in_envelope_intersecting( .locate_in_envelope_intersecting(
&limiting_shape.envelope_3d(0.0, node.primitive(self).layer()), &limiting_shape.envelope_3d(0.0, node.primitive_ref(self).layer()),
) )
.map(|wrapper| wrapper.data) .map(|wrapper| wrapper.data)
} }
@ -266,7 +266,7 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
collider: PrimitiveIndex, collider: PrimitiveIndex,
predicate: &impl Fn(&Self, PrimitiveIndex, PrimitiveIndex) -> bool, predicate: &impl Fn(&Self, PrimitiveIndex, PrimitiveIndex) -> bool,
) -> Option<Collision> { ) -> Option<Collision> {
let shape = collider.primitive(self).shape(); let shape = collider.primitive_ref(self).shape();
self.recording_geometry_with_rtree() self.recording_geometry_with_rtree()
.rtree() .rtree()
@ -290,14 +290,14 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
|| matches!(collidee, PrimitiveIndex::SeqLooseSeg(..)))) || matches!(collidee, PrimitiveIndex::SeqLooseSeg(..))))
}) })
.filter(|collidee| predicate(&self, collider, *collidee)) .filter(|collidee| predicate(&self, collider, *collidee))
.find(|collidee| shape.intersects(&collidee.primitive(self).shape())) .find(|collidee| shape.intersects(&collidee.primitive_ref(self).shape()))
.map(|collidee| Collision(shape, collidee)) .map(|collidee| Collision(shape, collidee))
} }
fn are_connectable(&self, node1: PrimitiveIndex, node2: PrimitiveIndex) -> bool { fn are_connectable(&self, node1: PrimitiveIndex, node2: PrimitiveIndex) -> bool {
if let (Some(node1_net), Some(node2_net)) = ( if let (Some(node1_net), Some(node2_net)) = (
node1.primitive(self).maybe_net(), node1.primitive_ref(self).maybe_net(),
node2.primitive(self).maybe_net(), node2.primitive_ref(self).maybe_net(),
) { ) {
node1_net == node2_net node1_net == node2_net
} else { } else {

View File

@ -6,9 +6,9 @@ use enum_dispatch::enum_dispatch;
use crate::{ use crate::{
drawing::{ drawing::{
graph::{GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight}, graph::{GetMaybeNet, MakePrimitiveRef, PrimitiveIndex, PrimitiveWeight},
loose::LooseIndex, loose::LooseIndex,
primitive::{GenericPrimitive, Primitive}, primitive::{GenericPrimitive, PrimitiveRef},
rules::AccessRules, rules::AccessRules,
Drawing, Drawing,
}, },
@ -18,7 +18,7 @@ use crate::{
use petgraph::stable_graph::NodeIndex; use petgraph::stable_graph::NodeIndex;
#[enum_dispatch(GetPetgraphIndex, MakePrimitive)] #[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
pub enum SegIndex { pub enum SegIndex {
Fixed(FixedSegIndex), Fixed(FixedSegIndex),
@ -26,7 +26,7 @@ pub enum SegIndex {
SeqLoose(SeqLooseSegIndex), SeqLoose(SeqLooseSegIndex),
} }
#[enum_dispatch(GetPetgraphIndex, MakePrimitive)] #[enum_dispatch(GetPetgraphIndex, MakePrimitiveRef)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
pub enum LooseSegIndex { pub enum LooseSegIndex {
Lone(LoneLooseSegIndex), Lone(LoneLooseSegIndex),

View File

@ -18,7 +18,7 @@ use crate::{
bend::{BendWeight, FixedBendWeight, LooseBendWeight}, bend::{BendWeight, FixedBendWeight, LooseBendWeight},
dot::{DotWeight, FixedDotWeight, LooseDotWeight}, dot::{DotWeight, FixedDotWeight, LooseDotWeight},
graph::PrimitiveWeight, graph::PrimitiveWeight,
primitive::Primitive, primitive::PrimitiveRef,
seg::{FixedSegWeight, LoneLooseSegWeight, SegWeight, SeqLooseSegWeight}, seg::{FixedSegWeight, LoneLooseSegWeight, SegWeight, SeqLooseSegWeight},
}, },
geometry::{ geometry::{

View File

@ -12,7 +12,7 @@ use crate::{
drawing::{ drawing::{
band::BandUid, band::BandUid,
dot::DotIndex, dot::DotIndex,
graph::{MakePrimitive, PrimitiveIndex}, graph::{MakePrimitiveRef, PrimitiveIndex},
loose::LooseIndex, loose::LooseIndex,
primitive::MakePrimitiveShape, primitive::MakePrimitiveShape,
rules::AccessRules, rules::AccessRules,
@ -70,7 +70,7 @@ impl<R: AccessRules> Layout<R> {
}) })
.map(|loose| { .map(|loose| {
let prim: PrimitiveIndex = loose.into(); let prim: PrimitiveIndex = loose.into();
let shape = prim.primitive(&self.drawing).shape(); let shape = prim.primitive_ref(&self.drawing).shape();
(loose, shape) (loose, shape)
}) })
.filter_map(move |(loose, shape)| { .filter_map(move |(loose, shape)| {

View File

@ -17,7 +17,7 @@ use crate::{
LooseDotWeight, LooseDotWeight,
}, },
gear::GearIndex, gear::GearIndex,
graph::{GetMaybeNet, IsInLayer, MakePrimitive, PrimitiveIndex, PrimitiveWeight}, graph::{GetMaybeNet, IsInLayer, MakePrimitiveRef, PrimitiveIndex, PrimitiveWeight},
primitive::{GetLimbs, MakePrimitiveShape}, primitive::{GetLimbs, MakePrimitiveShape},
rules::AccessRules, rules::AccessRules,
seg::{ seg::{
@ -98,7 +98,7 @@ impl<R: AccessRules> Layout<R> {
.overlapees(around.into()) .overlapees(around.into())
.find(|overlapee| { .find(|overlapee| {
PrimitiveIndex::from(overlapee.1) PrimitiveIndex::from(overlapee.1)
.primitive(drawing) .primitive_ref(drawing)
.limbs() .limbs()
.contains(&infringee) .contains(&infringee)
}) })
@ -340,7 +340,9 @@ impl<R: AccessRules> Layout<R> {
pub fn node_shape(&self, index: NodeIndex) -> Shape { pub fn node_shape(&self, index: NodeIndex) -> Shape {
match index { match index {
NodeIndex::Primitive(primitive) => primitive.primitive(&self.drawing).shape().into(), NodeIndex::Primitive(primitive) => {
primitive.primitive_ref(&self.drawing).shape().into()
}
NodeIndex::Compound(compound) => self.compound_shape(compound), NodeIndex::Compound(compound) => self.compound_shape(compound),
} }
} }

View File

@ -14,7 +14,7 @@ use crate::{
bend::{BendIndex, GeneralBendWeight, LooseBendWeight}, bend::{BendIndex, GeneralBendWeight, LooseBendWeight},
dot::{DotIndex, FixedDotIndex, GeneralDotWeight, LooseDotIndex, LooseDotWeight}, dot::{DotIndex, FixedDotIndex, GeneralDotWeight, LooseDotIndex, LooseDotWeight},
gear::GearIndex, gear::GearIndex,
graph::{GetMaybeNet, MakePrimitive}, graph::{GetMaybeNet, MakePrimitiveRef},
head::{CaneHead, GetFace, Head}, head::{CaneHead, GetFace, Head},
primitive::GetOtherJoint, primitive::GetOtherJoint,
rules::AccessRules, rules::AccessRules,
@ -89,7 +89,7 @@ impl<R: AccessRules> Draw for Layout<R> {
.map_err(Into::<DrawException>::into)?; .map_err(Into::<DrawException>::into)?;
let (layer, maybe_net) = { let (layer, maybe_net) = {
let face = head.face().primitive(self.drawing()); let face = head.face().primitive_ref(self.drawing());
(face.layer(), face.maybe_net()) (face.layer(), face.maybe_net())
}; };
@ -287,8 +287,8 @@ impl<R: AccessRules> DrawPrivate for Layout<R> {
width: f64, width: f64,
offset: f64, offset: f64,
) -> Result<CaneHead, DrawingException> { ) -> Result<CaneHead, DrawingException> {
let layer = head.face().primitive(self.drawing()).layer(); let layer = head.face().primitive_ref(self.drawing()).layer();
let maybe_net = head.face().primitive(self.drawing()).maybe_net(); let maybe_net = head.face().primitive_ref(self.drawing()).maybe_net();
let dot_weight = LooseDotWeight(GeneralDotWeight { let dot_weight = LooseDotWeight(GeneralDotWeight {
circle: Circle { circle: Circle {

View File

@ -9,7 +9,7 @@ use crate::{
drawing::{ drawing::{
band::BandTermsegIndex, band::BandTermsegIndex,
dot::FixedDotIndex, dot::FixedDotIndex,
graph::MakePrimitive, graph::MakePrimitiveRef,
head::{BareHead, CaneHead, Head}, head::{BareHead, CaneHead, Head},
primitive::MakePrimitiveShape, primitive::MakePrimitiveShape,
rules::AccessRules, rules::AccessRules,
@ -121,7 +121,10 @@ impl Navcord {
let final_termseg = layout.finish(navmesh, self, to_dot)?; let final_termseg = layout.finish(navmesh, self, to_dot)?;
self.maybe_final_termseg = Some(final_termseg); self.maybe_final_termseg = Some(final_termseg);
let final_termseg_length = final_termseg.primitive(layout.drawing()).shape().length(); let final_termseg_length = final_termseg
.primitive_ref(layout.drawing())
.shape()
.length();
let bend_length = match self.head { let bend_length = match self.head {
Head::Cane(old_cane_head) => layout Head::Cane(old_cane_head) => layout

View File

@ -24,10 +24,8 @@ use crate::{
bend::{FixedBendIndex, LooseBendIndex}, bend::{FixedBendIndex, LooseBendIndex},
dot::FixedDotIndex, dot::FixedDotIndex,
gear::{GearIndex, GetOuterGears, WalkOutwards}, gear::{GearIndex, GetOuterGears, WalkOutwards},
graph::{MakePrimitive, PrimitiveIndex}, graph::PrimitiveIndex,
primitive::Primitive,
rules::AccessRules, rules::AccessRules,
Drawing,
}, },
graph::{GenericIndex, GetPetgraphIndex, MakeRef}, graph::{GenericIndex, GetPetgraphIndex, MakeRef},
layout::{CompoundEntryLabel, Layout}, layout::{CompoundEntryLabel, Layout},

View File

@ -10,7 +10,7 @@ use crate::{
drawing::{ drawing::{
band::BandUid, band::BandUid,
dot::FixedDotIndex, dot::FixedDotIndex,
graph::MakePrimitive as _, graph::MakePrimitiveRef as _,
head::{BareHead, GetFace as _, Head}, head::{BareHead, GetFace as _, Head},
primitive::MakePrimitiveShape as _, primitive::MakePrimitiveShape as _,
rules::AccessRules, rules::AccessRules,
@ -130,7 +130,7 @@ impl AstarContext {
let mut length = ctx.length; let mut length = ctx.length;
if let Some(old_poly) = sub.polygon.take() { if let Some(old_poly) = sub.polygon.take() {
if prim != old_poly.apex { if prim != old_poly.apex {
let destination = prim.primitive(layout.drawing()).shape().center(); let destination = prim.primitive_ref(layout.drawing()).shape().center();
let exit = old_poly.entry_point(destination, true)?; let exit = old_poly.entry_point(destination, true)?;
let (new_head, length_delta) = old_poly.route_to_exit( let (new_head, length_delta) = old_poly.route_to_exit(
&mut layout, &mut layout,
@ -153,10 +153,10 @@ impl AstarContext {
length += sub length += sub
.active_head .active_head
.maybe_cane() .maybe_cane()
.map(|cane| cane.bend.primitive(layout.drawing()).shape().length()) .map(|cane| cane.bend.primitive_ref(layout.drawing()).shape().length())
.unwrap_or(0.0); .unwrap_or(0.0);
length += { length += {
match fin.primitive(layout.drawing()).shape() { match fin.primitive_ref(layout.drawing()).shape() {
PrimitiveShape::Dot(_) => unreachable!(), PrimitiveShape::Dot(_) => unreachable!(),
PrimitiveShape::Seg(seg) => seg.length(), PrimitiveShape::Seg(seg) => seg.length(),
PrimitiveShape::Bend(bend) => bend.length(), PrimitiveShape::Bend(bend) => bend.length(),
@ -224,8 +224,8 @@ impl AstarContext {
(Some(lhs), Some(rhs)) => Some(FloatingRouting::new( (Some(lhs), Some(rhs)) => Some(FloatingRouting::new(
&layout, &layout,
sub.active_head.face(), sub.active_head.face(),
lhs.primitive(&layout.drawing()).shape().center(), lhs.primitive_ref(&layout.drawing()).shape().center(),
rhs.primitive(&layout.drawing()).shape().center(), rhs.primitive_ref(&layout.drawing()).shape().center(),
)), )),
_ => None, _ => None,
}; };

View File

@ -7,8 +7,8 @@ use geo::Point;
use crate::{ use crate::{
drawing::{ drawing::{
dot::DotIndex, dot::DotIndex,
graph::MakePrimitive as _, graph::MakePrimitiveRef as _,
primitive::{GetWeight as _, Primitive}, primitive::{GetWeight as _, PrimitiveRef},
rules::AccessRules, rules::AccessRules,
}, },
geometry::GetSetPos as _, geometry::GetSetPos as _,
@ -35,9 +35,9 @@ impl FloatingRouting {
lhs: Point, lhs: Point,
rhs: Point, rhs: Point,
) -> Self { ) -> Self {
let active_head_pos = match active_head_face.primitive(layout.drawing()) { let active_head_pos = match active_head_face.primitive_ref(layout.drawing()) {
Primitive::FixedDot(dot) => dot.weight().0, PrimitiveRef::FixedDot(dot) => dot.weight().0,
Primitive::LooseDot(dot) => dot.weight().0, PrimitiveRef::LooseDot(dot) => dot.weight().0,
_ => unreachable!(), _ => unreachable!(),
} }
.pos(); .pos();

View File

@ -21,7 +21,7 @@ use crate::{
band::BandUid, band::BandUid,
bend::BendIndex, bend::BendIndex,
dot::{DotIndex, FixedDotIndex}, dot::{DotIndex, FixedDotIndex},
graph::{MakePrimitive as _, PrimitiveIndex}, graph::{MakePrimitiveRef as _, PrimitiveIndex},
head::{CaneHead, GetFace as _, Head}, head::{CaneHead, GetFace as _, Head},
primitive::MakePrimitiveShape as _, primitive::MakePrimitiveShape as _,
rules::AccessRules, rules::AccessRules,
@ -548,7 +548,7 @@ impl SubContext {
fn head_center<R: AccessRules>(&self, layout: &Layout<R>) -> Point { fn head_center<R: AccessRules>(&self, layout: &Layout<R>) -> Point {
self.active_head self.active_head
.face() .face()
.primitive(layout.drawing()) .primitive_ref(layout.drawing())
.shape() .shape()
.center() .center()
} }
@ -610,10 +610,15 @@ fn cane_around<R: AccessRules>(
} }
}?; }?;
// record the length of the current seg, and the old bend, if any // record the length of the current seg, and the old bend, if any
*route_length += ret.cane.seg.primitive(layout.drawing()).shape().length() *route_length += ret
.cane
.seg
.primitive_ref(layout.drawing())
.shape()
.length()
+ old_head + old_head
.maybe_cane() .maybe_cane()
.map(|cane| cane.bend.primitive(layout.drawing()).shape().length()) .map(|cane| cane.bend.primitive_ref(layout.drawing()).shape().length())
.unwrap_or(0.0); .unwrap_or(0.0);
Ok(ret) Ok(ret)
} }

View File

@ -10,7 +10,7 @@ use crate::{
drawing::{ drawing::{
band::BandUid, band::BandUid,
dot::FixedDotIndex, dot::FixedDotIndex,
graph::{MakePrimitive as _, PrimitiveIndex}, graph::{MakePrimitiveRef as _, PrimitiveIndex},
head::{CaneHead, Head}, head::{CaneHead, Head},
primitive::MakePrimitiveShape as _, primitive::MakePrimitiveShape as _,
}, },
@ -90,7 +90,7 @@ impl PolygonRouting {
} }
pub fn center<R: AccessRules>(&self, layout: &Layout<R>) -> Point { pub fn center<R: AccessRules>(&self, layout: &Layout<R>) -> Point {
self.apex.primitive(layout.drawing()).shape().center() self.apex.primitive_ref(layout.drawing()).shape().center()
} }
/// calculate the entry or exit point for the polygon (set `invert_cw` to `true` for exit point) /// calculate the entry or exit point for the polygon (set `invert_cw` to `true` for exit point)

View File

@ -12,11 +12,10 @@ use crate::{
drawing::{ drawing::{
bend::FixedBendIndex, bend::FixedBendIndex,
dot::{DotIndex, FixedDotIndex}, dot::{DotIndex, FixedDotIndex},
graph::{GetMaybeNet, MakePrimitive, PrimitiveIndex}, graph::{GetMaybeNet, MakePrimitiveRef, PrimitiveIndex},
primitive::{GetCore, GetJoints, MakePrimitiveShape, Primitive}, primitive::{GetCore, GetJoints, MakePrimitiveShape},
rules::AccessRules, rules::AccessRules,
seg::{FixedSegIndex, LoneLooseSegIndex, SeqLooseSegIndex}, seg::{FixedSegIndex, LoneLooseSegIndex, SeqLooseSegIndex},
Drawing,
}, },
geometry::{shape::AccessShape, GetLayer}, geometry::{shape::AccessShape, GetLayer},
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetPetgraphIndex},
@ -68,14 +67,14 @@ impl PrenavmeshWeight {
pub fn new_from_fixed_dot(layout: &Layout<impl AccessRules>, dot: FixedDotIndex) -> Self { pub fn new_from_fixed_dot(layout: &Layout<impl AccessRules>, dot: FixedDotIndex) -> Self {
Self { Self {
node: dot.into(), node: dot.into(),
pos: dot.primitive(layout.drawing()).shape().center(), pos: dot.primitive_ref(layout.drawing()).shape().center(),
} }
} }
pub fn new_from_fixed_bend(layout: &Layout<impl AccessRules>, bend: FixedBendIndex) -> Self { pub fn new_from_fixed_bend(layout: &Layout<impl AccessRules>, bend: FixedBendIndex) -> Self {
Self { Self {
node: bend.into(), node: bend.into(),
pos: bend.primitive(layout.drawing()).shape().center(), pos: bend.primitive_ref(layout.drawing()).shape().center(),
} }
} }
} }
@ -151,7 +150,7 @@ impl Prenavmesh {
let maybe_net = layout.drawing().primitive(origin).maybe_net(); let maybe_net = layout.drawing().primitive(origin).maybe_net();
for node in layout.drawing().layer_primitive_nodes(layer) { for node in layout.drawing().layer_primitive_nodes(layer) {
let primitive = node.primitive(layout.drawing()); let primitive = node.primitive_ref(layout.drawing());
let Some(primitive_net) = primitive.maybe_net() else { let Some(primitive_net) = primitive.maybe_net() else {
continue; continue;
@ -203,7 +202,7 @@ impl Prenavmesh {
} }
for node in layout.drawing().layer_primitive_nodes(layer) { for node in layout.drawing().layer_primitive_nodes(layer) {
let primitive = node.primitive(layout.drawing()); let primitive = node.primitive_ref(layout.drawing());
let Some(primitive_net) = primitive.maybe_net() else { let Some(primitive_net) = primitive.maybe_net() else {
continue; continue;

View File

@ -13,7 +13,7 @@ use crate::{
drawing::{ drawing::{
band::BandTermsegIndex, band::BandTermsegIndex,
dot::FixedDotIndex, dot::FixedDotIndex,
graph::{MakePrimitive, PrimitiveIndex}, graph::{MakePrimitiveRef, PrimitiveIndex},
primitive::MakePrimitiveShape, primitive::MakePrimitiveShape,
rules::AccessRules, rules::AccessRules,
}, },
@ -182,7 +182,7 @@ impl<R: AccessRules> ThetastarStrategy<Navmesh, f64, BandTermsegIndex>
fn estimate_cost_to_goal(&mut self, navmesh: &Navmesh, vertex: NavnodeIndex) -> f64 { fn estimate_cost_to_goal(&mut self, navmesh: &Navmesh, vertex: NavnodeIndex) -> f64 {
let start_point = PrimitiveIndex::from(navmesh.node_weight(vertex).unwrap().binavnode) let start_point = PrimitiveIndex::from(navmesh.node_weight(vertex).unwrap().binavnode)
.primitive(self.layout.drawing()) .primitive_ref(self.layout.drawing())
.shape() .shape()
.center(); .center();
let end_point = self let end_point = self

View File

@ -16,7 +16,7 @@ use crate::{
board::{edit::BoardEdit, AccessMesadata, Board}, board::{edit::BoardEdit, AccessMesadata, Board},
drawing::{ drawing::{
dot::{FixedDotIndex, FixedDotWeight, GeneralDotWeight}, dot::{FixedDotIndex, FixedDotWeight, GeneralDotWeight},
graph::{GetMaybeNet, MakePrimitive}, graph::{GetMaybeNet, MakePrimitiveRef},
primitive::MakePrimitiveShape, primitive::MakePrimitiveShape,
seg::{FixedSegWeight, GeneralSegWeight}, seg::{FixedSegWeight, GeneralSegWeight},
Drawing, Drawing,
@ -78,7 +78,7 @@ impl SpecctraDesign {
let mut net_outs = BTreeMap::<usize, structure::NetOut>::new(); let mut net_outs = BTreeMap::<usize, structure::NetOut>::new();
for index in drawing.primitive_nodes() { for index in drawing.primitive_nodes() {
let primitive = index.primitive(drawing); let primitive = index.primitive_ref(drawing);
if let Some(net) = primitive.maybe_net() { if let Some(net) = primitive.maybe_net() {
let coords = match primitive.shape() { let coords = match primitive.shape() {