Skip to content

Commit

Permalink
Merge pull request #131 from hannobraun/spade
Browse files Browse the repository at this point in the history
Replace delaunator-rs with Spade
  • Loading branch information
hannobraun authored Feb 4, 2022
2 parents 001e176 + a07386f commit 8d593db
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
29 changes: 19 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ anyhow = "1.0.53"
approx = "0.5.1"
bytemuck = "1.7.3"
decorum = "0.3.1"
delaunator = "1.0.1"
futures = "0.3.19"
libloading = "0.7.2"
nalgebra = "0.30.0"
notify = "5.0.0-pre.13"
parry2d-f64 = "0.8.0"
parry3d-f64 = "0.8.0"
spade = "2.0.0"
thiserror = "1.0.30"
threemf = "0.2.0"
tracing = "0.1.29"
Expand Down
21 changes: 11 additions & 10 deletions src/kernel/topology/faces.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeSet;

use decorum::R64;
use nalgebra::point;
use parry2d_f64::{
bounding_volume::AABB,
query::{Ray as Ray2, RayCast as _},
Expand Down Expand Up @@ -255,25 +256,25 @@ impl Face {

/// Create a Delaunay triangulation of all vertices
pub fn triangulate(vertices: &[Point<2>]) -> Vec<Triangle2> {
use spade::Triangulation as _;

let points: Vec<_> = vertices
.iter()
.map(|vertex| delaunator::Point {
.map(|vertex| spade::Point2 {
x: vertex.x,
y: vertex.y,
})
.collect();

let triangulation = delaunator::triangulate(&points);
let triangulation = spade::DelaunayTriangulation::<_>::bulk_load(points)
.expect("Inserted invalid values into triangulation");

let mut triangles = Vec::new();
for triangle in triangulation.triangles.chunks(3) {
let i0 = triangle[0];
let i1 = triangle[1];
let i2 = triangle[2];

let v0 = vertices[i0];
let v1 = vertices[i1];
let v2 = vertices[i2];
for triangle in triangulation.inner_faces() {
let [v0, v1, v2] = triangle.vertices().map(|vertex| {
let pos = vertex.position();
point![pos.x, pos.y]
});

let triangle = match corner_direction(&v0, &v1, &v2) {
Orientation::Ccw => [v0, v1, v2].into(),
Expand Down

0 comments on commit 8d593db

Please sign in to comment.