layout: move `GeometryIndex` and `GeometryWeight` to own file

This commit is contained in:
Mikolaj Wielgus 2024-01-30 01:51:19 +00:00
parent 43df065120
commit 8b1d95491d
17 changed files with 181 additions and 167 deletions

View File

@ -7,12 +7,12 @@ use crate::{
layout::{ layout::{
bend::{BendIndex, LooseBendWeight}, bend::{BendIndex, LooseBendWeight},
dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight}, dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight},
geometry::{GetBandIndex, MakePrimitive}, graph::{GetBandIndex, MakePrimitive},
primitive::GetOtherJoint,
seg::{LoneLooseSegWeight, SeqLooseSegWeight}, seg::{LoneLooseSegWeight, SeqLooseSegWeight},
}, },
layout::{Infringement, Layout, LayoutException}, layout::{Infringement, Layout, LayoutException},
math::{Circle, NoTangents}, math::{Circle, NoTangents},
primitive::GetOtherJoint,
rules::{Conditions, Rules}, rules::{Conditions, Rules},
wraparoundable::WraparoundableIndex, wraparoundable::WraparoundableIndex,
}; };

View File

@ -7,10 +7,10 @@ use crate::{
bend::BendIndex, bend::BendIndex,
connectivity::BandIndex, connectivity::BandIndex,
dot::{DotIndex, FixedDotIndex, LooseDotIndex}, dot::{DotIndex, FixedDotIndex, LooseDotIndex},
geometry::{GetBandIndex, MakePrimitive}, graph::{GetBandIndex, MakePrimitive},
primitive::{GetCore, GetInnerOuter, GetOtherJoint, GetWeight, MakeShape},
}, },
math::{self, Circle, NoTangents}, math::{self, Circle, NoTangents},
primitive::{GetCore, GetInnerOuter, GetOtherJoint, GetWeight, MakeShape},
rules::{Conditions, Rules}, rules::{Conditions, Rules},
segbend::Segbend, segbend::Segbend,
shape::{Shape, ShapeTrait}, shape::{Shape, ShapeTrait},

View File

@ -4,12 +4,12 @@ use super::{
}; };
use crate::{ use crate::{
graph::GetNodeIndex, graph::GetNodeIndex,
layout::Layout,
layout::{ layout::{
dot::{DotIndex, FixedDotIndex}, dot::{DotIndex, FixedDotIndex},
geometry::{GeometryIndex, MakePrimitive}, graph::{GeometryIndex, MakePrimitive},
},
primitive::{GetJoints, GetOtherJoint, MakeShape}, primitive::{GetJoints, GetOtherJoint, MakeShape},
Layout,
},
shape::ShapeTrait, shape::ShapeTrait,
}; };

View File

@ -4,14 +4,14 @@ use crate::{
graph::{GenericIndex, GetNodeIndex}, graph::{GenericIndex, GetNodeIndex},
layout::{ layout::{
connectivity::{BandIndex, ComponentIndex}, connectivity::{BandIndex, ComponentIndex},
Layout, geometry::{BendWeightTrait, GetOffset, GetWidth},
graph::{
GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex, GetComponentIndexMut,
MakePrimitive, Retag,
}, },
primitive::{GenericPrimitive, Primitive}, primitive::{GenericPrimitive, Primitive},
}; Layout,
},
use super::geometry::{
BendWeightTrait, GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex,
GetComponentIndexMut, GetOffset, GetWidth, MakePrimitive, Retag,
}; };
use petgraph::stable_graph::NodeIndex; use petgraph::stable_graph::NodeIndex;

View File

@ -5,16 +5,17 @@ use crate::{
graph::{GenericIndex, GetNodeIndex}, graph::{GenericIndex, GetNodeIndex},
layout::{ layout::{
connectivity::{BandIndex, ComponentIndex}, connectivity::{BandIndex, ComponentIndex},
geometry::{DotWeightTrait, GetPos, GetWidth},
graph::{
GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex, GetComponentIndexMut,
MakePrimitive, Retag,
},
primitive::{GenericPrimitive, Primitive},
Layout, Layout,
}, },
math::Circle, math::Circle,
primitive::{GenericPrimitive, Primitive},
}; };
use super::geometry::{
DotWeightTrait, GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex,
GetComponentIndexMut, GetPos, GetWidth, MakePrimitive, Retag,
};
use petgraph::stable_graph::NodeIndex; use petgraph::stable_graph::NodeIndex;
#[enum_dispatch(GetNodeIndex, MakePrimitive)] #[enum_dispatch(GetNodeIndex, MakePrimitive)]

