Skip to content

Commit

Permalink
Merge pull request #1135 from hannobraun/ready/partial-edge
Browse files Browse the repository at this point in the history
Convert edge build API into partial edge API
  • Loading branch information
hannobraun authored Sep 23, 2022
2 parents cc5b0e8 + 7270df9 commit dd66a76
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 282 deletions.
24 changes: 12 additions & 12 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ mod tests {
.with_surface(surface)
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[1., -1.], [1., 1.]])
.build();
let half_edge = HalfEdge::partial()
.as_line_segment_from_points(surface, [[1., -1.], [1., 1.]])
.build(&stores);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);

Expand All @@ -113,9 +113,9 @@ mod tests {
.with_surface(surface)
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[-1., -1.], [-1., 1.]])
.build();
let half_edge = HalfEdge::partial()
.as_line_segment_from_points(surface, [[-1., -1.], [-1., 1.]])
.build(&stores);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);

Expand All @@ -136,9 +136,9 @@ mod tests {
.with_surface(surface)
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[-1., -1.], [1., -1.]])
.build();
let half_edge = HalfEdge::partial()
.as_line_segment_from_points(surface, [[-1., -1.], [1., -1.]])
.build(&stores);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);

Expand All @@ -154,9 +154,9 @@ mod tests {
.with_surface(surface)
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[-1., 0.], [1., 0.]])
.build();
let half_edge = HalfEdge::partial()
.as_line_segment_from_points(surface, [[-1., 0.], [1., 0.]])
.build(&stores);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);

Expand Down
33 changes: 18 additions & 15 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,32 @@ mod tests {
fn sweep() {
let stores = Stores::new();

let half_edge = HalfEdge::builder(&stores, Surface::xy_plane())
.as_line_segment_from_points([[0., 0.], [1., 0.]])
.build();
let half_edge = HalfEdge::partial()
.as_line_segment_from_points(
Surface::xy_plane(),
[[0., 0.], [1., 0.]],
)
.build(&stores);

let face = (half_edge, Color::default()).sweep([0., 0., 1.], &stores);

let expected_face = {
let surface = Surface::xz_plane();

let bottom = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[0., 0.], [1., 0.]])
.build();
let top = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[0., 1.], [1., 1.]])
.build()
let bottom = HalfEdge::partial()
.as_line_segment_from_points(surface, [[0., 0.], [1., 0.]])
.build(&stores);
let top = HalfEdge::partial()
.as_line_segment_from_points(surface, [[0., 1.], [1., 1.]])
.build(&stores)
.reverse();
let left = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[0., 0.], [0., 1.]])
.build()
let left = HalfEdge::partial()
.as_line_segment_from_points(surface, [[0., 0.], [0., 1.]])
.build(&stores)
.reverse();
let right = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[1., 0.], [1., 1.]])
.build();
let right = HalfEdge::partial()
.as_line_segment_from_points(surface, [[1., 0.], [1., 1.]])
.build(&stores);

let cycle = Cycle::new(surface, [bottom, right, top, left]);

Expand Down
12 changes: 6 additions & 6 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ mod tests {
// https://doc.rust-lang.org/std/primitive.slice.html#method.array_windows
let [a, b] = [window[0], window[1]];

let half_edge = HalfEdge::builder(&stores, Surface::xy_plane())
.as_line_segment_from_points([a, b])
.build();
let half_edge = HalfEdge::partial()
.as_line_segment_from_points(Surface::xy_plane(), [a, b])
.build(&stores);
(half_edge, Color::default()).sweep(UP, &stores)
});

