mirror of https://codeberg.org/topola/topola.git
router: impl. more traits for triangulation to allow more algorithms
This commit is contained in:
parent
8a6b0724e9
commit
94c88a51f8
|
|
@ -31,7 +31,7 @@ pub enum VertexIndex {
|
||||||
|
|
||||||
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
||||||
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum TriangulationVertexIndex {
|
enum TriangulationVertexIndex {
|
||||||
FixedDot(FixedDotIndex),
|
FixedDot(FixedDotIndex),
|
||||||
FixedBend(FixedBendIndex),
|
FixedBend(FixedBendIndex),
|
||||||
}
|
}
|
||||||
|
|
@ -82,13 +82,13 @@ pub struct Mesh {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mesh {
|
impl Mesh {
|
||||||
pub fn new(layout: &Drawing<impl Copy, impl RulesTrait>) -> Self {
|
pub fn new(drawing: &Drawing<impl Copy, impl RulesTrait>) -> Self {
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
triangulation: Triangulation::new(layout),
|
triangulation: Triangulation::new(drawing),
|
||||||
vertex_to_triangulation_vertex: Vec::new(),
|
vertex_to_triangulation_vertex: Vec::new(),
|
||||||
};
|
};
|
||||||
this.vertex_to_triangulation_vertex
|
this.vertex_to_triangulation_vertex
|
||||||
.resize(layout.geometry().graph().node_bound(), None);
|
.resize(drawing.geometry().graph().node_bound(), None);
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@ use std::marker::PhantomData;
|
||||||
|
|
||||||
use geo::{point, Point};
|
use geo::{point, Point};
|
||||||
use petgraph::visit::{self, NodeIndexable};
|
use petgraph::visit::{self, NodeIndexable};
|
||||||
use spade::{handles::FixedVertexHandle, DelaunayTriangulation, HasPosition, InsertionError};
|
use spade::{
|
||||||
|
handles::FixedVertexHandle, iterators::VertexIterator, DelaunayTriangulation, HasPosition,
|
||||||
|
InsertionError,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{rules::RulesTrait, Drawing},
|
drawing::{rules::RulesTrait, Drawing},
|
||||||
|
|
@ -146,11 +149,8 @@ impl<'a, I: Copy + PartialEq + GetNodeIndex, W: GetVertexIndex<I> + HasPosition<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<'a, I: Copy + PartialEq + GetNodeIndex, W: GetVertexIndex<I> + HasPosition<Scalar = f64>>
|
||||||
'a,
|
visit::IntoEdges for &'a Triangulation<I, W>
|
||||||
I: Copy + PartialEq + GetNodeIndex + std::fmt::Debug,
|
|
||||||
W: GetVertexIndex<I> + HasPosition<Scalar = f64>,
|
|
||||||
> visit::IntoEdges for &'a Triangulation<I, W>
|
|
||||||
{
|
{
|
||||||
type Edges = Box<dyn Iterator<Item = TriangulationEdgeReference<I>> + 'a>;
|
type Edges = Box<dyn Iterator<Item = TriangulationEdgeReference<I>> + 'a>;
|
||||||
|
|
||||||
|
|
@ -165,3 +165,73 @@ impl<
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, I: Copy + PartialEq + GetNodeIndex, W: GetVertexIndex<I> + HasPosition<Scalar = f64>>
|
||||||
|
visit::IntoNodeIdentifiers for &'a Triangulation<I, W>
|
||||||
|
{
|
||||||
|
type NodeIdentifiers = Box<dyn Iterator<Item = I> + 'a>;
|
||||||
|
|
||||||
|
fn node_identifiers(self) -> Self::NodeIdentifiers {
|
||||||
|
Box::new(
|
||||||
|
spade::Triangulation::fixed_vertices(&self.triangulation).map(|vertex| {
|
||||||
|
spade::Triangulation::s(&self.triangulation)
|
||||||
|
.vertex_data(vertex)
|
||||||
|
.vertex()
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
pub struct TriangulationVertexReference<I> {
|
||||||
|
index: I,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I: Copy> visit::NodeRef for TriangulationVertexReference<I> {
|
||||||
|
type NodeId = I;
|
||||||
|
type Weight = ();
|
||||||
|
|
||||||
|
fn id(&self) -> Self::NodeId {
|
||||||
|
self.index
|
||||||
|
}
|
||||||
|
|
||||||
|
fn weight(&self) -> &Self::Weight {
|
||||||
|
&()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, I: Copy + PartialEq + GetNodeIndex, W: GetVertexIndex<I> + HasPosition<Scalar = f64>>
|
||||||
|
visit::IntoNodeReferences for &'a Triangulation<I, W>
|
||||||
|
{
|
||||||
|
type NodeRef = TriangulationVertexReference<I>;
|
||||||
|
type NodeReferences = Box<dyn Iterator<Item = TriangulationVertexReference<I>> + 'a>;
|
||||||
|
fn node_references(self) -> Self::NodeReferences {
|
||||||
|
Box::new(
|
||||||
|
spade::Triangulation::fixed_vertices(&self.triangulation).map(|vertex| {
|
||||||
|
TriangulationVertexReference {
|
||||||
|
index: spade::Triangulation::s(&self.triangulation)
|
||||||
|
.vertex_data(vertex)
|
||||||
|
.vertex(),
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, I: Copy + PartialEq + GetNodeIndex, W: GetVertexIndex<I> + HasPosition<Scalar = f64>>
|
||||||
|
visit::NodeIndexable for &'a Triangulation<I, W>
|
||||||
|
{
|
||||||
|
fn node_bound(&self) -> usize {
|
||||||
|
spade::Triangulation::num_vertices(&self.triangulation)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_index(&self, node: I) -> usize {
|
||||||
|
node.node_index().index()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_index(&self, index: usize) -> I {
|
||||||
|
spade::Triangulation::s(&self.triangulation)
|
||||||
|
.vertex_data(self.vertex_to_handle[index].unwrap())
|
||||||
|
.vertex()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue