Skip to content

Commit

Permalink
Merge pull request #1635 from hannobraun/inference
Browse files Browse the repository at this point in the history
Compute position of `HalfEdge`s start vertex
  • Loading branch information
hannobraun authored Mar 1, 2023
2 parents 0c6a689 + d7fe518 commit f6f85d4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Approx for (&Handle<HalfEdge>, &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]));
Expand Down
11 changes: 4 additions & 7 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 1 addition & 2 deletions crates/fj-kernel/src/objects/full/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions crates/fj-kernel/src/objects/full/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SurfaceVertex> {
&self.start_vertex
Expand Down

0 comments on commit f6f85d4

Please sign in to comment.