Move start_position to HalfEdgeGeometry

This commit is contained in:
Hanno Braun 2024-03-22 14:41:14 +01:00
parent bafd117b1c
commit bc6a6a2763
7 changed files with 44 additions and 16 deletions

View File

@ -27,7 +27,11 @@ impl Approx for (&Handle<HalfEdge>, &SurfaceGeometry) {
let (half_edge, surface) = self;
let tolerance = tolerance.into();
let start_position_surface = half_edge.start_position();
let start_position_surface = core
.layers
.geometry
.of_half_edge(half_edge)
.start_position(half_edge.boundary());
let start_position =
match cache.start_position.get(half_edge.start_vertex()) {
Some(position) => position,

View File

@ -1,4 +1,6 @@
use super::SurfacePath;
use fj_math::Point;
use super::{CurveBoundary, SurfacePath};
/// The geometry of a half-edge
#[derive(Copy, Clone)]
@ -30,3 +32,18 @@ pub struct HalfEdgeGeometry {
/// hopefully, temporary.
pub path: SurfacePath,
}
impl HalfEdgeGeometry {
/// Compute the surface position where the half-edge starts
pub fn start_position(
&self,
boundary: CurveBoundary<Point<1>>,
) -> Point<2> {
// Computing the surface position from the curve position is fine.
// `HalfEdge` "owns" its start position. There is no competing code that
// could compute the surface position from slightly different data.
let [start, _] = boundary.inner;
self.path.point_from_path_coords(start)
}
}

View File

@ -65,7 +65,11 @@ impl Cycle {
let mut sum = Scalar::ZERO;
for (a, b) in self.half_edges().pairs() {
let [a, b] = [a, b].map(|half_edge| half_edge.start_position());
let [a, b] = [a, b].map(|half_edge| {
geometry
.of_half_edge(half_edge)
.start_position(half_edge.boundary())
});
sum += (b.u - a.u) * (b.v + a.v);
}

View File

@ -76,14 +76,4 @@ impl HalfEdge {
pub fn start_vertex(&self) -> &Handle<Vertex> {
&self.start_vertex
}
/// Compute the surface position where the half-edge starts
pub fn start_position(&self) -> Point<2> {
// Computing the surface position from the curve position is fine.
// `HalfEdge` "owns" its start position. There is no competing code that
// could compute the surface position from slightly different data.
let [start, _] = self.boundary.inner;
self.path.point_from_path_coords(start)
}
}

View File

@ -104,7 +104,16 @@ impl SplitFace for Shell {
// Build the edge that's going to divide the new faces.
let dividing_half_edge_a_to_d = {
let half_edge = HalfEdge::line_segment(
[b.start_position(), d.start_position()],
[
core.layers
.geometry
.of_half_edge(&b)
.start_position(b.boundary()),
core.layers
.geometry
.of_half_edge(&d)
.start_position(d.boundary()),
],
None,
core,
);

View File

@ -92,7 +92,9 @@ impl SolidValidationError {
})
.map(|(h, s)| {
(
s.point_from_surface_coords(h.start_position()),
s.point_from_surface_coords(
geometry.of_half_edge(&h).start_position(h.boundary()),
),
h.start_vertex().clone(),
)
})

View File

@ -52,7 +52,9 @@ impl ValidationCheck<Cycle> for AdjacentHalfEdgesNotConnected {
.path
.point_from_path_coords(end)
};
let start_pos_of_second_half_edge = second.start_position();
let start_pos_of_second_half_edge = geometry
.of_half_edge(second)
.start_position(second.boundary());
let distance_between_positions = (end_pos_of_first_half_edge
- start_pos_of_second_half_edge)