Skip to content

Commit

Permalink
Merge pull request #1693 from hannobraun/builder
Browse files Browse the repository at this point in the history
Add `FaceBuilder`
  • Loading branch information
hannobraun authored Mar 17, 2023
2 parents ab50bca + 6e4db50 commit 3fc8188
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 198 deletions.
19 changes: 7 additions & 12 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ where
#[cfg(test)]
mod tests {
use crate::{
builder::CycleBuilder, geometry::curve::Curve, insert::Insert,
objects::Face, services::Services,
builder::{CycleBuilder, FaceBuilder},
geometry::curve::Curve,
services::Services,
};

use super::CurveFaceIntersection;
Expand All @@ -177,16 +178,10 @@ mod tests {
[ 1., -1.],
];

let face = Face::new(
services.objects.surfaces.xy_plane(),
CycleBuilder::polygon(exterior_points)
.build(&mut services.objects)
.insert(&mut services.objects),
vec![CycleBuilder::polygon(interior_points)
.build(&mut services.objects)
.insert(&mut services.objects)],
None,
);
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(exterior_points))
.with_interior(CycleBuilder::polygon(interior_points))
.build(&mut services.objects);

let expected =
CurveFaceIntersection::from_intervals([[[1.], [2.]], [[4.], [5.]]]);
Expand Down
27 changes: 9 additions & 18 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ mod tests {
use pretty_assertions::assert_eq;

use crate::{
algorithms::intersect::CurveFaceIntersection, builder::CycleBuilder,
geometry::curve::Curve, insert::Insert, objects::Face,
algorithms::intersect::CurveFaceIntersection,
builder::{CycleBuilder, FaceBuilder},
geometry::curve::Curve,
services::Services,
};

Expand All @@ -84,14 +85,9 @@ mod tests {
services.objects.surfaces.xz_plane(),
]
.map(|surface| {
Face::new(
surface,
CycleBuilder::polygon(points)
.build(&mut services.objects)
.insert(&mut services.objects),
Vec::new(),
None,
)
FaceBuilder::new(surface)
.with_exterior(CycleBuilder::polygon(points))
.build(&mut services.objects)
});

let intersection = FaceFaceIntersection::compute([&a, &b]);
Expand All @@ -115,14 +111,9 @@ mod tests {
services.objects.surfaces.xz_plane(),
];
let [a, b] = surfaces.clone().map(|surface| {
Face::new(
surface,
CycleBuilder::polygon(points)
.build(&mut services.objects)
.insert(&mut services.objects),
Vec::new(),
None,
)
FaceBuilder::new(surface)
.with_exterior(CycleBuilder::polygon(points))
.build(&mut services.objects)
});

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

use crate::{
algorithms::intersect::{face_point::FacePointIntersection, Intersect},
builder::CycleBuilder,
insert::Insert,
objects::Face,
builder::{CycleBuilder, FaceBuilder},
services::Services,
};

#[test]
fn point_is_outside_face() {
let mut services = Services::new();

let face = Face::new(
services.objects.surfaces.xy_plane(),
CycleBuilder::polygon([[0., 0.], [1., 1.], [0., 2.]])
.build(&mut services.objects)
.insert(&mut services.objects),
Vec::new(),
None,
);
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon([
[0., 0.],
[1., 1.],
[0., 2.],
]))
.build(&mut services.objects);
let point = Point::from([2., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -166,14 +163,13 @@ mod tests {
fn ray_hits_vertex_while_passing_outside() {
let mut services = Services::new();

let face = Face::new(
services.objects.surfaces.xy_plane(),
CycleBuilder::polygon([[0., 0.], [2., 1.], [0., 2.]])
.build(&mut services.objects)
.insert(&mut services.objects),
Vec::new(),
None,
);
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon([
[0., 0.],
[2., 1.],
[0., 2.],
]))
.build(&mut services.objects);
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -187,14 +183,13 @@ mod tests {
fn ray_hits_vertex_at_cycle_seam() {
let mut services = Services::new();

let face = Face::new(
services.objects.surfaces.xy_plane(),
CycleBuilder::polygon([[4., 2.], [0., 4.], [0., 0.]])
.build(&mut services.objects)
.insert(&mut services.objects),
Vec::new(),
None,
);
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon([
[4., 2.],
[0., 4.],
[0., 0.],
]))
.build(&mut services.objects);
let point = Point::from([1., 2.]);

let intersection = (&face, &point).intersect();
Expand All @@ -208,14 +203,14 @@ mod tests {
fn ray_hits_vertex_while_staying_inside() {
let mut services = Services::new();

let face = Face::new(
services.objects.surfaces.xy_plane(),
CycleBuilder::polygon([[0., 0.], [2., 1.], [3., 0.], [3., 4.]])
.build(&mut services.objects)
.insert(&mut services.objects),
Vec::new(),
None,
);
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon([
[0., 0.],
[2., 1.],
[3., 0.],
[3., 4.],
]))
.build(&mut services.objects);
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -229,14 +224,14 @@ mod tests {
fn ray_hits_parallel_edge_and_leaves_face_at_vertex() {
let mut services = Services::new();

let face = Face::new(
services.objects.surfaces.xy_plane(),
CycleBuilder::polygon([[0., 0.], [2., 1.], [3., 1.], [0., 2.]])
.build(&mut services.objects)
.insert(&mut services.objects),
Vec::new(),
None,
);
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon([
[0., 0.],
[2., 1.],
[3., 1.],
[0., 2.],
]))
.build(&mut services.objects);
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -250,20 +245,15 @@ mod tests {
fn ray_hits_parallel_edge_and_does_not_leave_face_there() {
let mut services = Services::new();

let face = Face::new(
services.objects.surfaces.xy_plane(),
CycleBuilder::polygon([
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon([
[0., 0.],
[2., 1.],
[3., 1.],
[4., 0.],
[4., 5.],
])
.build(&mut services.objects)
.insert(&mut services.objects),
Vec::new(),
None,
);
]))
.build(&mut services.objects);
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -277,14 +267,13 @@ mod tests {
fn point_is_coincident_with_edge() {
let mut services = Services::new();

let face = Face::new(
services.objects.surfaces.xy_plane(),
CycleBuilder::polygon([[0., 0.], [2., 0.], [0., 1.]])
.build(&mut services.objects)
.insert(&mut services.objects),
Vec::new(),
None,
);
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon([
[0., 0.],
[2., 0.],
[0., 1.],
]))
.build(&mut services.objects);
let point = Point::from([1., 0.]);

let intersection = (&face, &point).intersect();
Expand All @@ -304,14 +293,13 @@ mod tests {
fn point_is_coincident_with_vertex() {
let mut services = Services::new();

let face = Face::new(
services.objects.surfaces.xy_plane(),
CycleBuilder::polygon([[0., 0.], [1., 0.], [0., 1.]])
.build(&mut services.objects)
.insert(&mut services.objects),
Vec::new(),
None,
);
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon([
[0., 0.],
[1., 0.],
[0., 1.],
]))
.build(&mut services.objects);
let point = Point::from([1., 0.]);

let intersection = (&face, &point).intersect();
Expand Down
Loading

0 comments on commit 3fc8188

Please sign in to comment.