Skip to content

Commit

Permalink
Add PartialHalfEdge::as_line_segment
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Sep 26, 2022
1 parent a46eb3a commit 66c9124
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions crates/fj-kernel/src/partial/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,41 @@ impl PartialHalfEdge {
self
}

/// Update partial half-edge as a line segment, reusing existing vertices
pub fn as_line_segment(mut self) -> Self {
let [from, to] = self
.vertices
.clone()
.expect("Can't infer line segment without vertices")
.map(|vertex| {
vertex.surface_form().expect(
"Can't infer line segment without two surface vertices",
)
});

let surface = from
.surface()
.copied()
.or_else(|| to.surface().copied())
.expect("Can't infer line segment without a surface");
let points = [from, to].map(|vertex| {
vertex
.position()
.expect("Can't infer line segment without surface position")
});

let curve = PartialCurve {
global_form: self.extract_global_curve(),
..PartialCurve::default()
}
.with_surface(surface)
.as_line_from_points(points);

self.curve = Some(curve.into());

self
}

/// Build a full [`HalfEdge`] from the partial half-edge
pub fn build(self, stores: &Stores) -> HalfEdge {
let curve = self
Expand Down

0 comments on commit 66c9124

Please sign in to comment.