Skip to content
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
69 changes: 54 additions & 15 deletions src/cdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,29 @@
}
}

/// Removes a vertex from the triangulation.
///
/// This operation runs in O(n²), where n is the degree of the
/// removed vertex.
///
/// # Handle invalidation
/// This method will invalidate all vertex, edge and face handles.
fn remove(&mut self, vertex: FixedVertexHandle) -> V {
let removed_constraints = self
.dcel
.vertex(vertex)
.out_edges()
.filter(|edge| edge.is_constraint_edge())
.map(|e| e.as_undirected().fix())
.collect::<Vec<_>>();

for e in removed_constraints {
self.remove_constraint_edge(e);
}

self.remove_and_notify(vertex)
}

fn into_parts(
self,
) -> (
Expand Down Expand Up @@ -393,23 +416,15 @@
Ok(result)
}

/// Removes a vertex from the triangulation.
///
/// This operation runs in O(n²), where n is the degree of the
/// removed vertex.
///
/// # Handle invalidation
/// This method will invalidate all vertex, edge and face handles.
/// See [Triangulation::remove]. This function was accidentally implemented separately for CDTs and will be removed in future releases.
/// Use the method from the trait instead.
#[deprecated(
since = "2.14.0",
note = "Please use `remove` from trait `Triangulation` instead."
)]
pub fn remove(&mut self, vertex: FixedVertexHandle) -> V {
let num_removed_constraints = self
.dcel
.vertex(vertex)
.out_edges()
.map(|edge| edge.is_constraint_edge())
.filter(|b| *b)
.count();
self.num_constraints -= num_removed_constraints;
self.remove_and_notify(vertex)
<Self as Triangulation>::remove(self, vertex)
}

/// Returns the number of constraint edges.
Expand Down Expand Up @@ -1752,7 +1767,7 @@
cdt.add_constraint(v1, v2);
cdt.add_constraint(v2, v0);
assert_eq!(cdt.num_constraints(), 3);
cdt.remove(v1);

Check warning on line 1770 in src/cdt.rs

View workflow job for this annotation

GitHub Actions / Test Suite

use of deprecated method `cdt::ConstrainedDelaunayTriangulation::<V, DE, UE, F, L>::remove`: Please use `remove` from trait `Triangulation` instead.

Check warning on line 1770 in src/cdt.rs

View workflow job for this annotation

GitHub Actions / Test Suite

use of deprecated method `cdt::ConstrainedDelaunayTriangulation::<V, DE, UE, F, L>::remove`: Please use `remove` from trait `Triangulation` instead.
assert_eq!(cdt.num_constraints(), 1);
cdt.cdt_sanity_check();
Ok(())
Expand Down Expand Up @@ -2051,6 +2066,30 @@
Ok(())
}

#[test]
fn test_remove_vertex_respects_constraints() -> Result<(), InsertionError> {
let mut triangulation =
ConstrainedDelaunayTriangulation::<Point2<f32>>::bulk_load_cdt_stable(
vec![
Point2::new(-1.0, 0.0),
Point2::new(0.0, 0.0),
Point2::new(0.0, 1.0),
Point2::new(1.0, 1.0),
],
vec![[0, 1], [1, 2], [2, 3]],
)?;

let mut copy = triangulation.clone();

triangulation.remove(FixedVertexHandle::from_index(1));

Check warning on line 2084 in src/cdt.rs

View workflow job for this annotation

GitHub Actions / Test Suite

use of deprecated method `cdt::ConstrainedDelaunayTriangulation::<V, DE, UE, F, L>::remove`: Please use `remove` from trait `Triangulation` instead.

Check warning on line 2084 in src/cdt.rs

View workflow job for this annotation

GitHub Actions / Test Suite

use of deprecated method `cdt::ConstrainedDelaunayTriangulation::<V, DE, UE, F, L>::remove`: Please use `remove` from trait `Triangulation` instead.
triangulation.cdt_sanity_check();

copy.locate_and_remove(Point2::new(0.0, 0.0));
copy.cdt_sanity_check();

Ok(())
}

#[test]
fn test_remove_constraint_edge() -> Result<(), InsertionError> {
let mut cdt = get_cdt_for_try_add_constraint()?;
Expand Down
2 changes: 1 addition & 1 deletion src/delaunay_core/bulk_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ impl Hull {

const INVALID: usize = usize::MAX;
self.buckets
.extend(core::iter::repeat(INVALID).take(target_size));
.extend(core::iter::repeat_n(INVALID, target_size));

let (first_index, current_node) = self
.data
Expand Down
2 changes: 1 addition & 1 deletion src/delaunay_core/hint_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use alloc::vec::Vec;
/// fulfill most needs:
/// - A heuristic that uses the last inserted vertex as hint ([LastUsedVertexHintGenerator])
/// - A hint generator based on a hierarchy of triangulations that improves walk time to `O(log(n))`
/// ([HierarchyHintGenerator])
/// ([HierarchyHintGenerator])
pub trait HintGenerator<S: SpadeNum>: Default {
/// Returns a vertex handle that should be close to a given position.
///
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ mod test_utilities;
/// Reference handles come in one of four variants:
/// * [FaceHandle](handles::FaceHandle)s refer to a single face (triangle) of the triangulation.
/// They are used get the triangle's adjacent vertices and edges. They also may refer to
/// the single outer face.
/// the single outer face.
/// * [VertexHandle](handles::VertexHandle)s refer to a single vertex of the triangulation. They
/// allow to retrieve the vertex position and its outgoing edges.
/// * [DirectedEdgeHandle](handles::DirectedEdgeHandle)s refer to a single directed edge. They
Expand Down
2 changes: 1 addition & 1 deletion src/triangulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ pub trait Triangulation: Default {
point: Point2<<Self::Vertex as HasPosition>::Scalar>,
) -> Option<Self::Vertex> {
match self.locate_with_hint_option_core(point, None) {
PositionInTriangulation::OnVertex(handle) => Some(self.remove_and_notify(handle)),
PositionInTriangulation::OnVertex(handle) => Some(self.remove(handle)),
_ => None,
}
}
Expand Down
Loading