Skip to content

Commit

Permalink
Remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Sep 21, 2022
1 parent 5e526a7 commit ba0bc7d
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 101 deletions.
3 changes: 1 addition & 2 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ mod tests {
let face = Face::builder(&stores, surface)
.with_exterior_polygon_from_points(exterior)
.with_interior_polygon_from_points(interior)
.build()
.into_face();
.build();

let expected =
CurveFaceIntersection::from_intervals([[[1.], [2.]], [[4.], [5.]]]);
Expand Down
2 changes: 0 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ mod tests {
Face::builder(&stores, surface)
.with_exterior_polygon_from_points(points)
.build()
.into_face()
});

let intersection = FaceFaceIntersection::compute([&a, &b], &stores);
Expand All @@ -110,7 +109,6 @@ mod tests {
Face::builder(&stores, surface)
.with_exterior_polygon_from_points(points)
.build()
.into_face()
});

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

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

let intersection = (&face, &point).intersect();
Expand All @@ -158,8 +157,7 @@ mod tests {

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

let intersection = (&face, &point).intersect();
Expand All @@ -175,8 +173,7 @@ mod tests {

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

let intersection = (&face, &point).intersect();
Expand All @@ -197,8 +194,7 @@ mod tests {
[3., 0.],
[3., 4.],
])
.build()
.into_face();
.build();
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -219,8 +215,7 @@ mod tests {
[3., 1.],
[0., 2.],
])
.build()
.into_face();
.build();
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -242,8 +237,7 @@ mod tests {
[4., 0.],
[4., 5.],
])
.build()
.into_face();
.build();
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -259,8 +253,7 @@ mod tests {

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

let intersection = (&face, &point).intersect();
Expand All @@ -285,8 +278,7 @@ mod tests {

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

let intersection = (&face, &point).intersect();
Expand Down
9 changes: 1 addition & 8 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ mod tests {
[-1., 1.],
])
.build()
.into_face()
.translate([-1., 0., 0.], &stores);

assert_eq!((&ray, &face).intersect(), None);
Expand All @@ -196,7 +195,6 @@ mod tests {
[-1., 1.],
])
.build()
.into_face()
.translate([1., 0., 0.], &stores);

assert_eq!(
Expand All @@ -219,7 +217,6 @@ mod tests {
[-1., 1.],
])
.build()
.into_face()
.translate([0., 0., 2.], &stores);

assert_eq!((&ray, &face).intersect(), None);
Expand All @@ -239,7 +236,6 @@ mod tests {
[-1., 1.],
])
.build()
.into_face()
.translate([1., 1., 0.], &stores);

let edge = face
Expand Down Expand Up @@ -270,7 +266,6 @@ mod tests {
[-1., 1.],
])
.build()
.into_face()
.translate([1., 1., 1.], &stores);

let vertex = face
Expand Down Expand Up @@ -298,8 +293,7 @@ mod tests {
[1., 1.],
[-1., 1.],
])
.build()
.into_face();
.build();

assert_eq!(
(&ray, &face).intersect(),
Expand All @@ -321,7 +315,6 @@ mod tests {
[-1., 1.],
])
.build()
.into_face()
.translate([0., 0., 1.], &stores);