View File

@ -11,41 +11,14 @@ use petgraph::{
use crate::{ use crate::{
graph::{GenericIndex, GetNodeIndex}, graph::{GenericIndex, GetNodeIndex},
layout::{ layout::{
connectivity::{BandIndex, ComponentIndex}, bend::{BendWeight, FixedBendWeight, LooseBendWeight},
Layout, dot::{DotWeight, FixedDotWeight, LooseDotWeight},
graph::{GeometryWeight, Retag},
}, },
math::Circle, math::Circle,
primitive::Primitive,
shape::{BendShape, DotShape, SegShape, Shape}, shape::{BendShape, DotShape, SegShape, Shape},
}; };
use super::super::{
bend::{FixedBendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
dot::{FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
seg::{
FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex,
SeqLooseSegWeight,
},
};
#[enum_dispatch]
pub trait Retag<GeometryIndex> {
fn retag(&self, index: NodeIndex<usize>) -> GeometryIndex;
}
#[enum_dispatch]
pub trait GetComponentIndex {
fn component(&self) -> ComponentIndex;
}
pub trait GetComponentIndexMut {
fn component_mut(&mut self) -> &mut ComponentIndex;
}
pub trait GetBandIndex {
fn band(&self) -> BandIndex;
}
#[enum_dispatch] #[enum_dispatch]
pub trait GetPos { pub trait GetPos {
fn pos(&self) -> Point; fn pos(&self) -> Point;
@ -61,78 +34,6 @@ pub trait GetOffset {
fn offset(&self) -> f64; fn offset(&self) -> f64;
} }
macro_rules! impl_weight {
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
impl Retag<GeometryIndex> for $weight_struct {
fn retag(&self, index: NodeIndex<usize>) -> GeometryIndex {
GeometryIndex::$weight_variant($index_struct::new(index))
}
}
pub type $index_struct = GenericIndex<$weight_struct>;
impl MakePrimitive for $index_struct {
fn primitive<'a>(&self, layout: &'a Layout) -> Primitive<'a> {
Primitive::$weight_variant(GenericPrimitive::new(*self, layout))
}
}
};
}
macro_rules! impl_fixed_weight {
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
impl_weight!($weight_struct, $weight_variant, $index_struct);
impl GetComponentIndex for $weight_struct {
fn component(&self) -> ComponentIndex {
self.component
}
}
impl GetComponentIndexMut for $weight_struct {
fn component_mut(&mut self) -> &mut ComponentIndex {
&mut self.component
}
}
};
}
macro_rules! impl_loose_weight {
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
impl_weight!($weight_struct, $weight_variant, $index_struct);
impl GetBandIndex for $weight_struct {
fn band(&self) -> BandIndex {
self.band
}
}
};
}
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum GeometryIndex {
FixedDot(FixedDotIndex),
LooseDot(LooseDotIndex),
FixedSeg(FixedSegIndex),
LoneLooseSeg(LoneLooseSegIndex),
SeqLooseSeg(SeqLooseSegIndex),
FixedBend(FixedBendIndex),
LooseBend(LooseBendIndex),
}
#[enum_dispatch(GetWidth, Retag<GeometryIndex>)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum GeometryWeight {
FixedDot(FixedDotWeight),
LooseDot(LooseDotWeight),
FixedSeg(FixedSegWeight),
LoneLooseSeg(LoneLooseSegWeight),
SeqLooseSeg(SeqLooseSegWeight),
FixedBend(FixedBendWeight),
LooseBend(LooseBendWeight),
}
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum GeometryLabel { pub enum GeometryLabel {
Connection, Connection,
@ -140,11 +41,6 @@ pub enum GeometryLabel {
Core, Core,
} }
#[enum_dispatch]
pub trait MakePrimitive {
fn primitive<'a>(&self, layout: &'a Layout) -> Primitive<'a>;
}
pub trait DotWeightTrait<GW>: GetPos + GetWidth + Into<GW> + Copy {} pub trait DotWeightTrait<GW>: GetPos + GetWidth + Into<GW> + Copy {}
pub trait SegWeightTrait<GW>: GetWidth + Into<GW> + Copy {} pub trait SegWeightTrait<GW>: GetWidth + Into<GW> + Copy {}
pub trait BendWeightTrait<GW>: GetOffset + GetWidth + Into<GW> + Copy {} pub trait BendWeightTrait<GW>: GetOffset + GetWidth + Into<GW> + Copy {}

116
src/layout/graph.rs Normal file
View File

@ -0,0 +1,116 @@
use enum_dispatch::enum_dispatch;
use petgraph::stable_graph::NodeIndex;
use crate::{
graph::GetNodeIndex,
layout::{
connectivity::{BandIndex, ComponentIndex},
Layout,
},
};
use super::{
bend::{FixedBendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
dot::{FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
primitive::Primitive,
seg::{
FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex,
SeqLooseSegWeight,
},
};
#[enum_dispatch]
pub trait Retag<GeometryIndex> {
fn retag(&self, index: NodeIndex<usize>) -> GeometryIndex;
}
#[enum_dispatch]
pub trait GetComponentIndex {
fn component(&self) -> ComponentIndex;
}
pub trait GetComponentIndexMut {
fn component_mut(&mut self) -> &mut ComponentIndex;
}
pub trait GetBandIndex {
fn band(&self) -> BandIndex;
}
#[enum_dispatch]
pub trait MakePrimitive {
fn primitive<'a>(&self, layout: &'a Layout) -> Primitive<'a>;
}
macro_rules! impl_weight {
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
impl Retag<GeometryIndex> for $weight_struct {
fn retag(&self, index: NodeIndex<usize>) -> GeometryIndex {
GeometryIndex::$weight_variant($index_struct::new(index))
}
}
pub type $index_struct = GenericIndex<$weight_struct>;
impl MakePrimitive for $index_struct {
fn primitive<'a>(&self, layout: &'a Layout) -> Primitive<'a> {
Primitive::$weight_variant(GenericPrimitive::new(*self, layout))
}
}
};
}
macro_rules! impl_fixed_weight {
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
impl_weight!($weight_struct, $weight_variant, $index_struct);
impl GetComponentIndex for $weight_struct {
fn component(&self) -> ComponentIndex {
self.component
}
}
impl GetComponentIndexMut for $weight_struct {
fn component_mut(&mut self) -> &mut ComponentIndex {
&mut self.component
}
}
};
}
macro_rules! impl_loose_weight {
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
impl_weight!($weight_struct, $weight_variant, $index_struct);
impl GetBandIndex for $weight_struct {
fn band(&self) -> BandIndex {
self.band
}
}
};
}
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum GeometryIndex {
FixedDot(FixedDotIndex),
LooseDot(LooseDotIndex),
FixedSeg(FixedSegIndex),
LoneLooseSeg(LoneLooseSegIndex),
SeqLooseSeg(SeqLooseSegIndex),
FixedBend(FixedBendIndex),
LooseBend(LooseBendIndex),
}
#[enum_dispatch(GetWidth, Retag<GeometryIndex>)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum GeometryWeight {
FixedDot(FixedDotWeight),
LooseDot(LooseDotWeight),
FixedSeg(FixedSegWeight),
LoneLooseSeg(LoneLooseSegWeight),
SeqLooseSeg(SeqLooseSegWeight),
FixedBend(FixedBendWeight),
LooseBend(LooseBendWeight),
}

View File

@ -17,21 +17,23 @@ use crate::graph::{GenericIndex, GetNodeIndex};
use crate::guide::Guide; use crate::guide::Guide;
use crate::layout::bend::BendIndex; use crate::layout::bend::BendIndex;
use crate::layout::dot::DotWeight; use crate::layout::dot::DotWeight;
use crate::layout::geometry::{BendWeightTrait, DotWeightTrait, Geometry, SegWeightTrait}; use crate::layout::geometry::{
use crate::layout::seg::{SegIndex, SeqLooseSegWeight}; BendWeightTrait, DotWeightTrait, Geometry, GeometryLabel, SegWeightTrait,
};
use crate::layout::{ use crate::layout::{
bend::{FixedBendIndex, LooseBendIndex, LooseBendWeight}, bend::{FixedBendIndex, LooseBendIndex, LooseBendWeight},
dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight}, dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
geometry::{ graph::{GeometryIndex, GeometryWeight, GetComponentIndex, MakePrimitive, Retag},
GeometryIndex, GeometryLabel, GeometryWeight, GetComponentIndex, MakePrimitive, Retag, primitive::{
GenericPrimitive, GetConnectable, GetCore, GetInnerOuter, GetJoints, GetLimbs,
GetOtherJoint, GetWeight, MakeShape,
},
seg::{
FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SegIndex,
SeqLooseSegIndex, SeqLooseSegWeight,
}, },
seg::{FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex},
}; };
use crate::math::NoTangents; use crate::math::NoTangents;
use crate::primitive::{
GenericPrimitive, GetConnectable, GetCore, GetInnerOuter, GetJoints, GetLimbs, GetOtherJoint,
GetWeight, MakeShape,
};
use crate::segbend::Segbend; use crate::segbend::Segbend;
use crate::shape::{Shape, ShapeTrait}; use crate::shape::{Shape, ShapeTrait};
use crate::wraparoundable::{GetWraparound, Wraparoundable, WraparoundableIndex}; use crate::wraparoundable::{GetWraparound, Wraparoundable, WraparoundableIndex};

View File

@ -7,10 +7,10 @@ use crate::{
layout::{ layout::{
bend::LooseBendIndex, bend::LooseBendIndex,
dot::{DotIndex, LooseDotIndex}, dot::{DotIndex, LooseDotIndex},
geometry::{GeometryIndex, MakePrimitive}, graph::{GeometryIndex, MakePrimitive},
primitive::{GetJoints, LoneLooseSeg, LooseBend, LooseDot, Primitive, SeqLooseSeg},
seg::{LoneLooseSegIndex, SeqLooseSegIndex}, seg::{LoneLooseSegIndex, SeqLooseSegIndex},
}, },
primitive::{GetJoints, LoneLooseSeg, LooseBend, LooseDot, Primitive, SeqLooseSeg},
}; };
#[enum_dispatch] #[enum_dispatch]

View File

@ -1,10 +1,12 @@
#[macro_use] #[macro_use]
pub mod geometry; pub mod graph;
pub mod band; pub mod band;
pub mod bend; pub mod bend;
pub mod connectivity; pub mod connectivity;
pub mod dot; pub mod dot;
pub mod geometry;
pub mod loose; pub mod loose;
pub mod primitive;
pub mod seg; pub mod seg;
mod layout; mod layout;

View File

@ -9,14 +9,10 @@ use crate::layout::seg::{
}; };
use crate::layout::{ use crate::layout::{
bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight}, bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
geometry::{
GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex, GetOffset, GetWidth,
MakePrimitive, Retag,
},
};
use crate::layout::{
connectivity::{BandIndex, ComponentIndex, GetNet}, connectivity::{BandIndex, ComponentIndex, GetNet},
dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
geometry::{GetOffset, GetWidth},
graph::{GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex, MakePrimitive, Retag},
loose::{Loose, LooseIndex}, loose::{Loose, LooseIndex},
Layout, Layout,
}; };

View File

@ -4,15 +4,16 @@ use crate::{
graph::{GenericIndex, GetNodeIndex}, graph::{GenericIndex, GetNodeIndex},
layout::{ layout::{
connectivity::{BandIndex, ComponentIndex}, connectivity::{BandIndex, ComponentIndex},
Layout, geometry::{GetWidth, SegWeightTrait},
graph::{
GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex, GetComponentIndexMut,
MakePrimitive, Retag,
}, },
primitive::{GenericPrimitive, Primitive}, primitive::{GenericPrimitive, Primitive},
Layout,
},
}; };
use super::geometry::{
GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex, GetComponentIndexMut, GetWidth,
MakePrimitive, Retag, SegWeightTrait,
};
use petgraph::stable_graph::NodeIndex; use petgraph::stable_graph::NodeIndex;
#[enum_dispatch(GetNodeIndex, MakePrimitive)] #[enum_dispatch(GetNodeIndex, MakePrimitive)]

View File