Expand Down Expand Up @@ -148,9 +148,9 @@ mod tests {
// https://doc.rust-lang.org/std/primitive.slice.html#method.array_windows
let [a, b] = [window[0], window[1]];

let half_edge = HalfEdge::builder(&stores, Surface::xy_plane())
.as_line_segment_from_points([a, b])
.build()
let half_edge = HalfEdge::partial()
.as_line_segment_from_points(Surface::xy_plane(), [a, b])
.build(&stores)
.reverse();
(half_edge, Color::default()).sweep(DOWN, &stores)
});
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ mod tests {

let half_edge = (vertex, surface).sweep([0., 0., 1.], &stores);

let expected_half_edge = HalfEdge::builder(&stores, surface)
.as_line_segment_from_points([[0., 0.], [0., 1.]])
.build();
let expected_half_edge = HalfEdge::partial()
.as_line_segment_from_points(surface, [[0., 0.], [0., 1.]])
.build(&stores);
assert_eq!(half_edge, expected_half_edge);
}

Expand Down
5 changes: 3 additions & 2 deletions crates/fj-kernel/src/algorithms/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ mod tests {
);
let vertices = [a, b];

let global_edge = GlobalEdge::builder()
.build_from_curve_and_vertices(&curve, &vertices);
let global_edge = GlobalEdge::partial()
.from_curve_and_vertices(&curve, &vertices)
.build(&stores);
let half_edge = HalfEdge::new(curve, vertices, global_edge);

let result =
Expand Down
72 changes: 54 additions & 18 deletions crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fj_math::Point;

use crate::{
objects::{Cycle, HalfEdge, Surface},
objects::{Curve, Cycle, HalfEdge, Surface, SurfaceVertex, Vertex},
stores::Stores,
};

Expand Down Expand Up @@ -34,28 +34,64 @@ impl<'a> CycleBuilder<'a> {
mut self,
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Self {
let points = self
let iter = self
.half_edges
.last()
.map(|half_edge| {
let [_, last] = half_edge.vertices();
last.surface_form().position()

let vertex = *last.surface_form();
let position = last.surface_form().position();

(position, Some(vertex))
})
.into_iter()
.chain(points.into_iter().map(Into::into))
.collect::<Vec<_>>();
.chain(points.into_iter().map(|point| (point.into(), None)));

for points in points.windows(2) {
// Can't panic, as we passed `2` to `windows`.
//
// Can be cleaned up, once `array_windows` is stable.
let points = [points[0], points[1]];
let mut previous: Option<(Point<2>, Option<SurfaceVertex>)> = None;

self.half_edges.push(
HalfEdge::builder(self.stores, self.surface)
.as_line_segment_from_points(points)
.build(),
);
for (position, vertex) in iter {
if let Some((previous_position, previous_vertex)) = previous {
let from = previous_vertex.unwrap_or_else(|| {
SurfaceVertex::partial()
.with_surface(self.surface)
.with_position(previous_position)
.build(self.stores)
});
let to = vertex.unwrap_or_else(|| {
SurfaceVertex::partial()
.with_surface(self.surface)
.with_position(position)
.build(self.stores)
});

previous = Some((position, Some(to)));

let curve = Curve::partial()
.with_surface(self.surface)
.as_line_from_points([previous_position, position])
.build(self.stores);

let [from, to] =
[(0., from), (1., to)].map(|(position, surface_form)| {
Vertex::partial()
.with_curve(curve.clone())
.with_position([position])
.with_surface_form(surface_form)
.build(self.stores)
});

self.half_edges.push(
HalfEdge::partial()
.with_curve(curve)
.with_vertices([from, to])
.build(self.stores),
);

continue;
}

previous = Some((position, vertex));
}

self
Expand All @@ -74,9 +110,9 @@ impl<'a> CycleBuilder<'a> {
let vertices =
[last, first].map(|vertex| vertex.surface_form().position());
self.half_edges.push(
HalfEdge::builder(self.stores, self.surface)
.as_line_segment_from_points(vertices)
.build(),
HalfEdge::partial()
.as_line_segment_from_points(self.surface, vertices)
.build(self.stores),
);
}

Expand Down
Loading

0 comments on commit dd66a76

Please sign in to comment.