Skip to content

Commit

Permalink
Merge pull request #1175 from hannobraun/edge
Browse files Browse the repository at this point in the history
Simplify `HalfEdge`
  • Loading branch information
hannobraun authored Oct 6, 2022
2 parents b7bfad0 + 0e19c59 commit 7b269b5
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 46 deletions.
6 changes: 1 addition & 5 deletions crates/fj-kernel/src/algorithms/reverse/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ impl Reverse for HalfEdge {
[b, a]
};

HalfEdge::new(
self.curve().clone(),
vertices,
self.global_form().clone(),
)
HalfEdge::new(vertices, self.global_form().clone())
}
}
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Sweep for (HalfEdge, Color) {
})
};

HalfEdge::new(curve, vertices, edge.global_form().clone())
HalfEdge::new(vertices, edge.global_form().clone())
};

let side_edges = bottom_edge
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Sweep for (HalfEdge, Color) {
})
};

HalfEdge::new(curve, vertices, global)
HalfEdge::new(vertices, global)
};

let cycle = {
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Sweep for (Vertex, Handle<Surface>) {

// And finally, creating the output `Edge` is just a matter of
// assembling the pieces we've already created.
HalfEdge::new(curve, vertices, edge_global)
HalfEdge::new(vertices, edge_global)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ mod tests {
let global_edge = GlobalEdge::partial()
.from_curve_and_vertices(&curve, &vertices)
.build(&stores);
let half_edge = HalfEdge::new(curve, vertices, global_edge);
let half_edge = HalfEdge::new(vertices, global_edge);

let result =
half_edge.clone().validate_with_config(&ValidationConfig {
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Cycle {
for edge in &half_edges {
assert_eq!(
surface.id(),
edge.surface().id(),
edge.curve().surface().id(),
"Edges in cycle not defined in same surface"
);
}
Expand Down
47 changes: 13 additions & 34 deletions crates/fj-kernel/src/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ use pretty_assertions::{assert_eq, assert_ne};

use crate::stores::{Handle, HandleWrapper};

use super::{Curve, GlobalCurve, GlobalVertex, Surface, Vertex};
use super::{Curve, GlobalCurve, GlobalVertex, Vertex};

/// A half-edge
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct HalfEdge {
surface: Handle<Surface>,
curve: Curve,
vertices: [Vertex; 2],
global_form: GlobalEdge,
}
Expand All @@ -31,19 +29,15 @@ impl HalfEdge {
/// were, the edge would have no length, and thus not be valid. (It is
/// perfectly fine for global forms of the the vertices to be coincident.
/// That would just mean, that ends of the edge connect to each other.)
pub fn new(
curve: Curve,
vertices: [Vertex; 2],
global_form: GlobalEdge,
) -> Self {
pub fn new([a, b]: [Vertex; 2], global_form: GlobalEdge) -> Self {
// Make sure `curve` and `vertices` match.
for vertex in &vertices {
assert_eq!(
&curve,
vertex.curve(),
"An edge and its vertices must be defined on the same curve"
);
}
assert_eq!(
a.curve(),
b.curve(),
"An edge's vertices must be defined in the same curve",
);

let curve = a.curve();

// Make sure `curve` and `vertices` match `global_form`.
assert_eq!(
Expand All @@ -54,48 +48,33 @@ impl HalfEdge {
);
assert_eq!(
&normalize_vertex_order(
vertices.clone().map(|vertex| *vertex.global_form())
[&a, &b].map(|vertex| *vertex.global_form())
),
global_form.vertices_in_normalized_order(),
"The global forms of a half-edge's vertices must match the \
vertices of the half-edge's global form"
);

// Make sure that the edge vertices are not coincident on the curve.
let [a, b] = &vertices;
assert_ne!(
a.position(),
b.position(),
"Vertices of an edge must not be coincident on curve"
);

Self {
surface: curve.surface().clone(),
curve,
vertices,
vertices: [a, b],
global_form,
}
}

/// Access the surface that the half-edge's [`Curve`] is defined on
pub fn surface(&self) -> &Handle<Surface> {
&self.surface
}

/// Access the curve that defines the half-edge's geometry
///
/// The edge can be a segment of the curve that is bounded by two vertices,
/// or if the curve is continuous (i.e. connects to itself), the edge could
/// be defined by the whole curve, and have no bounding vertices.
pub fn curve(&self) -> &Curve {
&self.curve
let [vertex, _] = self.vertices();
vertex.curve()
}

/// Access the vertices that bound the half-edge on the curve
///
/// An edge has either two bounding vertices or none. The latter is possible
/// if the edge's curve is continuous (i.e. connects to itself), and defines
/// the whole edge.
pub fn vertices(&self) -> &[Vertex; 2] {
&self.vertices
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/partial/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ impl PartialHalfEdge {
})
.into_full(stores);

HalfEdge::new(curve, vertices, global_form)
HalfEdge::new(vertices, global_form)
}
}

impl From<&HalfEdge> for PartialHalfEdge {
fn from(half_edge: &HalfEdge) -> Self {
Self {
surface: Some(half_edge.surface().clone()),
surface: Some(half_edge.curve().surface().clone()),
curve: Some(half_edge.curve().clone().into()),
vertices: Some(half_edge.vertices().clone().map(Into::into)),
global_form: Some(half_edge.global_form().clone().into()),
Expand Down

0 comments on commit 7b269b5

Please sign in to comment.