assert_eq!((&ray, &face).intersect(), None)
Expand Down
8 changes: 2 additions & 6 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ mod tests {
let bottom = Face::builder(&stores, surface)
.with_exterior_polygon_from_points(TRIANGLE)
.build()
.into_face()
.reverse();
let top = Face::builder(&stores, surface.translate(UP, &stores))
.with_exterior_polygon_from_points(TRIANGLE)
.build()
.into_face();
.build();

assert!(solid.find_face(&bottom).is_some());
assert!(solid.find_face(&top).is_some());
Expand Down Expand Up @@ -134,12 +132,10 @@ mod tests {
let bottom = Face::builder(&stores, surface.translate(DOWN, &stores))
.with_exterior_polygon_from_points(TRIANGLE)
.build()
.into_face()
.reverse();
let top = Face::builder(&stores, surface)
.with_exterior_polygon_from_points(TRIANGLE)
.build()
.into_face();
.build();

assert!(solid.find_face(&bottom).is_some());
assert!(solid.find_face(&top).is_some());
Expand Down
9 changes: 3 additions & 6 deletions crates/fj-kernel/src/algorithms/triangulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ mod tests {
let surface = Surface::xy_plane();
let face = Face::builder(&stores, surface)
.with_exterior_polygon_from_points([a, b, c, d])
.build()
.into_face();
.build();

let a = Point::from(a).to_xyz();
let b = Point::from(b).to_xyz();
Expand Down Expand Up @@ -138,8 +137,7 @@ mod tests {
let face = Face::builder(&stores, surface)
.with_exterior_polygon_from_points([a, b, c, d])
.with_interior_polygon_from_points([e, f, g, h])
.build()
.into_face();
.build();

let triangles = triangulate(face)?;

Expand Down Expand Up @@ -191,8 +189,7 @@ mod tests {
let surface = Surface::xy_plane();
let face = Face::builder(&stores, surface)
.with_exterior_polygon_from_points([a, b, c, d, e])
.build()
.into_face();
.build();

let triangles = triangulate(face)?;

Expand Down
54 changes: 2 additions & 52 deletions crates/fj-kernel/src/builder/face.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::ops::Deref;

use fj_math::Point;

use crate::{
Expand Down Expand Up @@ -53,58 +51,10 @@ impl<'a> FaceBuilder<'a> {
}

/// Construct a polygon from a list of points
pub fn build(self) -> FacePolygon<'a> {
pub fn build(self) -> Face {
let exterior = self
.exterior
.expect("Can't build `Face` without exterior cycle");
let face =
Face::new(self.surface, exterior).with_interiors(self.interiors);

FacePolygon {
stores: self.stores,
face,
}
}
}

/// A polygon
#[derive(Clone, Debug)]
pub struct FacePolygon<'a> {
stores: &'a Stores,
face: Face,
}

impl FacePolygon<'_> {
/// Add a hole to the polygon
pub fn with_hole(
mut self,
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Self {
let surface = *self.face.surface();
self.face =
self.face
.with_interiors([Cycle::builder(self.stores, surface)
.build_polygon_from_points(points)]);

self
}

/// Consume the `Polygon` and return the [`Face`] it wraps
pub fn into_face(self) -> Face {
self.face
}
}

impl From<FacePolygon<'_>> for Face {
fn from(polygon: FacePolygon) -> Self {
polygon.into_face()
}
}

impl Deref for FacePolygon<'_> {
type Target = Face;

fn deref(&self) -> &Self::Target {
&self.face
Face::new(self.surface, exterior).with_interiors(self.interiors)
}
}
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub use self::{
curve::{CurveBuilder, GlobalCurveBuilder},
cycle::CycleBuilder,
edge::HalfEdgeBuilder,
face::{FaceBuilder, FacePolygon},
face::FaceBuilder,
shell::ShellBuilder,
sketch::SketchBuilder,
solid::SolidBuilder,
Expand Down
1 change: 0 additions & 1 deletion crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ impl<'a> ShellBuilder<'a> {
Face::builder(self.stores, plane)
.with_exterior_polygon_from_points(points)
.build()
.into_face()
});

Shell::new().with_faces(faces)
Expand Down
3 changes: 1 addition & 2 deletions crates/fj-kernel/src/builder/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ impl<'a> SketchBuilder<'a> {
) -> Sketch {
let face = Face::builder(self.stores, self.surface)
.with_exterior_polygon_from_points(points)
.build()
.into_face();
.build();
Sketch::new().with_faces([face])
}
}
6 changes: 2 additions & 4 deletions crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ mod tests {
let surface = Surface::xy_plane();
let object = Face::builder(&stores, surface)
.with_exterior_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]])
.build()
.into_face();
.build();

assert_eq!(3, object.curve_iter().count());
assert_eq!(1, object.cycle_iter().count());
Expand Down Expand Up @@ -502,8 +501,7 @@ mod tests {
let surface = Surface::xy_plane();
let face = Face::builder(&stores, surface)
.with_exterior_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]])
.build()
.into_face();
.build();
let object = Sketch::new().with_faces([face]);

assert_eq!(3, object.curve_iter().count());
Expand Down
1 change: 0 additions & 1 deletion crates/fj-operations/src/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl Shape for fj::Sketch {
Face::builder(stores, surface)
.with_exterior_polygon_from_points(points)
.build()
.into_face()
.with_color(Color(self.color()))
}
};
Expand Down

0 comments on commit ba0bc7d

Please sign in to comment.