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

chore: remove optional crate #91

Merged
merged 5 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ bench = false
smallvec = "1"
robust = "0.2"
num-traits = "0.2"
optional = "0.5"

[dependencies.serde]
package = "serde"
Expand All @@ -25,7 +24,7 @@ version = "1"
features = ["derive"]

[features]
serde = ["optional/serde", "dep:serde"]
RobWalt marked this conversation as resolved.
Show resolved Hide resolved
serde = ["dep:serde"]

[workspace]
members = ["delaunay_compare"]
Expand Down
7 changes: 3 additions & 4 deletions src/delaunay_core/dcel.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -21,7 +20,7 @@ impl<DE, UE> EdgeData<DE, UE> {}
serde(crate = "serde")
)]
pub(super) struct FaceEntry<F> {
pub(super) adjacent_edge: Optioned<FixedDirectedEdgeHandle>,
pub(super) adjacent_edge: Option<FixedDirectedEdgeHandle>,
pub(super) data: F,
}

Expand All @@ -33,7 +32,7 @@ pub(super) struct FaceEntry<F> {
)]
pub(super) struct VertexEntry<V> {
pub(super) data: V,
pub(super) out_edge: Optioned<FixedDirectedEdgeHandle>,
pub(super) out_edge: Option<FixedDirectedEdgeHandle>,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down Expand Up @@ -247,7 +246,7 @@ impl<V, DE, UE, F> Dcel<V, DE, UE, F> {
&self,
handle: FixedHandleImpl<FaceTag, InnerOuter>,
) -> Option<FixedHandleImpl<DirectedEdgeTag, InnerTag>> {
self.faces[handle.index()].adjacent_edge.into_option()
self.faces[handle.index()].adjacent_edge
}

pub fn vertex_data<InnerOuter: InnerOuterMarker>(
Expand Down
103 changes: 51 additions & 52 deletions src/delaunay_core/dcel_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
};

Expand All @@ -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());
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
});

Expand Down Expand Up @@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -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
}
Expand Down Expand Up @@ -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(),
};

Expand All @@ -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);

Expand All @@ -841,7 +840,7 @@ pub fn insert_first_vertex<V, DE, UE, F>(
assert!(dcel.vertices.is_empty());
dcel.vertices.push(VertexEntry {
data: vertex,
out_edge: optional::none(),
out_edge: None,
});
FixedVertexHandle::new(0)
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -939,20 +938,20 @@ 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(),
};

dcel.faces.push(face1);
dcel.faces.push(face2);

let vertex = VertexEntry {
out_edge: optional::some(e4),
out_edge: Some(e4),
data: vertex,
};
dcel.vertices.push(vertex);
Expand Down Expand Up @@ -1021,7 +1020,7 @@ where
F: Default,
{
let outer_face = FaceEntry {
adjacent_edge: optional::none(),
adjacent_edge: None,
data: F::default(),
};

Expand Down Expand Up @@ -1066,11 +1065,11 @@ pub fn flip_cw<V, DE, UE, F>(dcel: &mut Dcel<V, DE, UE, F>, 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).
Expand Down Expand Up @@ -1135,8 +1134,8 @@ fn fix_handle_swap<V, DE, UE, F>(

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.
Expand Down Expand Up @@ -1233,8 +1232,8 @@ fn remove_when_two_vertices_left<V, DE, UE, F>(
};

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,
Expand All @@ -1260,8 +1259,8 @@ fn remove_when_all_vertices_on_line<V, DE, UE, F>(

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());

Expand Down Expand Up @@ -1290,10 +1289,10 @@ fn remove_when_all_vertices_on_line<V, DE, UE, F>(
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());
Expand Down Expand Up @@ -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,
};

Expand Down
Loading