diff --git a/editor/src/main.rs b/editor/src/main.rs index 92102a7..b04adac 100644 --- a/editor/src/main.rs +++ b/editor/src/main.rs @@ -281,9 +281,9 @@ fn setup_meshes( Name::new("Generated Shape"), )); - show_vertex_indices(&mut texts, &mesh); + /*show_vertex_indices(&mut texts, &mesh); show_edges(&mut texts, &mesh, 0.1); - show_faces(&mut texts, &mesh); + show_faces(&mut texts, &mesh);*/ commands.spawn(( PbrBundle { diff --git a/src/representation/face/tesselate/delaunay/mod.rs b/src/representation/face/tesselate/delaunay/mod.rs index e0090b0..13f9102 100644 --- a/src/representation/face/tesselate/delaunay/mod.rs +++ b/src/representation/face/tesselate/delaunay/mod.rs @@ -22,11 +22,13 @@ where ) where P::Vec: Vector3D, { - let eps = P::S::ZERO; // TODO: Numerical instability... This is so close to zero we have to include equal to zero (or slightly smaller). This just doesn't work! + let eps = P::S::EPS; // TODO: Numerical instability... This is so close to zero we have to include equal to zero (or slightly smaller). This just doesn't work! + let mut this_is_a_hack_eps = P::S::ZERO; let vs: Vec<(P::Vec2, V)> = self.vertices_2d::(mesh).collect(); let mut flips = 0; let max_flips = vs.len() * vs.len(); + let min_flips = vs.len() * ((vs.len() as f32).sqrt() as usize); assert!(indices.len() - first == (self.num_vertices(mesh) - 2) * 3); assert!(indices[first..] @@ -55,7 +57,7 @@ where if vs[indices[neigh.other_ns].index()] .0 - .is_inside_circumcircle(v21, v22, v23, eps) + .is_inside_circumcircle(v21, v22, v23, this_is_a_hack_eps) { dual.flip(&neigh, indices); neigh.flip_indices(indices); @@ -66,6 +68,10 @@ where println!("WARNING: Delaunay might not terminate if numerical instabilities are too bad. Aborting."); return; } + // After a few iterations, increase the eps to the "real" eps + if flips == min_flips { + this_is_a_hack_eps = eps; + } // println!("{} <-> {}", neigh.s.index(), neigh.o.index());