Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HalfEdge::start_vertex, start using it #1535

Merged
merged 6 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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