diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index a3542dbb4..95bc0f724 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -30,7 +30,7 @@ impl Approx for (&Handle, &Surface) { let range = RangeOnPath { boundary }; let first = ApproxPoint::new( - half_edge.start_vertex().position(), + half_edge.start_position(), half_edge.start_vertex().global_form().position(), ) .with_source((half_edge.clone(), half_edge.boundary()[0])); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 1f13c0a8e..6d6924570 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -318,10 +318,7 @@ mod tests { let edge = face .exterior() .half_edges() - .find(|edge| { - let vertex = edge.start_vertex(); - vertex.position() == Point::from([0., 0.]) - }) + .find(|edge| edge.start_position() == Point::from([0., 0.])) .unwrap(); assert_eq!( intersection, @@ -352,10 +349,10 @@ mod tests { let vertex = face .exterior() .half_edges() - .map(|half_edge| half_edge.start_vertex().clone()) - .find(|surface_vertex| { - surface_vertex.position() == Point::from([1., 0.]) + .find(|half_edge| { + half_edge.start_position() == Point::from([1., 0.]) }) + .map(|half_edge| half_edge.start_vertex().clone()) .unwrap(); assert_eq!( intersection, diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index df4937d90..f117e480f 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -256,10 +256,7 @@ mod tests { let edge = face .exterior() .half_edges() - .find(|edge| { - let vertex = edge.start_vertex(); - vertex.position() == Point::from([-1., 1.]) - }) + .find(|edge| edge.start_position() == Point::from([-1., 1.])) .unwrap(); assert_eq!( (&ray, &face).intersect(), @@ -291,10 +288,10 @@ mod tests { let vertex = face .exterior() .half_edges() - .map(|half_edge| half_edge.start_vertex().clone()) - .find(|surface_vertex| { - surface_vertex.position() == Point::from([-1., -1.]) + .find(|half_edge| { + half_edge.start_position() == Point::from([-1., -1.]) }) + .map(|half_edge| half_edge.start_vertex().clone()) .unwrap(); assert_eq!( (&ray, &face).intersect(), diff --git a/crates/fj-kernel/src/objects/full/cycle.rs b/crates/fj-kernel/src/objects/full/cycle.rs index be42f3fda..dd2abbb35 100644 --- a/crates/fj-kernel/src/objects/full/cycle.rs +++ b/crates/fj-kernel/src/objects/full/cycle.rs @@ -77,8 +77,7 @@ impl Cycle { let mut sum = Scalar::ZERO; for [a, b] in self.half_edges.as_slice().array_windows_ext() { - let [a, b] = - [a, b].map(|half_edge| half_edge.start_vertex().position()); + let [a, b] = [a, b].map(|half_edge| half_edge.start_position()); sum += (b.u - a.u) * (b.v + a.v); } diff --git a/crates/fj-kernel/src/objects/full/edge.rs b/crates/fj-kernel/src/objects/full/edge.rs index f0a0a4915..a40b1b193 100644 --- a/crates/fj-kernel/src/objects/full/edge.rs +++ b/crates/fj-kernel/src/objects/full/edge.rs @@ -79,6 +79,16 @@ impl HalfEdge { self.boundary } + /// 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; + self.curve.point_from_path_coords(start) + } + /// Access the vertex from where this half-edge starts pub fn start_vertex(&self) -> &Handle { &self.start_vertex