diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 27ee3c0e3..58f6204a2 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -25,9 +25,10 @@ impl Approx for &HalfEdge { let boundary = self.boundary(); let range = RangeOnPath { boundary }; - let [first, _] = self.surface_vertices(); - let first = - ApproxPoint::new(first.position(), first.global_form().position()); + let first = ApproxPoint::new( + self.start_vertex().position(), + self.start_vertex().global_form().position(), + ); let curve_approx = (self.curve(), range).approx_with_cache(tolerance, cache); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 730162d1f..1e018e9df 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -1,6 +1,5 @@ //! Intersection between faces and points in 2D -use fj_interop::ext::ArrayExt; use fj_math::Point; use crate::{ @@ -49,17 +48,15 @@ impl Intersect for (&Handle, &Point<2>) { )); } (Some(RaySegmentIntersection::RayStartsOnOnFirstVertex), _) => { - let [vertex, _] = half_edge.boundary().zip_ext( - half_edge.surface_vertices().map(Clone::clone) - ); + let [vertex, _] = + half_edge.surface_vertices().map(Clone::clone); return Some( FacePointIntersection::PointIsOnVertex(vertex) ); } (Some(RaySegmentIntersection::RayStartsOnSecondVertex), _) => { - let [_, vertex] = half_edge.boundary().zip_ext( - half_edge.surface_vertices().map(Clone::clone) - ); + let [_, vertex] = + half_edge.surface_vertices().map(Clone::clone); return Some( FacePointIntersection::PointIsOnVertex(vertex) ); @@ -130,12 +127,11 @@ pub enum FacePointIntersection { PointIsOnEdge(Handle), /// The point is coincident with a vertex - PointIsOnVertex((Point<1>, Handle)), + PointIsOnVertex(Handle), } #[cfg(test)] mod tests { - use fj_interop::ext::ArrayExt; use fj_math::Point; use pretty_assertions::assert_eq; @@ -315,9 +311,8 @@ mod tests { .exterior() .half_edges() .find(|edge| { - let [a, b] = edge.surface_vertices(); - a.position() == Point::from([0., 0.]) - && b.position() == Point::from([2., 0.]) + let vertex = edge.start_vertex(); + vertex.position() == Point::from([0., 0.]) }) .unwrap(); assert_eq!( @@ -348,12 +343,8 @@ mod tests { let vertex = face .exterior() .half_edges() - .flat_map(|half_edge| { - half_edge - .boundary() - .zip_ext(half_edge.surface_vertices().map(Clone::clone)) - }) - .find(|(_, surface_vertex)| { + .map(|half_edge| half_edge.start_vertex().clone()) + .find(|surface_vertex| { surface_vertex.position() == Point::from([1., 0.]) }) .unwrap(); diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index de54e5cc4..336ffb5be 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -136,12 +136,11 @@ pub enum RayFaceIntersection { RayHitsEdge(Handle), /// The ray hits a vertex - RayHitsVertex((Point<1>, Handle)), + RayHitsVertex(Handle), } #[cfg(test)] mod tests { - use fj_interop::ext::ArrayExt; use fj_math::Point; use crate::{ @@ -254,9 +253,8 @@ mod tests { .exterior() .half_edges() .find(|edge| { - let [a, b] = edge.surface_vertices(); - a.position() == Point::from([-1., 1.]) - && b.position() == Point::from([-1., -1.]) + let vertex = edge.start_vertex(); + vertex.position() == Point::from([-1., 1.]) }) .unwrap(); assert_eq!( @@ -288,12 +286,8 @@ mod tests { let vertex = face .exterior() .half_edges() - .flat_map(|half_edge| { - half_edge - .boundary() - .zip_ext(half_edge.surface_vertices().map(Clone::clone)) - }) - .find(|(_, surface_vertex)| { + .map(|half_edge| half_edge.start_vertex().clone()) + .find(|surface_vertex| { surface_vertex.position() == Point::from([-1., -1.]) }) .unwrap(); diff --git a/crates/fj-kernel/src/objects/full/cycle.rs b/crates/fj-kernel/src/objects/full/cycle.rs index dc9f8b192..2a829a8a5 100644 --- a/crates/fj-kernel/src/objects/full/cycle.rs +++ b/crates/fj-kernel/src/objects/full/cycle.rs @@ -92,10 +92,8 @@ 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| { - let [surface_vertex, _] = half_edge.surface_vertices(); - surface_vertex.position() - }); + let [a, b] = + [a, b].map(|half_edge| half_edge.start_vertex().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 95f678b35..390ec41e3 100644 --- a/crates/fj-kernel/src/objects/full/edge.rs +++ b/crates/fj-kernel/src/objects/full/edge.rs @@ -40,6 +40,13 @@ impl HalfEdge { self.boundary.each_ref_ext().map(|&(point, _)| point) } + /// Access the vertex from where this half-edge starts + pub fn start_vertex(&self) -> &Handle { + let [vertex, _] = + self.boundary.each_ref_ext().map(|(_, vertex)| vertex); + vertex + } + /// Access the surface vertices that bound the half-edge pub fn surface_vertices(&self) -> [&Handle; 2] { self.boundary