Skip to content

Commit

Permalink
Add HalfEdgeBuilder::as_line_segment_from_points
Browse files Browse the repository at this point in the history
Repalces `build_line_segment_from_points`.
  • Loading branch information
hannobraun committed Sep 21, 2022
1 parent 1c4abd1 commit 133575c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 28 deletions.
12 changes: 8 additions & 4 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ mod tests {
let surface = Surface::xy_plane();
let curve = Curve::builder(&stores, surface).build_u_axis();
let half_edge = HalfEdge::builder(&stores, surface)
.build_line_segment_from_points([[1., -1.], [1., 1.]]);
.as_line_segment_from_points([[1., -1.], [1., 1.]])
.build();

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

Expand All @@ -107,7 +108,8 @@ mod tests {
let surface = Surface::xy_plane();
let curve = Curve::builder(&stores, surface).build_u_axis();
let half_edge = HalfEdge::builder(&stores, surface)
.build_line_segment_from_points([[-1., -1.], [-1., 1.]]);
.as_line_segment_from_points([[-1., -1.], [-1., 1.]])
.build();

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

Expand All @@ -126,7 +128,8 @@ mod tests {
let surface = Surface::xy_plane();
let curve = Curve::builder(&stores, surface).build_u_axis();
let half_edge = HalfEdge::builder(&stores, surface)
.build_line_segment_from_points([[-1., -1.], [1., -1.]]);
.as_line_segment_from_points([[-1., -1.], [1., -1.]])
.build();

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

Expand All @@ -140,7 +143,8 @@ mod tests {
let surface = Surface::xy_plane();
let curve = Curve::builder(&stores, surface).build_u_axis();
let half_edge = HalfEdge::builder(&stores, surface)
.build_line_segment_from_points([[-1., 0.], [1., 0.]]);
.as_line_segment_from_points([[-1., 0.], [1., 0.]])
.build();

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

Expand Down
15 changes: 10 additions & 5 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,28 @@ mod tests {
let stores = Stores::new();

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

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)
.build_line_segment_from_points([[0., 0.], [1., 0.]]);
.as_line_segment_from_points([[0., 0.], [1., 0.]])
.build();
let top = HalfEdge::builder(&stores, surface)
.build_line_segment_from_points([[0., 1.], [1., 1.]])
.as_line_segment_from_points([[0., 1.], [1., 1.]])
.build()
.reverse();
let left = HalfEdge::builder(&stores, surface)
.build_line_segment_from_points([[0., 0.], [0., 1.]])
.as_line_segment_from_points([[0., 0.], [0., 1.]])
.build()
.reverse();
let right = HalfEdge::builder(&stores, surface)
.build_line_segment_from_points([[1., 0.], [1., 1.]]);
.as_line_segment_from_points([[1., 0.], [1., 1.]])
.build();

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

Expand Down
6 changes: 4 additions & 2 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ mod tests {
let [a, b] = [window[0], window[1]];

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

Expand Down Expand Up @@ -148,7 +149,8 @@ mod tests {
let [a, b] = [window[0], window[1]];

let half_edge = HalfEdge::builder(&stores, Surface::xy_plane())
.build_line_segment_from_points([a, b])
.as_line_segment_from_points([a, b])
.build()
.reverse();
(half_edge, Color::default()).sweep(DOWN, &stores)
});
Expand Down
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ mod tests {
let half_edge = (vertex, surface).sweep([0., 0., 1.], &stores);

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

Expand Down
6 changes: 4 additions & 2 deletions crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ impl<'a> CycleBuilder<'a> {

self.half_edges.push(
HalfEdge::builder(self.stores, self.surface)
.build_line_segment_from_points(points),
.as_line_segment_from_points(points)
.build(),
);
}

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

Expand Down
24 changes: 11 additions & 13 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ impl<'a> HalfEdgeBuilder<'a> {
self
}

/// Finish building the [`HalfEdge`] as a line segment from the given points
pub fn build_line_segment_from_points(
self,
/// Build the [`HalfEdge`] as a line segment from the given points
pub fn as_line_segment_from_points(
mut self,
points: [impl Into<Point<2>>; 2],
) -> HalfEdge {
) -> Self {
let points = points.map(Into::into);

let global_vertices = points.map(|position| {
Expand All @@ -118,7 +118,7 @@ impl<'a> HalfEdgeBuilder<'a> {
)
};

let curve = self.curve.unwrap_or_else(|| {
let curve = {
let path = SurfacePath::Line(Line::from_points(points));
let global_form = {
let points = global_vertices
Expand All @@ -129,9 +129,9 @@ impl<'a> HalfEdgeBuilder<'a> {
};

Curve::new(self.surface, path, global_form)
});
};

let vertices = self.vertices.unwrap_or_else(|| {
let vertices = {
let [a_global, b_global] = global_vertices;
let [a_surface, b_surface] = surface_vertices;

Expand All @@ -149,14 +149,12 @@ impl<'a> HalfEdgeBuilder<'a> {
b_global,
),
]
});
};

let global_form = self.global_form.unwrap_or_else(|| {
GlobalEdge::builder()
.build_from_curve_and_vertices(&curve, &vertices)
});
self.curve = Some(curve);
self.vertices = Some(vertices);

HalfEdge::new(curve, vertices, global_form)
self
}

/// Finish building the [`HalfEdge`]
Expand Down
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ mod tests {
let stores = Stores::new();

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

assert_eq!(1, object.curve_iter().count());
assert_eq!(0, object.cycle_iter().count());
Expand Down

0 comments on commit 133575c

Please sign in to comment.