triangulation: move out and make independent of layout and drawing

This commit is contained in:
Mikolaj Wielgus 2024-04-20 14:44:44 +02:00
parent 51c6eeea1f
commit 47b8616a40
4 changed files with 8 additions and 15 deletions

View File

@ -9,3 +9,4 @@ pub mod layout;
pub mod math;
pub mod overlay;
pub mod router;
pub mod triangulation;

View File

@ -3,6 +3,5 @@ pub mod draw;
pub mod navmesh;
mod router;
pub mod tracer;
pub mod triangulation;
pub use router::*;

View File

@ -19,7 +19,7 @@ use crate::{
geometry::primitive::PrimitiveShapeTrait,
graph::GetNodeIndex,
layout::Layout,
router::triangulation::{GetVertexIndex, Triangulation, TriangulationEdgeReference},
triangulation::{GetVertexIndex, Triangulation, TriangulationEdgeReference},
};
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
@ -85,7 +85,7 @@ pub struct Navmesh {
impl Navmesh {
pub fn new(layout: &Layout<impl RulesTrait>) -> Result<Self, InsertionError> {
let mut this = Self {
triangulation: Triangulation::new(layout.drawing()),
triangulation: Triangulation::new(layout.drawing().geometry().graph().node_bound()),
vertex_to_triangulation_vertex: Vec::new(),
};
this.vertex_to_triangulation_vertex

View File

@ -1,16 +1,10 @@
use std::marker::PhantomData;
use geo::{point, Point};
use petgraph::visit::{self, NodeIndexable};
use spade::{
handles::FixedVertexHandle, iterators::VertexIterator, DelaunayTriangulation, HasPosition,
InsertionError,
};
use petgraph::visit;
use spade::{handles::FixedVertexHandle, DelaunayTriangulation, HasPosition, InsertionError};
use crate::{
drawing::{rules::RulesTrait, Drawing},
graph::GetNodeIndex,
};
use crate::graph::GetNodeIndex;
pub trait GetVertexIndex<I> {
fn vertex(&self) -> I;
@ -26,14 +20,13 @@ pub struct Triangulation<I: Copy + PartialEq + GetNodeIndex, W: GetVertexIndex<I
impl<I: Copy + PartialEq + GetNodeIndex, W: GetVertexIndex<I> + HasPosition<Scalar = f64>>
Triangulation<I, W>
{
pub fn new(drawing: &Drawing<impl Copy, impl RulesTrait>) -> Self {
pub fn new(node_bound: usize) -> Self {
let mut this = Self {
triangulation: <DelaunayTriangulation<W> as spade::Triangulation>::new(),
vertex_to_handle: Vec::new(),
index_marker: PhantomData,
};
this.vertex_to_handle
.resize(drawing.geometry().graph().node_bound(), None);
this.vertex_to_handle.resize(node_bound, None);
this
}