geometry: rename geometry submodule to layout, small typing changes

This commit is contained in:
Mikolaj Wielgus 2024-01-27 16:20:04 +00:00
parent 9f42991032
commit 3fe54290c6
19 changed files with 93 additions and 92 deletions

View File

@ -1,11 +1,11 @@
use crate::{
connectivity::{BandIndex, BandWeight, ConnectivityWeight, GetNet},
geometry::{
graph::GetNodeIndex,
layout::Layout,
layout::{
dot::{DotIndex, FixedDotIndex},
geometry::{GeometryIndex, MakePrimitive},
},
graph::GetNodeIndex,
layout::Layout,
loose::{GetNextLoose, LooseIndex},
primitive::{GetEnds, GetOtherEnd, MakeShape},
shape::ShapeTrait,

View File

@ -1,7 +1,7 @@
use enum_dispatch::enum_dispatch;
use petgraph::stable_graph::StableDiGraph;
use crate::{geometry::dot::FixedDotIndex, graph::GenericIndex};
use crate::{graph::GenericIndex, layout::dot::FixedDotIndex};
#[enum_dispatch]
pub trait GetNet {

View File

@ -3,13 +3,13 @@ use geo::{EuclideanLength, Point};
use thiserror::Error;
use crate::{
geometry::{
guide::{Guide, Head, HeadTrait, SegbendHead},
layout::{
bend::{BendIndex, LooseBendWeight},
dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight},
geometry::{GetBandIndex, MakePrimitive},
seg::{LoneLooseSegWeight, SeqLooseSegWeight},
},
guide::{Guide, Head, HeadTrait, SegbendHead},
layout::{Infringement, Layout, LayoutException},
math::{Circle, NoTangents},
primitive::GetOtherEnd,

View File

@ -1,5 +0,0 @@
#[macro_use]
pub mod geometry;
pub mod bend;
pub mod dot;
pub mod seg;

View File

@ -8,7 +8,7 @@ use petgraph::stable_graph::NodeIndex;
// Due to apparent limitations of enum_dispatch we're forced to import some types backwards.
use crate::geometry::{bend::BendIndex, dot::DotIndex, geometry::GeometryIndex, seg::SegIndex};
use crate::layout::{bend::BendIndex, dot::DotIndex, geometry::GeometryIndex, seg::SegIndex};
#[enum_dispatch]
pub trait GetNodeIndex {

View File

@ -3,12 +3,12 @@ use geo::Line;
use crate::{
connectivity::BandIndex,
geometry::{
layout::Layout,
layout::{
bend::BendIndex,
dot::{DotIndex, FixedDotIndex, LooseDotIndex},
geometry::{GetBandIndex, MakePrimitive},
},
layout::Layout,
math::{self, Circle, NoTangents},
primitive::{GetCore, GetInnerOuter, GetOtherEnd, GetWeight, MakeShape},
rules::{Conditions, Rules},

View File

@ -1,3 +1,9 @@
#[macro_use]
pub mod geometry;
pub mod bend;
pub mod dot;
pub mod seg;
use contracts::{debug_ensures, debug_invariant};
use enum_dispatch::enum_dispatch;
use geo::Point;
@ -13,22 +19,20 @@ use crate::connectivity::{
BandIndex, BandWeight, ComponentIndex, ComponentWeight, ConnectivityGraph, ConnectivityLabel,
ConnectivityWeight, GetNet,
};
use crate::geometry::geometry::Geometry;
use crate::geometry::seg::SeqLooseSegWeight;
use crate::geometry::{
bend::{BendWeight, FixedBendIndex, LooseBendIndex, LooseBendWeight},
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
use crate::graph::{GenericIndex, GetNodeIndex};
use crate::guide::Guide;
use crate::layout::bend::BendIndex;
use crate::layout::geometry::{BendWeight, DotWeight, Geometry, SegWeight};
use crate::layout::seg::{SegIndex, SeqLooseSegWeight};
use crate::layout::{
bend::{FixedBendIndex, LooseBendIndex, LooseBendWeight},
dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
geometry::{
GeometryGraph, GeometryIndex, GeometryLabel, GeometryWeight, GetComponentIndex,
MakePrimitive, Retag,
},
seg::{
FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SegWeight,
SeqLooseSegIndex,
},
seg::{FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex},
};
use crate::graph::{GenericIndex, GetNodeIndex};
use crate::guide::Guide;
use crate::loose::{GetNextLoose, Loose, LooseIndex};
use crate::math::NoTangents;
use crate::primitive::{
@ -71,7 +75,7 @@ pub struct AlreadyConnected(pub i64, pub GeometryIndex);
pub struct Layout {
rtree: RTree<RTreeWrapper>,
connectivity: ConnectivityGraph,
geometry: Geometry,
geometry: Geometry<DotIndex, SegIndex, BendIndex>,
}
#[debug_invariant(self.geometry.graph().node_count() == self.rtree.size())]
@ -246,7 +250,7 @@ impl Layout {
to: FixedDotIndex,
weight: FixedSegWeight,
) -> Result<FixedSegIndex, Infringement> {
self.add_seg_infringably(from, to, weight, &[])
self.add_seg_infringably(from.into(), to.into(), weight, &[])
}
#[debug_ensures(ret.is_ok() -> self.geometry.graph().node_count() == old(self.geometry.graph().node_count() + 4))]
@ -518,7 +522,7 @@ impl Layout {
) -> Result<Segbend, LayoutException> {
let seg_to = self.add_dot_infringably(dot_weight, infringables)?;
let seg = self
.add_seg_infringably(from, seg_to, seg_weight, infringables)
.add_seg_infringably(from, seg_to.into(), seg_weight, infringables)
.map_err(|err| {
self.remove(seg_to.into());
err
@ -557,7 +561,7 @@ impl Layout {
to: FixedDotIndex,
weight: LoneLooseSegWeight,
) -> Result<LoneLooseSegIndex, Infringement> {
let seg = self.add_seg_infringably(from, to, weight, &[])?;
let seg = self.add_seg_infringably(from.into(), to.into(), weight, &[])?;
self.connectivity.update_edge(
self.primitive(from).component().node_index(),
@ -583,7 +587,7 @@ impl Layout {
to: LooseDotIndex,
weight: SeqLooseSegWeight,
) -> Result<SeqLooseSegIndex, Infringement> {
let seg = self.add_seg_infringably(from, to, weight, &[])?;
let seg = self.add_seg_infringably(from, to.into(), weight, &[])?;
if let DotIndex::Fixed(dot) = from {
self.connectivity.update_edge(
@ -602,8 +606,8 @@ impl Layout {
#[debug_ensures(ret.is_err() -> self.geometry.graph().edge_count() == old(self.geometry.graph().edge_count()))]
fn add_seg_infringably<W: SegWeight>(
&mut self,
from: impl GetNodeIndex,
to: impl GetNodeIndex,
from: DotIndex,
to: DotIndex,
weight: W,
infringables: &[GeometryIndex],
) -> Result<GenericIndex<W>, Infringement>
@ -662,7 +666,7 @@ impl Layout {
match around {
WraparoundableIndex::FixedDot(core) => self
.add_core_bend_infringably(from, to, core, weight, infringables)
.add_core_bend_infringably(from.into(), to.into(), core, weight, infringables)
.map_err(Into::into),
WraparoundableIndex::FixedBend(around) => self
.add_outer_bend_infringably(from, to, around, weight, infringables)
@ -679,8 +683,8 @@ impl Layout {
#[debug_ensures(ret.is_err() -> self.geometry.graph().edge_count() == old(self.geometry.graph().edge_count()))]
fn add_core_bend_infringably<W: BendWeight>(
&mut self,
from: impl GetNodeIndex,
to: impl GetNodeIndex,
from: DotIndex,
to: DotIndex,
core: FixedDotIndex,
weight: W,
infringables: &[GeometryIndex],
@ -688,7 +692,7 @@ impl Layout {
where
GenericIndex<W>: Into<GeometryIndex> + Copy,
{
let bend = self.geometry.add_bend(from, to, core, weight);
let bend = self.geometry.add_bend(from, to, core.into(), weight);
self.insert_into_rtree(bend.into());
self.fail_and_remove_if_infringes_except(bend.into(), infringables)?;
@ -701,8 +705,8 @@ impl Layout {
#[debug_ensures(ret.is_err() -> self.geometry.graph().edge_count() == old(self.geometry.graph().edge_count()))]
fn add_outer_bend_infringably<W: BendWeight>(
&mut self,
from: impl GetNodeIndex,
to: impl GetNodeIndex,
from: LooseDotIndex,
to: LooseDotIndex,
inner: impl GetNodeIndex,
weight: W,
infringables: &[GeometryIndex],
@ -733,7 +737,9 @@ impl Layout {
.first()
.unwrap();
let bend = self.geometry.add_bend(from, to, core, weight);
let bend = self
.geometry
.add_bend(from.into(), to.into(), core.into(), weight);
self.geometry.graph.update_edge(
inner.node_index(),
@ -947,7 +953,7 @@ impl Layout {
#[debug_ensures(self.geometry.graph().node_count() == old(self.geometry.graph().node_count()))]
#[debug_ensures(self.geometry.graph().edge_count() == old(self.geometry.graph().edge_count()))]
pub fn geometry(&self) -> &Geometry {
pub fn geometry(&self) -> &Geometry<DotIndex, SegIndex, BendIndex> {
&self.geometry
}

View File

@ -3,13 +3,13 @@ use enum_dispatch::enum_dispatch;
use crate::{
connectivity::{BandIndex, ComponentIndex},
graph::GenericIndex,
layout::Layout,
layout::{GetNodeIndex, Layout},
primitive::{GenericPrimitive, Primitive},
};
use super::geometry::{
GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex, GetComponentIndexMut,
GetOffset, GetWidth, MakePrimitive, Retag,
BendWeight, GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex,
GetComponentIndexMut, GetOffset, GetWidth, MakePrimitive, Retag,
};
use petgraph::stable_graph::NodeIndex;
@ -29,8 +29,6 @@ impl From<BendIndex> for GeometryIndex {
}
}
pub trait BendWeight: Into<GeometryWeight> + Copy {}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedBendWeight {
pub component: ComponentIndex,

View File

@ -3,14 +3,14 @@ use enum_dispatch::enum_dispatch;
use crate::{
connectivity::{BandIndex, ComponentIndex},
graph::GenericIndex,
layout::Layout,
layout::{GetNodeIndex, Layout},
math::Circle,
primitive::{GenericPrimitive, Primitive},
};
use super::geometry::{
GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex, GetComponentIndexMut, GetWidth,
MakePrimitive, Retag,
DotWeight, GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex,
GetComponentIndexMut, GetWidth, MakePrimitive, Retag,
};
use petgraph::stable_graph::NodeIndex;
@ -30,8 +30,6 @@ impl From<DotIndex> for GeometryIndex {
}
}
pub trait DotWeight: GetWidth + Into<GeometryWeight> + Copy {}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedDotWeight {
pub component: ComponentIndex,

View File

@ -1,3 +1,5 @@
use std::marker::PhantomData;
use contracts::debug_invariant;
use enum_dispatch::enum_dispatch;
use geo::Point;
@ -11,11 +13,11 @@ use crate::{
};
use super::{
bend::{BendWeight, FixedBendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
dot::{DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
bend::{FixedBendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
dot::{FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
seg::{
FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SegWeight,
SeqLooseSegIndex, SeqLooseSegWeight,
FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex,
SeqLooseSegWeight,
},
};
@ -132,15 +134,25 @@ pub trait MakePrimitive {
fn primitive<'a>(&self, layout: &'a Layout) -> Primitive<'a>;
}
pub trait DotWeight: GetWidth + Into<GeometryWeight> + Copy {}
pub trait SegWeight: Into<GeometryWeight> + Copy {}
pub trait BendWeight: Into<GeometryWeight> + Copy {}
#[derive(Debug)]
pub struct Geometry {
pub struct Geometry<DI: GetNodeIndex, SI: GetNodeIndex, BI: GetNodeIndex> {
pub graph: GeometryGraph,
dot_index_marker: PhantomData<DI>,
seg_index_marker: PhantomData<SI>,
bend_index_marker: PhantomData<BI>,
}
impl Geometry {
impl<DI: GetNodeIndex, SI: GetNodeIndex, BI: GetNodeIndex> Geometry<DI, SI, BI> {
pub fn new() -> Self {
Self {
graph: StableDiGraph::default(),
dot_index_marker: PhantomData,
seg_index_marker: PhantomData,
bend_index_marker: PhantomData,
}
}
@ -148,12 +160,7 @@ impl Geometry {
GenericIndex::<W>::new(self.graph.add_node(weight.into()))
}
pub fn add_seg<W: SegWeight>(
&mut self,
from: impl GetNodeIndex,
to: impl GetNodeIndex,
weight: W,
) -> GenericIndex<W> {
pub fn add_seg<W: SegWeight>(&mut self, from: DI, to: DI, weight: W) -> GenericIndex<W> {
let seg = GenericIndex::<W>::new(self.graph.add_node(weight.into()));
self.graph
@ -166,9 +173,9 @@ impl Geometry {
pub fn add_bend<W: BendWeight>(
&mut self,
from: impl GetNodeIndex,
to: impl GetNodeIndex,
core: impl GetNodeIndex,
from: DI,
to: DI,
core: DI,
weight: W,
) -> GenericIndex<W> {
let bend = GenericIndex::<W>::new(self.graph.add_node(weight.into()));

View File

@ -3,13 +3,13 @@ use enum_dispatch::enum_dispatch;
use crate::{
connectivity::{BandIndex, ComponentIndex},
graph::GenericIndex,
layout::Layout,
layout::{GetNodeIndex, Layout},
primitive::{GenericPrimitive, Primitive},
};
use super::geometry::{
GeometryIndex, GeometryWeight, GetBandIndex, GetComponentIndex, GetComponentIndexMut, GetWidth,
MakePrimitive, Retag,
MakePrimitive, Retag, SegWeight,
};
use petgraph::stable_graph::NodeIndex;
@ -31,8 +31,6 @@ impl From<SegIndex> for GeometryIndex {
}
}
pub trait SegWeight: Into<GeometryWeight> + Copy {}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedSegWeight {
pub component: ComponentIndex,

View File

@ -2,14 +2,14 @@ use enum_dispatch::enum_dispatch;
use petgraph::stable_graph::NodeIndex;
use crate::{
geometry::{
graph::GetNodeIndex,
layout::Layout,
layout::{
bend::LooseBendIndex,
dot::{DotIndex, LooseDotIndex},
geometry::{GeometryIndex, MakePrimitive},
seg::{LoneLooseSegIndex, SeqLooseSegIndex},
},
graph::GetNodeIndex,
layout::Layout,
primitive::{GetEnds, LoneLooseSeg, LooseBend, LooseDot, Primitive, SeqLooseSeg},
};

View File

@ -12,7 +12,6 @@ mod astar;
mod band;
mod connectivity;
mod draw;
mod geometry;
mod graph;
mod guide;
mod layout;
@ -31,9 +30,9 @@ mod wraparoundable;
use connectivity::BandIndex;
use draw::DrawException;
use geo::point;
use geometry::dot::FixedDotWeight;
use geometry::geometry::{GeometryIndex, MakePrimitive};
use geometry::seg::FixedSegWeight;
use layout::dot::FixedDotWeight;
use layout::geometry::{GeometryIndex, MakePrimitive};
use layout::seg::FixedSegWeight;
use layout::{Infringement, Layout, LayoutException};
use mesh::{Mesh, MeshEdgeReference, VertexIndex};
use petgraph::visit::{EdgeRef, IntoEdgeReferences};

View File

@ -10,13 +10,13 @@ use spade::{HasPosition, InsertionError, Point2};
use crate::primitive::{GetCore, Primitive};
use crate::triangulation::TriangulationEdgeReference;
use crate::{
geometry::{
graph::GetNodeIndex,
layout::Layout,
layout::{
bend::{FixedBendIndex, LooseBendIndex},
dot::FixedDotIndex,
geometry::{GeometryIndex, MakePrimitive},
},
graph::GetNodeIndex,
layout::Layout,
primitive::MakeShape,
shape::ShapeTrait,
triangulation::{GetVertexIndex, Triangulation},

View File

@ -5,11 +5,13 @@ use petgraph::stable_graph::NodeIndex;
use petgraph::Direction::{Incoming, Outgoing};
use crate::connectivity::{BandIndex, ComponentIndex, GetNet};
use crate::geometry::seg::{
use crate::graph::{GenericIndex, GetNodeIndex};
use crate::layout::seg::{
FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SegIndex,
SeqLooseSegIndex, SeqLooseSegWeight,
};
use crate::geometry::{
use crate::layout::Layout;
use crate::layout::{
bend::{BendIndex, FixedBendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
geometry::{
@ -17,8 +19,6 @@ use crate::geometry::{
GetWidth, MakePrimitive, Retag,
},
};
use crate::graph::{GenericIndex, GetNodeIndex};
use crate::layout::Layout;
use crate::loose::{Loose, LooseIndex};
use crate::math::{self, Circle};
use crate::shape::{BendShape, DotShape, SegShape, Shape, ShapeTrait};

View File

@ -7,12 +7,12 @@ use thiserror::Error;
use crate::astar::{astar, AstarStrategy, PathTracker};
use crate::connectivity::BandIndex;
use crate::draw::DrawException;
use crate::geometry::{
use crate::guide::HeadTrait;
use crate::layout::Layout;
use crate::layout::{
dot::FixedDotIndex,
geometry::{GeometryIndex, MakePrimitive},
};
use crate::guide::HeadTrait;
use crate::layout::Layout;
use crate::mesh::{Mesh, MeshEdgeReference, VertexIndex};

View File

@ -1,8 +1,8 @@
use crate::{
geometry::{
layout::Layout,
layout::{
bend::LooseBendIndex, dot::LooseDotIndex, geometry::GeometryIndex, seg::SeqLooseSegIndex,
},
layout::Layout,
primitive::{GetEnds, GetInterior, GetOtherEnd, LooseBend, LooseDot},
};

View File

@ -2,9 +2,9 @@ use contracts::debug_ensures;
use crate::{
draw::{Draw, DrawException},
geometry::{bend::LooseBendIndex, dot::FixedDotIndex},
guide::{BareHead, Head, SegbendHead},
layout::Layout,
layout::{bend::LooseBendIndex, dot::FixedDotIndex},
mesh::{Mesh, VertexIndex},
rules::Rules,
};

View File

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