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

Consolidate builder API for Face in FaceBuilder #1254

Merged
merged 10 commits into from
Oct 22, 2022
Prev Previous commit
Next Next commit
Simplify Face::builder
hannobraun committed Oct 22, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit bb9980f39f6d4ee0fa5494a38e1959d2ad968ba5
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
@@ -182,7 +182,8 @@ mod tests {
[ 1., -1.],
];

let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points(exterior)
.with_interior_polygon_from_points(interior)
.build();
6 changes: 4 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
@@ -79,7 +79,8 @@ mod tests {
];
let [a, b] = [objects.surfaces.xy_plane(), objects.surfaces.xz_plane()]
.map(|surface| {
Face::builder(&objects, surface)
Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points(points)
.build()
});
@@ -103,7 +104,8 @@ mod tests {
let surfaces =
[objects.surfaces.xy_plane(), objects.surfaces.xz_plane()];
let [a, b] = surfaces.clone().map(|surface| {
Face::builder(&objects, surface)
Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points(points)
.build()
});
24 changes: 16 additions & 8 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
@@ -145,7 +145,8 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([[0., 0.], [1., 1.], [0., 2.]])
.build();
let point = Point::from([2., 1.]);
@@ -159,7 +160,8 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([[0., 0.], [2., 1.], [0., 2.]])
.build();
let point = Point::from([1., 1.]);
@@ -176,7 +178,8 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([[4., 2.], [0., 4.], [0., 0.]])
.build();
let point = Point::from([1., 2.]);
@@ -193,7 +196,8 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([
[0., 0.],
[2., 1.],
@@ -215,7 +219,8 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([
[0., 0.],
[2., 1.],
@@ -237,7 +242,8 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([
[0., 0.],
[2., 1.],
@@ -260,7 +266,8 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([[0., 0.], [2., 0.], [0., 1.]])
.build();
let point = Point::from([1., 0.]);
@@ -286,7 +293,8 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]])
.build();
let point = Point::from([1., 0.]);
21 changes: 14 additions & 7 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
@@ -163,7 +163,8 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = objects.surfaces.yz_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
@@ -183,7 +184,8 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = objects.surfaces.yz_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
@@ -206,7 +208,8 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = objects.surfaces.yz_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
@@ -226,7 +229,8 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = objects.surfaces.yz_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
@@ -257,7 +261,8 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = objects.surfaces.yz_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
@@ -286,7 +291,8 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
@@ -308,7 +314,8 @@ mod tests {
let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([
[-1., -1.],
[1., -1.],
19 changes: 11 additions & 8 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
@@ -102,11 +102,13 @@ mod tests {
.build_polygon_from_points(TRIANGLE)
.sweep(UP, &objects);

let bottom = Face::builder(&objects, surface.clone())
let bottom = Face::builder(&objects)
.with_surface(surface.clone())
.with_exterior_polygon_from_points(TRIANGLE)
.build()
.reverse(&objects);
let top = Face::builder(&objects, surface.translate(UP, &objects))
let top = Face::builder(&objects)
.with_surface(surface.translate(UP, &objects))
.with_exterior_polygon_from_points(TRIANGLE)
.build();

@@ -134,12 +136,13 @@ mod tests {
.build_polygon_from_points(TRIANGLE)
.sweep(DOWN, &objects);

let bottom =
Face::builder(&objects, surface.clone().translate(DOWN, &objects))
.with_exterior_polygon_from_points(TRIANGLE)
.build()
.reverse(&objects);
let top = Face::builder(&objects, surface)
let bottom = Face::builder(&objects)
.with_surface(surface.clone().translate(DOWN, &objects))
.with_exterior_polygon_from_points(TRIANGLE)
.build()
.reverse(&objects);
let top = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points(TRIANGLE)
.build();

9 changes: 6 additions & 3 deletions crates/fj-kernel/src/algorithms/triangulate/mod.rs
Original file line number Diff line number Diff line change
@@ -99,7 +99,8 @@ mod tests {
let d = [0., 1.];

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([a, b, c, d])
.build();

@@ -133,7 +134,8 @@ mod tests {
let h = [3., 1.];

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface.clone())
let face = Face::builder(&objects)
.with_surface(surface.clone())
.with_exterior_polygon_from_points([a, b, c, d])
.with_interior_polygon_from_points([e, f, g, h])
.build();
@@ -193,7 +195,8 @@ mod tests {
let e = [0., 0.8];

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface.clone())
let face = Face::builder(&objects)
.with_surface(surface.clone())
.with_exterior_polygon_from_points([a, b, c, d, e])
.build();

3 changes: 2 additions & 1 deletion crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
@@ -39,7 +39,8 @@ impl<'a> ShellBuilder<'a> {
.xy_plane()
.translate([Z, Z, -h], self.objects);

Face::builder(self.objects, surface)
Face::builder(self.objects)
.with_surface(surface)
.with_exterior_polygon_from_points([
[-h, -h],
[h, -h],
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/builder/sketch.rs
Original file line number Diff line number Diff line change
@@ -22,7 +22,8 @@ impl<'a> SketchBuilder<'a> {
self,
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Sketch {
let face = Face::builder(self.objects, self.surface)
let face = Face::builder(self.objects)
.with_surface(self.surface)
.with_exterior_polygon_from_points(points)
.build();
Sketch::new().with_faces([face])
6 changes: 4 additions & 2 deletions crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
@@ -421,7 +421,8 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let object = Face::builder(&objects, surface)
let object = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]])
.build();

@@ -522,7 +523,8 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
let face = Face::builder(&objects)
.with_surface(surface)
.with_exterior_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]])
.build();
let object = Sketch::new().with_faces([face]);
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/objects/face.rs
Original file line number Diff line number Diff line change
@@ -41,10 +41,10 @@ pub struct Face {

impl Face {
/// Build a `Face` using [`FaceBuilder`]
pub fn builder(objects: &Objects, surface: Handle<Surface>) -> FaceBuilder {
pub fn builder(objects: &Objects) -> FaceBuilder {
FaceBuilder {
objects,
surface: Some(surface),
surface: None,
exterior: None,
interiors: Vec::new(),
}
3 changes: 2 additions & 1 deletion crates/fj-operations/src/sketch.rs
Original file line number Diff line number Diff line change
@@ -38,7 +38,8 @@ impl Shape for fj::Sketch {
let points =
poly_chain.to_points().into_iter().map(Point::from);

Face::builder(objects, surface)
Face::builder(objects)
.with_surface(surface)
.with_exterior_polygon_from_points(points)
.build()
.with_color(Color(self.color()))