@ -12,10 +12,10 @@ mod astar;
mod draw; mod draw;
mod graph; mod graph;
mod guide; mod guide;
#[macro_use]
mod layout; mod layout;
mod math; mod math;
mod mesh; mod mesh;
mod primitive;
mod router; mod router;
mod rules; mod rules;
mod segbend; mod segbend;
@ -28,12 +28,12 @@ use draw::DrawException;
use geo::point; use geo::point;
use layout::connectivity::BandIndex; use layout::connectivity::BandIndex;
use layout::dot::FixedDotWeight; use layout::dot::FixedDotWeight;
use layout::geometry::{GeometryIndex, MakePrimitive}; use layout::graph::{GeometryIndex, MakePrimitive};
use layout::primitive::MakeShape;
use layout::seg::FixedSegWeight; use layout::seg::FixedSegWeight;
use layout::{Infringement, Layout, LayoutException}; use layout::{Infringement, Layout, LayoutException};
use mesh::{Mesh, MeshEdgeReference, VertexIndex}; use mesh::{Mesh, MeshEdgeReference, VertexIndex};
use petgraph::visit::{EdgeRef, IntoEdgeReferences}; use petgraph::visit::{EdgeRef, IntoEdgeReferences};
use primitive::MakeShape;
use router::RouterObserver; use router::RouterObserver;
use sdl2::event::Event; use sdl2::event::Event;

View File

@ -7,7 +7,6 @@ use petgraph::visit::{self, NodeIndexable};
use petgraph::{stable_graph::NodeIndex, visit::EdgeRef}; use petgraph::{stable_graph::NodeIndex, visit::EdgeRef};
use spade::{HasPosition, InsertionError, Point2}; use spade::{HasPosition, InsertionError, Point2};
use crate::primitive::{GetCore, Primitive};
use crate::triangulation::TriangulationEdgeReference; use crate::triangulation::TriangulationEdgeReference;
use crate::{ use crate::{
graph::GetNodeIndex, graph::GetNodeIndex,
@ -15,9 +14,9 @@ use crate::{
layout::{ layout::{
bend::{FixedBendIndex, LooseBendIndex}, bend::{FixedBendIndex, LooseBendIndex},
dot::FixedDotIndex, dot::FixedDotIndex,
geometry::{GeometryIndex, MakePrimitive}, graph::{GeometryIndex, MakePrimitive},
primitive::{GetCore, MakeShape, Primitive},
}, },
primitive::MakeShape,
shape::ShapeTrait, shape::ShapeTrait,
triangulation::{GetVertexIndex, Triangulation}, triangulation::{GetVertexIndex, Triangulation},
}; };

View File

@ -11,12 +11,12 @@ use crate::layout::Layout;
use crate::layout::{ use crate::layout::{
connectivity::BandIndex, connectivity::BandIndex,
dot::FixedDotIndex, dot::FixedDotIndex,
geometry::{GeometryIndex, MakePrimitive}, graph::{GeometryIndex, MakePrimitive},
primitive::MakeShape,
}; };
use crate::mesh::{Mesh, MeshEdgeReference, VertexIndex}; use crate::mesh::{Mesh, MeshEdgeReference, VertexIndex};
use crate::primitive::MakeShape;
use crate::rules::Rules; use crate::rules::Rules;
use crate::shape::ShapeTrait; use crate::shape::ShapeTrait;
use crate::tracer::{Trace, Tracer}; use crate::tracer::{Trace, Tracer};

View File

@ -1,9 +1,10 @@
use crate::{ use crate::layout::{
layout::Layout, bend::LooseBendIndex,
layout::{ dot::LooseDotIndex,
bend::LooseBendIndex, dot::LooseDotIndex, geometry::GeometryIndex, seg::SeqLooseSegIndex, graph::GeometryIndex,
},
primitive::{GetInterior, GetJoints, GetOtherJoint, LooseBend, LooseDot}, primitive::{GetInterior, GetJoints, GetOtherJoint, LooseBend, LooseDot},
seg::SeqLooseSegIndex,
Layout,
}; };
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]

View File

@ -3,15 +3,15 @@ use petgraph::stable_graph::NodeIndex;
use crate::{ use crate::{
graph::GetNodeIndex, graph::GetNodeIndex,
layout::Layout,
layout::{ layout::{
bend::{BendIndex, FixedBendIndex, LooseBendIndex}, bend::{BendIndex, FixedBendIndex, LooseBendIndex},
dot::FixedDotIndex, dot::FixedDotIndex,
geometry::{GeometryIndex, MakePrimitive}, graph::{GeometryIndex, MakePrimitive},
},
primitive::{ primitive::{
FixedBend, FixedDot, GetFirstRail, GetInnerOuter, GetLayout, LooseBend, Primitive, FixedBend, FixedDot, GetFirstRail, GetInnerOuter, GetLayout, LooseBend, Primitive,
}, },
Layout,
},
}; };
#[enum_dispatch] #[enum_dispatch]