Skip to content

Commit

Permalink
Merge pull request #1124 from hannobraun/builder
Browse files Browse the repository at this point in the history
Clean up `FaceBuilder` API
  • Loading branch information
hannobraun authored Sep 21, 2022
2 parents d5c7fae + ba0bc7d commit bfb4b97
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 128 deletions.
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ mod tests {
];

let face = Face::builder(&stores, surface)
.build_polygon_from_points(exterior)
.with_hole(interior)
.into_face();
.with_exterior_polygon_from_points(exterior)
.with_interior_polygon_from_points(interior)
.build();

let expected =
CurveFaceIntersection::from_intervals([[[1.], [2.]], [[4.], [5.]]]);
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ mod tests {
let surfaces = [Surface::xy_plane(), Surface::xz_plane()];
let [a, b] = surfaces.map(|surface| {
Face::builder(&stores, surface)
.build_polygon_from_points(points)
.into_face()
.with_exterior_polygon_from_points(points)
.build()
});

let intersection = FaceFaceIntersection::compute([&a, &b], &stores);
Expand All @@ -107,8 +107,8 @@ mod tests {
let surfaces = [Surface::xy_plane(), Surface::xz_plane()];
let [a, b] = surfaces.map(|surface| {
Face::builder(&stores, surface)
.build_polygon_from_points(points)
.into_face()
.with_exterior_polygon_from_points(points)
.build()
});

let intersection = FaceFaceIntersection::compute([&a, &b], &stores);
Expand Down
42 changes: 26 additions & 16 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ mod tests {
let stores = Stores::new();

let face = Face::builder(&stores, Surface::xy_plane())
.build_polygon_from_points([[0., 0.], [1., 1.], [0., 2.]])
.into_face();
.with_exterior_polygon_from_points([[0., 0.], [1., 1.], [0., 2.]])
.build();
let point = Point::from([2., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -156,8 +156,8 @@ mod tests {
let stores = Stores::new();

let face = Face::builder(&stores, Surface::xy_plane())
.build_polygon_from_points([[0., 0.], [2., 1.], [0., 2.]])
.into_face();
.with_exterior_polygon_from_points([[0., 0.], [2., 1.], [0., 2.]])
.build();
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -172,8 +172,8 @@ mod tests {
let stores = Stores::new();

let face = Face::builder(&stores, Surface::xy_plane())
.build_polygon_from_points([[4., 2.], [0., 4.], [0., 0.]])
.into_face();
.with_exterior_polygon_from_points([[4., 2.], [0., 4.], [0., 0.]])
.build();
let point = Point::from([1., 2.]);

let intersection = (&face, &point).intersect();
Expand All @@ -188,8 +188,13 @@ mod tests {
let stores = Stores::new();

let face = Face::builder(&stores, Surface::xy_plane())
.build_polygon_from_points([[0., 0.], [2., 1.], [3., 0.], [3., 4.]])
.into_face();
.with_exterior_polygon_from_points([
[0., 0.],
[2., 1.],
[3., 0.],
[3., 4.],
])
.build();
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -204,8 +209,13 @@ mod tests {
let stores = Stores::new();

let face = Face::builder(&stores, Surface::xy_plane())
.build_polygon_from_points([[0., 0.], [2., 1.], [3., 1.], [0., 2.]])
.into_face();
.with_exterior_polygon_from_points([
[0., 0.],
[2., 1.],
[3., 1.],
[0., 2.],
])
.build();
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -220,14 +230,14 @@ mod tests {
let stores = Stores::new();

let face = Face::builder(&stores, Surface::xy_plane())
.build_polygon_from_points([
.with_exterior_polygon_from_points([
[0., 0.],
[2., 1.],
[3., 1.],
[4., 0.],
[4., 5.],
])
.into_face();
.build();
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -242,8 +252,8 @@ mod tests {
let stores = Stores::new();

let face = Face::builder(&stores, Surface::xy_plane())
.build_polygon_from_points([[0., 0.], [2., 0.], [0., 1.]])
.into_face();
.with_exterior_polygon_from_points([[0., 0.], [2., 0.], [0., 1.]])
.build();
let point = Point::from([1., 0.]);

let intersection = (&face, &point).intersect();
Expand All @@ -267,8 +277,8 @@ mod tests {
let stores = Stores::new();

let face = Face::builder(&stores, Surface::xy_plane())
.build_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]])
.into_face();
.with_exterior_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]])
.build();
let point = Point::from([1., 0.]);

let intersection = (&face, &point).intersect();
Expand Down
28 changes: 14 additions & 14 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let face = Face::builder(&stores, Surface::yz_plane())
.build_polygon_from_points([
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
])
.into_face()
.build()
.translate([-1., 0., 0.], &stores);

assert_eq!((&ray, &face).intersect(), None);
Expand All @@ -188,13 +188,13 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let face = Face::builder(&stores, Surface::yz_plane())
.build_polygon_from_points([
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
])
.into_face()
.build()
.translate([1., 0., 0.], &stores);

assert_eq!(
Expand All @@ -210,13 +210,13 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let face = Face::builder(&stores, Surface::yz_plane())
.build_polygon_from_points([
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
])
.into_face()
.build()
.translate([0., 0., 2.], &stores);

assert_eq!((&ray, &face).intersect(), None);
Expand All @@ -229,13 +229,13 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let face = Face::builder(&stores, Surface::yz_plane())
.build_polygon_from_points([
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
])
.into_face()
.build()
.translate([1., 1., 0.], &stores);

let edge = face
Expand All @@ -259,13 +259,13 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let face = Face::builder(&stores, Surface::yz_plane())
.build_polygon_from_points([
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
])
.into_face()
.build()
.translate([1., 1., 1.], &stores);

let vertex = face
Expand All @@ -287,13 +287,13 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let face = Face::builder(&stores, Surface::xy_plane())
.build_polygon_from_points([
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
])
.into_face();
.build();

assert_eq!(
(&ray, &face).intersect(),
Expand All @@ -308,13 +308,13 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let face = Face::builder(&stores, Surface::xy_plane())
.build_polygon_from_points([
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
])
.into_face()
.build()
.translate([0., 0., 1.], &stores);

assert_eq!((&ray, &face).intersect(), None)
Expand Down
13 changes: 6 additions & 7 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,17 @@ mod tests {

let expected_face = {
let surface = Surface::xz_plane();
let builder = HalfEdge::builder(&stores, surface);

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

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

Expand Down
16 changes: 8 additions & 8 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ mod tests {
.sweep(UP, &stores);

let bottom = Face::builder(&stores, surface)
.build_polygon_from_points(TRIANGLE)
.into_face()
.with_exterior_polygon_from_points(TRIANGLE)
.build()
.reverse();
let top = Face::builder(&stores, surface.translate(UP, &stores))
.build_polygon_from_points(TRIANGLE)
.into_face();
.with_exterior_polygon_from_points(TRIANGLE)
.build();

assert!(solid.find_face(&bottom).is_some());
assert!(solid.find_face(&top).is_some());
Expand Down Expand Up @@ -130,12 +130,12 @@ mod tests {
.sweep(DOWN, &stores);

let bottom = Face::builder(&stores, surface.translate(DOWN, &stores))
.build_polygon_from_points(TRIANGLE)
.into_face()
.with_exterior_polygon_from_points(TRIANGLE)
.build()
.reverse();
let top = Face::builder(&stores, surface)
.build_polygon_from_points(TRIANGLE)
.into_face();
.with_exterior_polygon_from_points(TRIANGLE)
.build();

assert!(solid.find_face(&bottom).is_some());
assert!(solid.find_face(&top).is_some());
Expand Down
14 changes: 7 additions & 7 deletions crates/fj-kernel/src/algorithms/triangulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ mod tests {

let surface = Surface::xy_plane();
let face = Face::builder(&stores, surface)
.build_polygon_from_points([a, b, c, d])
.into_face();
.with_exterior_polygon_from_points([a, b, c, d])
.build();

let a = Point::from(a).to_xyz();
let b = Point::from(b).to_xyz();
Expand Down Expand Up @@ -135,9 +135,9 @@ mod tests {

let surface = Surface::xy_plane();
let face = Face::builder(&stores, surface)
.build_polygon_from_points([a, b, c, d])
.with_hole([e, f, g, h])
.into_face();
.with_exterior_polygon_from_points([a, b, c, d])
.with_interior_polygon_from_points([e, f, g, h])
.build();

let triangles = triangulate(face)?;

Expand Down Expand Up @@ -188,8 +188,8 @@ mod tests {

let surface = Surface::xy_plane();
let face = Face::builder(&stores, surface)
.build_polygon_from_points([a, b, c, d, e])
.into_face();
.with_exterior_polygon_from_points([a, b, c, d, e])
.build();

let triangles = triangulate(face)?;

Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/builder/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ pub struct CurveBuilder<'a> {

impl<'a> CurveBuilder<'a> {
/// Build a line that represents the u-axis on the surface
pub fn build_u_axis(&self) -> Curve {
pub fn build_u_axis(self) -> Curve {
let a = Point::origin();
let b = a + Vector::unit_u();

self.build_line_from_points([a, b])
}

/// Build a line that represents the v-axis on the surface
pub fn build_v_axis(&self) -> Curve {
pub fn build_v_axis(self) -> Curve {
let a = Point::origin();
let b = a + Vector::unit_v();

self.build_line_from_points([a, b])
}

/// Build a circle from the given radius
pub fn build_circle_from_radius(&self, radius: impl Into<Scalar>) -> Curve {
pub fn build_circle_from_radius(self, radius: impl Into<Scalar>) -> Curve {
let radius = radius.into();

let path = SurfacePath::circle_from_radius(radius);
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct CycleBuilder<'a> {
impl<'a> CycleBuilder<'a> {
/// Create a polygon from a list of points
pub fn build_polygon_from_points(
&self,
self,
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Cycle {
let mut points: Vec<_> = points.into_iter().map(Into::into).collect();
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct HalfEdgeBuilder<'a> {
impl<'a> HalfEdgeBuilder<'a> {
/// Build a circle from the given radius
pub fn build_circle_from_radius(
&self,
self,
radius: impl Into<Scalar>,
) -> HalfEdge {
let curve = Curve::builder(self.stores, self.surface)
Expand Down Expand Up @@ -62,7 +62,7 @@ impl<'a> HalfEdgeBuilder<'a> {

/// Build a line segment from two points
pub fn build_line_segment_from_points(
&self,
self,
points: [impl Into<Point<2>>; 2],
) -> HalfEdge {
let points = points.map(Into::into);
Expand Down
Loading

0 comments on commit bfb4b97

Please sign in to comment.