diff --git a/src/delaunay_core/bulk_load.rs b/src/delaunay_core/bulk_load.rs index db21b23..a343baa 100644 --- a/src/delaunay_core/bulk_load.rs +++ b/src/delaunay_core/bulk_load.rs @@ -1469,4 +1469,26 @@ mod test { Ok(()) } + + #[test] + fn test_bulk_load_with_flat_triangle() -> Result<(), InsertionError> { + let dt = DelaunayTriangulation::>::bulk_load(vec![ + Point2::new(-0.4583333333333335, 0.0035353982507333875), + Point2::new(-0.44401041666666685, 0.09000381880347848), + Point2::new(-0.4296875000000002, 0.17647223935622358), + Point2::new(-0.4153645833333336, 0.26294065990896864), + Point2::new(-0.40104166666666696, 0.34940908046171376), + Point2::new(-0.34375, 0.4242340611633537), + Point2::new(-0.2864583333333335, 0.48354314550173816), + Point2::new(-0.22916666666666696, 0.5220359027883882), + Point2::new(-0.171875, 0.5605286600750382), + Point2::new(-0.11458333333333348, 0.5743482879175245), + Point2::new(-0.05729166666666696, 0.5864208547026089), + ])?; + dt.sanity_check(); + let tri = dt.inner_faces().nth(4).unwrap(); + let [p0, p1, p2] = tri.positions(); + assert!(crate::delaunay_core::math::side_query(p0, p1, p2).is_on_left_side()); + Ok(()) + } } diff --git a/src/delaunay_core/handles/handle_impls.rs b/src/delaunay_core/handles/handle_impls.rs index dd6f14d..7b1f732 100644 --- a/src/delaunay_core/handles/handle_impls.rs +++ b/src/delaunay_core/handles/handle_impls.rs @@ -12,13 +12,13 @@ use core::hash::{Hash, Hasher}; use num_traits::{Float, One}; // Debug implementations -impl<'a, V, DE, UE, F> Debug for VertexHandle<'a, V, DE, UE, F> { +impl Debug for VertexHandle<'_, V, DE, UE, F> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { write!(f, "VertexHandle({:?})", self.handle.index()) } } -impl<'a, V, DE, UE, F> Debug for DirectedEdgeHandle<'a, V, DE, UE, F> { +impl Debug for DirectedEdgeHandle<'_, V, DE, UE, F> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { write!( f, @@ -30,7 +30,7 @@ impl<'a, V, DE, UE, F> Debug for DirectedEdgeHandle<'a, V, DE, UE, F> { } } -impl<'a, V, DE, UE, F> Debug for UndirectedEdgeHandle<'a, V, DE, UE, F> { +impl Debug for UndirectedEdgeHandle<'_, V, DE, UE, F> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { let [v0, v1] = self.vertices(); write!( @@ -43,7 +43,7 @@ impl<'a, V, DE, UE, F> Debug for UndirectedEdgeHandle<'a, V, DE, UE, F> { } } -impl<'a, V, DE, UE, F> Debug for FaceHandle<'a, PossiblyOuterTag, V, DE, UE, F> { +impl Debug for FaceHandle<'_, PossiblyOuterTag, V, DE, UE, F> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(inner) = self.as_inner() { inner.fmt(f) @@ -53,7 +53,7 @@ impl<'a, V, DE, UE, F> Debug for FaceHandle<'a, PossiblyOuterTag, V, DE, UE, F> } } -impl<'a, V, DE, UE, F> Debug for FaceHandle<'a, InnerTag, V, DE, UE, F> { +impl Debug for FaceHandle<'_, InnerTag, V, DE, UE, F> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { let [v0, v1, v2] = self.vertices(); write!( @@ -107,58 +107,58 @@ impl FixedDirectedEdgeHandle { } } -impl<'a, V, DE, UE, F, Type: Copy, InnerOuter: InnerOuterMarker> Clone - for DynamicHandleImpl<'a, V, DE, UE, F, Type, InnerOuter> +impl Clone + for DynamicHandleImpl<'_, V, DE, UE, F, Type, InnerOuter> { fn clone(&self) -> Self { *self } } -impl<'a, V, DE, UE, F, Type: Copy, InnerOuter: InnerOuterMarker> Copy - for DynamicHandleImpl<'a, V, DE, UE, F, Type, InnerOuter> +impl Copy + for DynamicHandleImpl<'_, V, DE, UE, F, Type, InnerOuter> { } -impl<'a, V, DE, UE, F, Type: PartialEq, InnerOuter: InnerOuterMarker> PartialEq - for DynamicHandleImpl<'a, V, DE, UE, F, Type, InnerOuter> +impl PartialEq + for DynamicHandleImpl<'_, V, DE, UE, F, Type, InnerOuter> { fn eq(&self, other: &Self) -> bool { self.handle == other.handle } } -impl<'a, V, DE, UE, F, Type: Eq, InnerOuter: InnerOuterMarker> Eq - for DynamicHandleImpl<'a, V, DE, UE, F, Type, InnerOuter> +impl Eq + for DynamicHandleImpl<'_, V, DE, UE, F, Type, InnerOuter> { } -impl<'a, V, DE, UE, F, Type: Hash, InnerOuter: InnerOuterMarker> Hash - for DynamicHandleImpl<'a, V, DE, UE, F, Type, InnerOuter> +impl Hash + for DynamicHandleImpl<'_, V, DE, UE, F, Type, InnerOuter> { fn hash(&self, state: &mut HA) { self.handle.hash(state); } } -impl<'a, V, DE, UE, F, Type: Ord, InnerOuter: InnerOuterMarker> Ord - for DynamicHandleImpl<'a, V, DE, UE, F, Type, InnerOuter> +impl Ord + for DynamicHandleImpl<'_, V, DE, UE, F, Type, InnerOuter> { fn cmp(&self, other: &Self) -> Ordering { self.handle.cmp(&other.handle) } } -impl<'a, V, DE, UE, F, Type: PartialOrd, InnerOuter: InnerOuterMarker> PartialOrd - for DynamicHandleImpl<'a, V, DE, UE, F, Type, InnerOuter> +impl PartialOrd + for DynamicHandleImpl<'_, V, DE, UE, F, Type, InnerOuter> { fn partial_cmp(&self, other: &Self) -> Option { self.handle.partial_cmp(&other.handle) } } -impl<'a, V, DE, UE, F, Type: Copy + Default, InnerOuter: InnerOuterMarker> - DynamicHandleImpl<'a, V, DE, UE, F, Type, InnerOuter> +impl + DynamicHandleImpl<'_, V, DE, UE, F, Type, InnerOuter> { /// Converts this dynamic handle to its fixed variant. /// @@ -201,7 +201,7 @@ impl FixedFaceHandle { } } -impl<'a, V, DE, UE, F> AsRef for DirectedEdgeHandle<'a, V, DE, UE, F> { +impl AsRef for DirectedEdgeHandle<'_, V, DE, UE, F> { fn as_ref(&self) -> &DE { self.data() } @@ -328,7 +328,7 @@ impl<'a, V, DE, UE, F> DirectedEdgeHandle<'a, V, DE, UE, F> { } } -impl<'a, V, DE, UE, F> DirectedEdgeHandle<'a, V, DE, UE, F> +impl DirectedEdgeHandle<'_, V, DE, UE, F> where V: HasPosition, { @@ -432,7 +432,7 @@ where } } -impl<'a, V, DE, UE, F> DirectedEdgeHandle<'a, V, DE, CdtEdge, F> { +impl DirectedEdgeHandle<'_, V, DE, CdtEdge, F> { /// Returns `true` if this edge is a constraint edge. pub fn is_constraint_edge(self) -> bool { self.as_undirected().is_constraint_edge() @@ -488,7 +488,7 @@ impl<'a, V, DE, UE, F> UndirectedVoronoiEdge<'a, V, DE, UE, F> { } } -impl<'a, V, DE, UE, F> AsRef for UndirectedEdgeHandle<'a, V, DE, UE, F> { +impl AsRef for UndirectedEdgeHandle<'_, V, DE, UE, F> { fn as_ref(&self) -> &UE { self.data() } @@ -527,7 +527,7 @@ impl<'a, V, DE, UE, F> UndirectedEdgeHandle<'a, V, DE, UE, F> { } } -impl<'a, V, DE, UE, F> UndirectedEdgeHandle<'a, V, DE, UE, F> +impl UndirectedEdgeHandle<'_, V, DE, UE, F> where V: HasPosition, { @@ -546,7 +546,7 @@ where } } -impl<'a, V, DE, UE, F> UndirectedEdgeHandle<'a, V, DE, UE, F> +impl UndirectedEdgeHandle<'_, V, DE, UE, F> where V: HasPosition, V::Scalar: Float, @@ -570,14 +570,14 @@ where } } -impl<'a, V, DE, UE, F> UndirectedEdgeHandle<'a, V, DE, CdtEdge, F> { +impl UndirectedEdgeHandle<'_, V, DE, CdtEdge, F> { /// Returns `true` if this edge is a constraint edge. pub fn is_constraint_edge(self) -> bool { self.data().is_constraint_edge() } } -impl<'a, V, DE, UE, InnerOuter, F> AsRef for FaceHandle<'a, InnerOuter, V, DE, UE, F> +impl AsRef for FaceHandle<'_, InnerOuter, V, DE, UE, F> where InnerOuter: InnerOuterMarker, { @@ -617,7 +617,7 @@ impl<'a, V, DE, UE, F> FaceHandle<'a, InnerTag, V, DE, UE, F> { } } -impl<'a, V, DE, UE, F> FaceHandle<'a, InnerTag, V, DE, UE, F> +impl FaceHandle<'_, InnerTag, V, DE, UE, F> where V: HasPosition, { @@ -700,13 +700,13 @@ where } } -impl<'a, V, DE, UE, F> AsRef for VertexHandle<'a, V, DE, UE, F> { +impl AsRef for VertexHandle<'_, V, DE, UE, F> { fn as_ref(&self) -> &V { self.data() } } -impl<'a, V, DE, UE, F> VertexHandle<'a, V, DE, UE, F> +impl VertexHandle<'_, V, DE, UE, F> where V: HasPosition, { @@ -775,7 +775,7 @@ impl<'a, V, DE, UE, F> VertexHandle<'a, V, DE, UE, F> { } } -impl<'a, V, DE, UE, F> DirectedEdgeHandle<'a, V, DE, UE, F> +impl DirectedEdgeHandle<'_, V, DE, UE, F> where V: HasPosition, V::Scalar: Float, @@ -796,7 +796,7 @@ where } } -impl<'a, V, DE, UE, F, InnerOuter: InnerOuterMarker> FaceHandle<'a, InnerOuter, V, DE, UE, F> { +impl FaceHandle<'_, InnerOuter, V, DE, UE, F> { /// Returns a reference to the data associated with this face. pub fn data(&self) -> &F { self.dcel.face_data(self.handle) diff --git a/src/delaunay_core/handles/iterators/fixed_iterators.rs b/src/delaunay_core/handles/iterators/fixed_iterators.rs index 61f26a7..5ae1828 100644 --- a/src/delaunay_core/handles/iterators/fixed_iterators.rs +++ b/src/delaunay_core/handles/iterators/fixed_iterators.rs @@ -101,8 +101,8 @@ where } } -impl<'a, V, DE, UE, F, Type, InnerOuter> DoubleEndedIterator - for DynamicHandleIterator<'a, V, DE, UE, F, Type, InnerOuter> +impl DoubleEndedIterator + for DynamicHandleIterator<'_, V, DE, UE, F, Type, InnerOuter> where Type: DelaunayElementType, InnerOuter: InnerOuterMarker, @@ -120,8 +120,8 @@ where } } -impl<'a, V, DE, UE, F, Type, InnerOuter> ExactSizeIterator - for DynamicHandleIterator<'a, V, DE, UE, F, Type, InnerOuter> +impl ExactSizeIterator + for DynamicHandleIterator<'_, V, DE, UE, F, Type, InnerOuter> where Type: DelaunayElementType, InnerOuter: InnerOuterMarker, diff --git a/src/delaunay_core/handles/iterators/hull_iterator.rs b/src/delaunay_core/handles/iterators/hull_iterator.rs index 35fa69f..51a32f2 100644 --- a/src/delaunay_core/handles/iterators/hull_iterator.rs +++ b/src/delaunay_core/handles/iterators/hull_iterator.rs @@ -50,7 +50,7 @@ impl<'a, V, DE, UE, F> Iterator for HullIterator<'a, V, DE, UE, F> { } } -impl<'a, V, DE, UE, F> DoubleEndedIterator for HullIterator<'a, V, DE, UE, F> { +impl DoubleEndedIterator for HullIterator<'_, V, DE, UE, F> { fn next_back(&mut self) -> Option { self.inner_iterator.next_back() } diff --git a/src/delaunay_core/handles/public_handles.rs b/src/delaunay_core/handles/public_handles.rs index 20102f9..e385ea3 100644 --- a/src/delaunay_core/handles/public_handles.rs +++ b/src/delaunay_core/handles/public_handles.rs @@ -343,7 +343,7 @@ impl<'a, V, DE, UE, F> DirectedVoronoiEdge<'a, V, DE, UE, F> { } } -impl<'a, V, DE, UE, F> DirectedVoronoiEdge<'a, V, DE, UE, F> +impl DirectedVoronoiEdge<'_, V, DE, UE, F> where V: HasPosition, { diff --git a/src/delaunay_core/hint_generator.rs b/src/delaunay_core/hint_generator.rs index 870b40d..0957f7c 100644 --- a/src/delaunay_core/hint_generator.rs +++ b/src/delaunay_core/hint_generator.rs @@ -250,8 +250,7 @@ impl HintGenerator } let prev_num_vertices = last_layer_size as u32; - // Divide by BRANCH_FACTOR and round up - let max_num_vertices = (prev_num_vertices + BRANCH_FACTOR - 1) / BRANCH_FACTOR; + let max_num_vertices = prev_num_vertices.div_ceil(BRANCH_FACTOR); if triangulation.num_vertices() as u32 > max_num_vertices { // The layer contains too many elements. Remove the last. let vertex_to_pop = FixedVertexHandle::new(triangulation.num_vertices() - 1); diff --git a/src/delaunay_core/math.rs b/src/delaunay_core/math.rs index 58e47f8..1d82ae3 100644 --- a/src/delaunay_core/math.rs +++ b/src/delaunay_core/math.rs @@ -57,7 +57,6 @@ impl std::error::Error for InsertionError {} /// /// *See also [validate_coordinate], [validate_vertex], [MAX_ALLOWED_VALUE], /// [crate::Triangulation::insert], [mitigate_underflow]* - // Implementation note: These numbers come from the paper of Jonathan Richard Shewchuk: // "The four predicates implemented for this report will not overflow nor underflow if // their inputs have exponents in the range -[142, 201] and IEEE-745 double precision diff --git a/src/delaunay_core/refinement.rs b/src/delaunay_core/refinement.rs index ece729e..abbb92e 100644 --- a/src/delaunay_core/refinement.rs +++ b/src/delaunay_core/refinement.rs @@ -820,7 +820,7 @@ where let [is_left_side_excluded, is_right_side_excluded] = [segment.face(), segment.rev().face()].map(|face| { face.as_inner() - .map_or(false, |face| excluded_faces.contains(&face.fix())) + .is_some_and(|face| excluded_faces.contains(&face.fix())) }); let is_constraint_edge = segment.is_constraint_edge(); diff --git a/src/intersection_iterator.rs b/src/intersection_iterator.rs index 664bdcb..65dd37f 100644 --- a/src/intersection_iterator.rs +++ b/src/intersection_iterator.rs @@ -89,7 +89,7 @@ where EdgeOverlap(DirectedEdgeHandle<'a, V, DE, UE, F>), } -impl<'a, V, DE, UE, F> core::fmt::Debug for Intersection<'a, V, DE, UE, F> +impl core::fmt::Debug for Intersection<'_, V, DE, UE, F> where V: HasPosition, { @@ -103,7 +103,7 @@ where } } -impl<'a, V, DE, UE, F> PartialEq for Intersection<'a, V, DE, UE, F> +impl PartialEq for Intersection<'_, V, DE, UE, F> where V: HasPosition, { @@ -118,9 +118,9 @@ where } } -impl<'a, V, DE, UE, F> Copy for Intersection<'a, V, DE, UE, F> where V: HasPosition {} +impl Copy for Intersection<'_, V, DE, UE, F> where V: HasPosition {} -impl<'a, V, DE, UE, F> Clone for Intersection<'a, V, DE, UE, F> +impl Clone for Intersection<'_, V, DE, UE, F> where V: HasPosition, {