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

Convert edge builder API into partial edge API #1135

Merged
merged 25 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4f2e39b
Move `builder::edge` to `partial`
hannobraun Sep 22, 2022
12e3453
Derive `Default` for `GlobalEdgeBuilder`
hannobraun Sep 22, 2022
238c24c
Split `GlobalEdgeBuilder` method
hannobraun Sep 22, 2022
1b649d4
Rename `GlobalEdgeBuilder` to `PartialGlobalEdge`
hannobraun Sep 22, 2022
bbcc1e8
Rename `GlobalEdge::builder`
hannobraun Sep 22, 2022
7db7209
Derive full set of traits for `PartialGlobalEdge`
hannobraun Sep 23, 2022
25d3f12
Add conversion to `PartialGlobalEdge`
hannobraun Sep 23, 2022
07016d2
Integrate `PartialGlobalEdge` into `partial` infra
hannobraun Sep 23, 2022
5310c1d
Update documentation of `PartialGlobalEdge`
hannobraun Sep 22, 2022
14381c0
Rename `HalfEdgeBuilder` to `PartialHalfEdge`
hannobraun Sep 22, 2022
ced8d37
Rename `HalfEdge::builder` to `HalfEdge::partial`
hannobraun Sep 22, 2022
6c2d6a5
Pass `Surface` only into the methods that need it
hannobraun Sep 23, 2022
a342528
Make vertices settable separately
hannobraun Sep 23, 2022
73bdcdb
Don't create duplicate vertices in `CycleBuilder`
hannobraun Sep 23, 2022
8a9952d
Simplify `PartialHalfEdge::as_circle_from_radius`
hannobraun Sep 23, 2022
10c1807
Consolidate redundant code
hannobraun Sep 23, 2022
a2aba5e
Simplify `PartialHalfEdge` method
hannobraun Sep 23, 2022
5ac6767
Make `PartialHalfEdge`'s `vertices` more flexible
hannobraun Sep 23, 2022
0481a4d
Make `PartialHalfEdge`'s `curve` more flexible
hannobraun Sep 23, 2022
38d41c6
Pass `&Stores` into `PartialHalfEdge::build`
hannobraun Sep 23, 2022
5c47e5d
Derive `Default` for `PartialHalfEdge`
hannobraun Sep 23, 2022
1b0badb
Derive full set of traits for `PartialHalfEdge`
hannobraun Sep 23, 2022
fcb9c63
Implement conversion to `PartialHalfEdge`
hannobraun Sep 23, 2022
42c12fa
Integrate `PartialHalfEdge` into `partial` infra
hannobraun Sep 23, 2022
7270df9
Update documentation of `PartialHalfEdge`
hannobraun Sep 23, 2022
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
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