diff --git a/Cargo.toml b/Cargo.toml index f13b532..7a1e797 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ bench = false smallvec = "1" robust = "0.2" num-traits = "0.2" -optional = "0.5" [dependencies.serde] package = "serde" @@ -24,9 +23,6 @@ optional = true version = "1" features = ["derive"] -[features] -serde = ["optional/serde", "dep:serde"] - [workspace] members = ["delaunay_compare"] diff --git a/src/delaunay_core/bulk_load.rs b/src/delaunay_core/bulk_load.rs index 420baa1..9232ffd 100644 --- a/src/delaunay_core/bulk_load.rs +++ b/src/delaunay_core/bulk_load.rs @@ -478,7 +478,6 @@ impl Hull { .find(|(index, _)| !self.empty.contains(index)) .unwrap(); - let first_index = first_index; let mut current_index = first_index; let first_bucket = self.ceiled_bucket(current_node.angle); self.buckets[first_bucket] = current_index; diff --git a/src/delaunay_core/dcel.rs b/src/delaunay_core/dcel.rs index a4e8f82..bbec1a1 100644 --- a/src/delaunay_core/dcel.rs +++ b/src/delaunay_core/dcel.rs @@ -1,7 +1,6 @@ use super::handles::handle_defs::FixedHandleImpl; use super::handles::iterators::*; use super::handles::*; -use optional::Optioned; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -21,7 +20,7 @@ impl EdgeData {} serde(crate = "serde") )] pub(super) struct FaceEntry { - pub(super) adjacent_edge: Optioned, + pub(super) adjacent_edge: Option, pub(super) data: F, } @@ -33,7 +32,7 @@ pub(super) struct FaceEntry { )] pub(super) struct VertexEntry { pub(super) data: V, - pub(super) out_edge: Optioned, + pub(super) out_edge: Option, } #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -247,7 +246,7 @@ impl Dcel { &self, handle: FixedHandleImpl, ) -> Option> { - self.faces[handle.index()].adjacent_edge.into_option() + self.faces[handle.index()].adjacent_edge } pub fn vertex_data( diff --git a/src/delaunay_core/dcel_operations.rs b/src/delaunay_core/dcel_operations.rs index 9366acb..b323b7f 100644 --- a/src/delaunay_core/dcel_operations.rs +++ b/src/delaunay_core/dcel_operations.rs @@ -49,8 +49,8 @@ where dcel.half_edge_mut(edge).face = OUTER_FACE_HANDLE; - dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = optional::some(edge); - dcel.vertices[from.index()].out_edge = optional::some(edge); + dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = Some(edge); + dcel.vertices[from.index()].out_edge = Some(edge); } IsolateVertexResult { @@ -144,7 +144,7 @@ where let new_edge = EdgeEntry::new(new_norm, new_twin); let new_face = FaceEntry { - adjacent_edge: optional::some(new_edge_handle), + adjacent_edge: Some(new_edge_handle), data: F::default(), }; @@ -157,7 +157,7 @@ where dcel.half_edge_mut(inner_edge).next = outer_edge; dcel.half_edge_mut(inner_edge).face = new_face_handle; - dcel.vertices[outer_edge_from.index()].out_edge = optional::some(outer_edge); + dcel.vertices[outer_edge_from.index()].out_edge = Some(outer_edge); dcel.edges.push(new_edge); new_edges.push(new_edge_handle.as_undirected()); @@ -174,7 +174,7 @@ where // Create a new face for the last triangle let new_face_handle = FixedFaceHandle::new(dcel.faces.len()); let new_face = FaceEntry { - adjacent_edge: optional::some(inner_edge), + adjacent_edge: Some(inner_edge), data: F::default(), }; dcel.half_edge_mut(inner_edge).face = new_face_handle; @@ -194,13 +194,13 @@ where // Update out_edge entries for the triangle's vertices let prev_origin = dcel.half_edge_mut(inner_edge_prev).origin; - dcel.vertices[prev_origin.index()].out_edge = optional::some(inner_edge_prev); + dcel.vertices[prev_origin.index()].out_edge = Some(inner_edge_prev); let next_origin = dcel.half_edge_mut(inner_edge_next).origin; - dcel.vertices[next_origin.index()].out_edge = optional::some(inner_edge_next); + dcel.vertices[next_origin.index()].out_edge = Some(inner_edge_next); // fan_origin is the third vertex of the triangle - dcel.vertices[fan_origin.index()].out_edge = optional::some(inner_edge); + dcel.vertices[fan_origin.index()].out_edge = Some(inner_edge); IsolateVertexResult { new_edges, @@ -281,11 +281,11 @@ where dcel.half_edge_mut(edge).face = new_face_handle; dcel.half_edge_mut(edge_entry.next).face = new_face_handle; - dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = optional::some(new_outer_handle); + dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = Some(new_outer_handle); dcel.edges.push(new_edge_entry); dcel.faces.push(FaceEntry { - adjacent_edge: optional::some(new_inner_handle), + adjacent_edge: Some(new_inner_handle), data: F::default(), }); @@ -368,13 +368,13 @@ where }); dcel.faces.push(FaceEntry { - adjacent_edge: optional::some(edge), + adjacent_edge: Some(edge), data: F::default(), }); dcel.vertices.push(VertexEntry { data: new_vertex, - out_edge: optional::some(new_prev_handle.normalized()), + out_edge: Some(new_prev_handle.normalized()), }); *dcel.half_edge_mut(edge) = HalfEdgeEntry { @@ -384,8 +384,7 @@ where ..edge_entry }; - dcel.faces[edge_entry.face.index()].adjacent_edge = - optional::some(new_prev_handle.not_normalized()); + dcel.faces[edge_entry.face.index()].adjacent_edge = Some(new_prev_handle.not_normalized()); dcel.half_edge_mut(edge_entry.next).prev = new_next_handle.not_normalized(); dcel.half_edge_mut(edge_entry.prev).next = new_prev_handle.not_normalized(); @@ -449,7 +448,7 @@ where dcel.vertices.push(VertexEntry { data: new_vertex, - out_edge: optional::some(new_edge), + out_edge: Some(new_edge), }); new_vertex_handle @@ -496,7 +495,7 @@ where dcel.half_edge_mut(rev).origin = new_vertex_handle; - dcel.vertices[to.index()].out_edge = optional::some(new_edge_rev); + dcel.vertices[to.index()].out_edge = Some(new_edge_rev); let (new_edge_next, new_rev_prev) = if is_isolated { (new_edge_rev, new_edge) @@ -523,7 +522,7 @@ where dcel.vertices.push(VertexEntry { data: new_vertex, - out_edge: optional::some(new_edge), + out_edge: Some(new_edge), }); new_vertex_handle @@ -629,13 +628,13 @@ where }; let new_face = FaceEntry { - adjacent_edge: optional::some(e2), + adjacent_edge: Some(e2), data: Default::default(), }; let new_vertex_entry = VertexEntry { data: new_vertex_data, - out_edge: optional::some(e2), + out_edge: Some(e2), }; dcel.edges.push(EdgeEntry::new(edge1, twin1)); @@ -654,8 +653,8 @@ where dcel.half_edge_mut(edge_next).face = nf; dcel.half_edge_mut(edge_twin).origin = nv; - dcel.vertices[to.index()].out_edge = optional::some(e2.rev()); - dcel.faces[f1.index()].adjacent_edge = optional::some(edge_handle); + dcel.vertices[to.index()].out_edge = Some(e2.rev()); + dcel.faces[f1.index()].adjacent_edge = Some(edge_handle); nv } @@ -792,17 +791,17 @@ where }; let new_vertex_entry = VertexEntry { - out_edge: optional::some(t0), + out_edge: Some(t0), data: new_vertex, }; let face2 = FaceEntry { - adjacent_edge: optional::some(e2), + adjacent_edge: Some(e2), data: F::default(), }; let face3 = FaceEntry { - adjacent_edge: optional::some(e3), + adjacent_edge: Some(e3), data: F::default(), }; @@ -824,10 +823,10 @@ where dcel.half_edge_mut(ep).prev = t3; dcel.vertices.push(new_vertex_entry); - dcel.vertices[v3.index()].out_edge = optional::some(e2); + dcel.vertices[v3.index()].out_edge = Some(e2); - dcel.faces[f0.index()].adjacent_edge = optional::some(e0); - dcel.faces[f1.index()].adjacent_edge = optional::some(e1); + dcel.faces[f0.index()].adjacent_edge = Some(e0); + dcel.faces[f1.index()].adjacent_edge = Some(e1); dcel.faces.push(face2); dcel.faces.push(face3); @@ -841,7 +840,7 @@ pub fn insert_first_vertex( assert!(dcel.vertices.is_empty()); dcel.vertices.push(VertexEntry { data: vertex, - out_edge: optional::none(), + out_edge: None, }); FixedVertexHandle::new(0) } @@ -876,10 +875,10 @@ where dcel.vertices.push(VertexEntry { data: vertex, - out_edge: optional::some(not_normalized), + out_edge: Some(not_normalized), }); - dcel.vertices[0].out_edge = optional::some(normalized); - dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = optional::some(normalized); + dcel.vertices[0].out_edge = Some(normalized); + dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = Some(normalized); second_vertex } @@ -939,12 +938,12 @@ where let f2 = FixedFaceHandle::new(dcel.faces.len() + 1); let face1 = FaceEntry { - adjacent_edge: optional::some(e1), + adjacent_edge: Some(e1), data: F::default(), }; let face2 = FaceEntry { - adjacent_edge: optional::some(e2), + adjacent_edge: Some(e2), data: F::default(), }; @@ -952,7 +951,7 @@ where dcel.faces.push(face2); let vertex = VertexEntry { - out_edge: optional::some(e4), + out_edge: Some(e4), data: vertex, }; dcel.vertices.push(vertex); @@ -1021,7 +1020,7 @@ where F: Default, { let outer_face = FaceEntry { - adjacent_edge: optional::none(), + adjacent_edge: None, data: F::default(), }; @@ -1066,11 +1065,11 @@ pub fn flip_cw(dcel: &mut Dcel, e: FixedUndirectedEd dcel.half_edge_mut(ep).prev = t; dcel.half_edge_mut(ep).face = t_face; - dcel.vertices[e_origin.index()].out_edge = optional::some(tn); - dcel.vertices[t_origin.index()].out_edge = optional::some(en); + dcel.vertices[e_origin.index()].out_edge = Some(tn); + dcel.vertices[t_origin.index()].out_edge = Some(en); - dcel.faces[e_face.index()].adjacent_edge = optional::some(e); - dcel.faces[t_face.index()].adjacent_edge = optional::some(t); + dcel.faces[e_face.index()].adjacent_edge = Some(e); + dcel.faces[t_face.index()].adjacent_edge = Some(t); } /// Vertex removal has two stages: First, the vertex is disconnected from its surroundings (isolated). @@ -1135,8 +1134,8 @@ fn fix_handle_swap( let edge_origin = dcel.half_edge(edge_handle).origin; let edge_face = dcel.half_edge(edge_handle).face; - dcel.vertices[edge_origin.index()].out_edge = optional::some(edge_handle); - dcel.faces[edge_face.index()].adjacent_edge = optional::some(edge_handle); + dcel.vertices[edge_origin.index()].out_edge = Some(edge_handle); + dcel.faces[edge_face.index()].adjacent_edge = Some(edge_handle); } /// Removes a vertex from the DCEL by swapping in another. @@ -1233,8 +1232,8 @@ fn remove_when_two_vertices_left( }; let result = dcel.vertices.swap_remove(vertex_to_remove.index()).data; - dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = optional::none(); - dcel.vertices[0].out_edge = optional::none(); + dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = None; + dcel.vertices[0].out_edge = None; dcel.edges.clear(); RemovalResult { removed_vertex: result, @@ -1260,8 +1259,8 @@ fn remove_when_all_vertices_on_line( dcel.half_edge_mut(o_next).prev = o_next.rev(); dcel.half_edge_mut(o_next.rev()).next = o_next; - dcel.vertices[vertex_to_update.index()].out_edge = optional::some(o_next); - dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = optional::some(o_next); + dcel.vertices[vertex_to_update.index()].out_edge = Some(o_next); + dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = Some(o_next); swap_remove_undirected_edge(dcel, out_edge1.as_undirected()); @@ -1290,10 +1289,10 @@ fn remove_when_all_vertices_on_line( dcel.half_edge_mut(t1.rev()).prev = t2_prev; } - dcel.vertices[e2_to.index()].out_edge = optional::some(t1.rev()); + dcel.vertices[e2_to.index()].out_edge = Some(t1.rev()); dcel.half_edge_mut(t1.rev()).origin = e2_to; - dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = optional::some(t1); + dcel.faces[OUTER_FACE_HANDLE.index()].adjacent_edge = Some(t1); let result = swap_remove_vertex(dcel, vertex_to_remove); swap_remove_undirected_edge(dcel, e2.as_undirected()); @@ -1372,27 +1371,27 @@ mod test { ); let face0 = FaceEntry { - adjacent_edge: optional::some(e0), + adjacent_edge: Some(e0), data: (), }; let face1 = FaceEntry { - adjacent_edge: optional::some(e1), + adjacent_edge: Some(e1), data: (), }; let vertex0 = VertexEntry { - out_edge: optional::some(e0), + out_edge: Some(e0), data: 0, }; let vertex1 = VertexEntry { - out_edge: optional::some(e2), + out_edge: Some(e2), data: 1, }; let vertex2 = VertexEntry { - out_edge: optional::some(e4), + out_edge: Some(e4), data: 2, }; diff --git a/src/delaunay_core/handles/handle_defs.rs b/src/delaunay_core/handles/handle_defs.rs index 975e1a4..2e88880 100644 --- a/src/delaunay_core/handles/handle_defs.rs +++ b/src/delaunay_core/handles/handle_defs.rs @@ -27,38 +27,6 @@ pub struct FixedHandleImpl { inner_outer: InnerOuter, } -impl optional::Noned - for FixedHandleImpl -{ - fn is_none(&self) -> bool { - optional::wrap(self.index).is_none() - } - - fn get_none() -> Self { - Self { - index: optional::Optioned::<_>::none().unpack(), - ty: Default::default(), - inner_outer: Default::default(), - } - } -} - -impl optional::OptEq - for FixedHandleImpl -{ - fn opt_eq(&self, other: &Self) -> bool { - self.index().opt_eq(&other.index()) - } -} - -impl optional::OptOrd - for FixedHandleImpl -{ - fn opt_cmp(&self, other: &Self) -> std::cmp::Ordering { - self.index().opt_cmp(&other.index()) - } -} - impl std::fmt::Debug for FixedHandleImpl { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("FixedHandle") @@ -233,18 +201,3 @@ impl DelaunayElementType for UndirectedVoronoiEdgeTag { dcel.num_undirected_edges() } } - -#[cfg(test)] -pub mod test { - use optional::Optioned; - - use crate::handles::FixedDirectedEdgeHandle; - - #[test] - fn optioned_handle_is_smaller_than_option_type() { - let optioned_size = std::mem::size_of::>(); - let option_size = std::mem::size_of::>(); - - assert!(optioned_size < option_size); - } -} diff --git a/src/delaunay_core/handles/handle_impls.rs b/src/delaunay_core/handles/handle_impls.rs index f2792c2..ac96735 100644 --- a/src/delaunay_core/handles/handle_impls.rs +++ b/src/delaunay_core/handles/handle_impls.rs @@ -111,10 +111,7 @@ impl<'a, V, DE, UE, F, Type: Copy, InnerOuter: InnerOuterMarker> Clone for DynamicHandleImpl<'a, V, DE, UE, F, Type, InnerOuter> { fn clone(&self) -> Self { - Self { - dcel: self.dcel, - handle: self.handle, - } + *self } } diff --git a/src/delaunay_core/handles/iterators/fixed_iterators.rs b/src/delaunay_core/handles/iterators/fixed_iterators.rs index 39ce5de..c143cc2 100644 --- a/src/delaunay_core/handles/iterators/fixed_iterators.rs +++ b/src/delaunay_core/handles/iterators/fixed_iterators.rs @@ -71,7 +71,7 @@ where DynamicHandleIterator { fixed_iterator: FixedHandleIterator::new(Type::num_elements(dcel)), dcel, - inner_outer: std::marker::PhantomData::default(), + inner_outer: std::marker::PhantomData, } } } diff --git a/src/delaunay_triangulation.rs b/src/delaunay_triangulation.rs index 22b5785..6d55fef 100644 --- a/src/delaunay_triangulation.rs +++ b/src/delaunay_triangulation.rs @@ -356,7 +356,7 @@ mod test { use crate::{DelaunayTriangulation, InsertionError, Point2, Triangulation}; #[allow(unused)] - #[cfg(all(feature = "serde"))] + #[cfg(feature = "serde")] // Just needs to compile fn check_serde() { use serde::{Deserialize, Serialize}; diff --git a/src/intersection_iterator.rs b/src/intersection_iterator.rs index 68ce544..321423b 100644 --- a/src/intersection_iterator.rs +++ b/src/intersection_iterator.rs @@ -60,12 +60,7 @@ where V: HasPosition, { fn clone(&self) -> Self { - use self::Intersection::*; - match self { - EdgeIntersection(handle) => EdgeIntersection(*handle), - VertexIntersection(handle) => VertexIntersection(*handle), - EdgeOverlap(handle) => EdgeOverlap(*handle), - } + *self } }