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

Remove FaceBuilder #864

Merged
merged 5 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 11 additions & 5 deletions crates/fj-kernel/src/algorithms/approx/faces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod tests {

use crate::{
local::Local,
objects::{Face, Surface},
objects::{Cycle, Face, Surface},
};

use super::{CycleApprox, FaceApprox, Tolerance};
Expand All @@ -106,10 +106,16 @@ mod tests {
let g = Point::from([2., 2.]);
let h = Point::from([1., 2.]);

let face = Face::builder(Surface::xy_plane())
.with_exterior_polygon([a, b, c, d])
.with_interior_polygon([e, f, g, h])
.build();
let surface = Surface::xy_plane();
let face = Face::new(surface)
.with_exteriors([Cycle::polygon_from_points(
&surface,
[a, b, c, d],
)])
.with_interiors([Cycle::polygon_from_points(
&surface,
[e, f, g, h],
)]);

let a = Local::new(a, a.to_xyz());
let b = Local::new(b, b.to_xyz());
Expand Down
10 changes: 5 additions & 5 deletions crates/fj-kernel/src/algorithms/intersection/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub type CurveFaceIntersection = [Scalar; 2];
mod tests {
use fj_math::{Line, Point, Vector};

use crate::objects::{Curve, Face, Surface};
use crate::objects::{Curve, Cycle, Face, Surface};

use super::CurveFaceIntersectionList;

Expand All @@ -210,10 +210,10 @@ mod tests {
[-1., 1.],
];

let face = Face::builder(Surface::xy_plane())
.with_exterior_polygon(exterior)
.with_interior_polygon(interior)
.build();
let surface = Surface::xy_plane();
let face = Face::new(surface)
.with_exteriors([Cycle::polygon_from_points(&surface, exterior)])
.with_interiors([Cycle::polygon_from_points(&surface, interior)]);

let expected =
CurveFaceIntersectionList::from_intervals([[1., 2.], [4., 5.]]);
Expand Down
20 changes: 13 additions & 7 deletions crates/fj-kernel/src/algorithms/reverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,25 @@ fn reverse_local_coordinates_in_cycle<'r>(
mod tests {
use pretty_assertions::assert_eq;

use crate::objects::{Face, Surface};
use crate::objects::{Cycle, Face, Surface};

#[test]
fn reverse_face() {
let original = Face::builder(Surface::xy_plane())
.with_exterior_polygon([[0., 0.], [1., 0.], [0., 1.]])
.build();
let surface = Surface::xy_plane();
let original =
Face::new(surface).with_exteriors([Cycle::polygon_from_points(
&surface,
[[0., 0.], [1., 0.], [0., 1.]],
)]);

let reversed = super::reverse_face(&original);

let expected = Face::builder(Surface::xy_plane().reverse())
.with_exterior_polygon([[0., 0.], [1., 0.], [0., -1.]])
.build();
let surface = Surface::xy_plane().reverse();
let expected =
Face::new(surface).with_exteriors([Cycle::polygon_from_points(
&surface,
[[0., 0.], [1., 0.], [0., -1.]],
)]);

assert_eq!(expected, reversed);
}
Expand Down
18 changes: 11 additions & 7 deletions crates/fj-kernel/src/algorithms/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ mod tests {
use crate::{
algorithms::Tolerance,
iter::ObjectIters,
objects::{Face, Sketch, Surface},
objects::{Cycle, Face, Sketch, Surface},
};

#[test]
Expand Down Expand Up @@ -294,9 +294,12 @@ mod tests {
) -> anyhow::Result<()> {
let tolerance = Tolerance::from_scalar(Scalar::ONE)?;

let face = Face::builder(Surface::xy_plane())
.with_exterior_polygon([[0., 0.], [1., 0.], [0., 1.]])
.build();
let surface = Surface::xy_plane();
let face =
Face::new(surface).with_exteriors([Cycle::polygon_from_points(
&surface,
[[0., 0.], [1., 0.], [0., 1.]],
)]);
let sketch = Sketch::from_faces([face]);

let solid =
Expand All @@ -310,9 +313,10 @@ mod tests {
let faces = expected_surfaces.into_iter().map(|surface| {
let surface = Surface::plane_from_points(surface);

Face::builder(surface)
.with_exterior_polygon(expected_vertices.clone())
.build()
Face::new(surface).with_exteriors([Cycle::polygon_from_points(
&surface,
expected_vertices.clone(),
)])
});

for face in faces {
Expand Down
34 changes: 23 additions & 11 deletions crates/fj-kernel/src/algorithms/triangulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mod tests {

use crate::{
algorithms::Tolerance,
objects::{Face, Surface},
objects::{Cycle, Face, Surface},
};

#[test]
Expand All @@ -77,9 +77,12 @@ mod tests {
let c = [2., 2.];
let d = [0., 1.];

let face = Face::builder(Surface::xy_plane())
.with_exterior_polygon([a, b, c, d])
.build();
let surface = Surface::xy_plane();
let face =
Face::new(surface).with_exteriors([Cycle::polygon_from_points(
&surface,
[a, b, c, d],
)]);

let a = Point::from(a).to_xyz();
let b = Point::from(b).to_xyz();
Expand Down Expand Up @@ -108,10 +111,16 @@ mod tests {
let g = [3., 3.];
let h = [1., 2.];

let face = Face::builder(Surface::xy_plane())
.with_exterior_polygon([a, b, c, d])
.with_interior_polygon([e, f, g, h])
.build();
let surface = Surface::xy_plane();
let face = Face::new(surface)
.with_exteriors([Cycle::polygon_from_points(
&surface,
[a, b, c, d],
)])
.with_interiors([Cycle::polygon_from_points(
&surface,
[e, f, g, h],
)]);

let triangles = triangulate(face)?;

Expand Down Expand Up @@ -158,9 +167,12 @@ mod tests {
let d = Point::from([0.1, 0.1]);
let e = Point::from([0., 0.8]);

let face = Face::builder(Surface::xy_plane())
.with_exterior_polygon([a, b, c, d, e])
.build();
let surface = Surface::xy_plane();
let face =
Face::new(surface).with_exteriors([Cycle::polygon_from_points(
&surface,
[a, b, c, d, e],
)]);

let triangles = triangulate(face)?;

Expand Down
83 changes: 0 additions & 83 deletions crates/fj-kernel/src/builder.rs

This file was deleted.

18 changes: 12 additions & 6 deletions crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,12 @@ mod tests {

#[test]
fn face() {
let object = Face::builder(Surface::xy_plane())
.with_exterior_polygon([[0., 0.], [1., 0.], [0., 1.]])
.build();
let surface = Surface::xy_plane();
let object =
Face::new(surface).with_exteriors([Cycle::polygon_from_points(
&surface,
[[0., 0.], [1., 0.], [0., 1.]],
)]);

assert_eq!(3, object.curve_iter().count());
assert_eq!(1, object.cycle_iter().count());
Expand Down Expand Up @@ -387,9 +390,12 @@ mod tests {

#[test]
fn sketch() {
let face = Face::builder(Surface::xy_plane())
.with_exterior_polygon([[0., 0.], [1., 0.], [0., 1.]])
.build();
let surface = Surface::xy_plane();
let face =
Face::new(surface).with_exteriors([Cycle::polygon_from_points(
&surface,
[[0., 0.], [1., 0.], [0., 1.]],
)]);
let object = Sketch::from_faces([face]);

assert_eq!(3, object.curve_iter().count());
Expand Down
1 change: 0 additions & 1 deletion crates/fj-kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
#![warn(missing_docs)]

pub mod algorithms;
pub mod builder;
pub mod iter;
pub mod local;
pub mod objects;
Expand Down
7 changes: 0 additions & 7 deletions crates/fj-kernel/src/objects/face.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use fj_interop::mesh::Color;
use fj_math::Triangle;

use crate::builder::FaceBuilder;

use super::{Cycle, Surface};

/// A face of a shape
Expand Down Expand Up @@ -34,11 +32,6 @@ impl Face {
}
}

/// Build a face using the [`FaceBuilder`] API
pub fn builder(surface: Surface) -> FaceBuilder {
FaceBuilder::new(surface)
}

/// Access this face's surface
pub fn surface(&self) -> &Surface {
&self.brep().surface
Expand Down
5 changes: 3 additions & 2 deletions crates/fj-kernel/src/objects/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::BTreeSet;

use fj_math::Scalar;

use crate::algorithms::TransformObject;
use crate::{algorithms::TransformObject, objects::Cycle};

use super::{Face, Surface};

Expand Down Expand Up @@ -49,7 +49,8 @@ impl Solid {
];

let faces = planes.map(|plane| {
Face::builder(plane).with_exterior_polygon(points).build()
Face::new(plane)
.with_exteriors([Cycle::polygon_from_points(&plane, points)])
});

Solid::from_faces(faces)
Expand Down
7 changes: 4 additions & 3 deletions crates/fj-operations/src/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ impl Shape for fj::Sketch {
let points =
poly_chain.to_points().into_iter().map(Point::from);

Face::builder(surface)
.with_exterior_polygon(points)
Face::new(surface)
.with_exteriors([Cycle::polygon_from_points(
&surface, points,
)])
.with_color(Color(self.color()))
.build()
}
};

Expand Down