drawing: obtain `HeadRef` via new trait for abstract reference objects

This commit is contained in:
Mikolaj Wielgus 2024-07-21 14:49:43 +02:00
parent 0552dd3f33
commit 57c970e22e
4 changed files with 9 additions and 8 deletions

View File

@ -5,3 +5,5 @@ pub enum BandFirstSegIndex {
Straight(LoneLooseSegIndex), Straight(LoneLooseSegIndex),
Bended(SeqLooseSegIndex), Bended(SeqLooseSegIndex),
} }
pub struct BandRef {}

View File

@ -1,6 +1,6 @@
use enum_dispatch::enum_dispatch; use enum_dispatch::enum_dispatch;
use crate::geometry::shape::MeasureLength; use crate::{geometry::shape::MeasureLength, graph::MakeRef};
use super::{ use super::{
cane::Cane, cane::Cane,
@ -22,11 +22,8 @@ pub enum Head {
Cane(CaneHead), Cane(CaneHead),
} }
impl Head { impl<'a, CW: Copy, R: AccessRules> MakeRef<'a, HeadRef<'a, CW, R>, Drawing<CW, R>> for Head {
pub fn ref_<'a, CW: Copy, R: AccessRules>( fn ref_(&self, drawing: &'a Drawing<CW, R>) -> HeadRef<'a, CW, R> {
&self,
drawing: &'a Drawing<CW, R>,
) -> HeadRef<'a, CW, R> {
HeadRef::new(*self, drawing) HeadRef::new(*self, drawing)
} }
} }

View File

@ -6,7 +6,9 @@ use std::{
use enum_dispatch::enum_dispatch; use enum_dispatch::enum_dispatch;
use petgraph::stable_graph::NodeIndex; use petgraph::stable_graph::NodeIndex;
// Due to apparent limitations of enum_dispatch we're forced to import some types backwards. pub trait MakeRef<'a, R: 'a, C> {
fn ref_(&self, context: &'a C) -> R;
}
#[enum_dispatch] #[enum_dispatch]
pub trait GetPetgraphIndex { pub trait GetPetgraphIndex {

View File

@ -16,7 +16,7 @@ use crate::{
primitive::{AccessPrimitiveShape, PrimitiveShape}, primitive::{AccessPrimitiveShape, PrimitiveShape},
shape::{AccessShape, MeasureLength}, shape::{AccessShape, MeasureLength},
}, },
graph::GetPetgraphIndex, graph::{GetPetgraphIndex, MakeRef},
layout::Layout, layout::Layout,
}; };