Skip to content

Commit

Permalink
correct order of polygons for each vertex
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Aug 8, 2023
1 parent bad17f6 commit 928fb6a
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/input/triangulation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::collections::VecDeque;

use glam::{vec2, Vec2};
use hashbrown::HashMap;
use spade::{ConstrainedDelaunayTriangulation, Point2, Triangulation as SpadeTriangulation};

use crate::{
Expand Down Expand Up @@ -80,12 +83,14 @@ impl Triangulation {
(intersect - parallel) % 2 == 1
};

let mut face_to_polygon = HashMap::new();
let polygons = cdt
.inner_faces()
.filter_map(|face| {
let centre = face.center();
let centre = Vec2::new(centre.x, centre.y);
in_polygon(centre, &outer_edges, max_y_outer_edge).then(|| {
face_to_polygon.insert(face.index(), face_to_polygon.len() as isize);
Polygon::new(
face.vertices()
.iter()
Expand All @@ -99,23 +104,26 @@ impl Triangulation {

let vertices = cdt
.vertices()
.enumerate()
.map(|(point_index, point)| {
let mut polygons = polygons
.iter()
.enumerate()
.filter_map(|(polygon_index, polygon)| {
if polygon.vertices.contains(&(point_index as u32)) {
Some(polygon_index as isize)
} else {
None
}
.map(|point| {
let mut point_polygons = point
.out_edges()
.map(|out_edge| {
face_to_polygon
.get(&out_edge.face().index())
.cloned()
.unwrap_or(-1)
})
.collect::<Vec<_>>();
if cdt.locate_vertex(point.position()).is_some() {
polygons.push(-1);
.collect::<VecDeque<_>>();
while point_polygons[0] == -1 {
point_polygons.pop_front();
point_polygons.push_back(-1);
}
Vertex::new(Vec2::new(point.position().x, point.position().y), polygons)
let mut point_polygons: Vec<_> = point_polygons.into();
point_polygons.dedup();
Vertex::new(
Vec2::new(point.position().x, point.position().y),
point_polygons,
)
})
.collect::<Vec<_>>();

Expand Down

0 comments on commit 928fb6a

Please sign in to comment.