Skip to content

Commit

Permalink
Merge pull request #1535 from hannobraun/edge
Browse files Browse the repository at this point in the history
Add `HalfEdge::start_vertex`, start using it
  • Loading branch information
hannobraun authored Jan 24, 2023
2 parents 71d16ce + ab6f537 commit 122a6f8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 36 deletions.
7 changes: 4 additions & 3 deletions crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
27 changes: 9 additions & 18 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Intersection between faces and points in 2D
use fj_interop::ext::ArrayExt;
use fj_math::Point;

use crate::{
Expand Down Expand Up @@ -49,17 +48,15 @@ impl Intersect for (&Handle<Face>, &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)
);
Expand Down Expand Up @@ -130,12 +127,11 @@ pub enum FacePointIntersection {
PointIsOnEdge(Handle<HalfEdge>),

/// The point is coincident with a vertex
PointIsOnVertex((Point<1>, Handle<SurfaceVertex>)),
PointIsOnVertex(Handle<SurfaceVertex>),
}

#[cfg(test)]
mod tests {
use fj_interop::ext::ArrayExt;
use fj_math::Point;
use pretty_assertions::assert_eq;

Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 5 additions & 11 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ pub enum RayFaceIntersection {
RayHitsEdge(Handle<HalfEdge>),

/// The ray hits a vertex
RayHitsVertex((Point<1>, Handle<SurfaceVertex>)),
RayHitsVertex(Handle<SurfaceVertex>),
}

#[cfg(test)]
mod tests {
use fj_interop::ext::ArrayExt;
use fj_math::Point;

use crate::{
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions crates/fj-kernel/src/objects/full/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions crates/fj-kernel/src/objects/full/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SurfaceVertex> {
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<SurfaceVertex>; 2] {
self.boundary
Expand Down

0 comments on commit 122a6f8

Please sign in to comment.