Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace delaunator-rs with Spade #131

Merged
merged 3 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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