Skip to content

Commit

Permalink
Merge pull request #1812 from hannobraun/builder
Browse files Browse the repository at this point in the history
Migrate tests away from `FaceBuilder`, towards operations API
  • Loading branch information
hannobraun authored May 3, 2023
2 parents 5510bde + 3ed567f commit fa02019
Show file tree
Hide file tree
Showing 14 changed files with 419 additions and 209 deletions.
26 changes: 15 additions & 11 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, FaceBuilder},
geometry::curve::Curve,
objects::{Cycle, Face},
operations::{BuildCycle, BuildFace, Insert, UpdateFace},
services::Services,
};

Expand All @@ -178,20 +179,23 @@ mod tests {
[ 1., -1.],
];

let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
exterior_points,
&mut services,
))
.with_interior(CycleBuilder::polygon(
interior_points,
&mut services,
))
.build(&mut services);
let face =
Face::unbound(services.objects.surfaces.xy_plane(), &mut services)
.update_exterior(|_| {
Cycle::polygon(exterior_points, &mut services)
.insert(&mut services)
})
.add_interiors([Cycle::polygon(
interior_points,
&mut services,
)
.insert(&mut services)]);

let expected =
CurveFaceIntersection::from_intervals([[[1.], [2.]], [[4.], [5.]]]);
assert_eq!(CurveFaceIntersection::compute(&curve, &face), expected);

services.only_validate(face);
}

#[test]
Expand Down
20 changes: 12 additions & 8 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ mod tests {

use crate::{
algorithms::intersect::CurveFaceIntersection,
builder::{CycleBuilder, FaceBuilder},
geometry::curve::Curve,
objects::{Cycle, Face},
operations::{BuildCycle, BuildFace, Insert, UpdateFace},
services::Services,
};

Expand All @@ -85,14 +86,15 @@ mod tests {
services.objects.surfaces.xz_plane(),
]
.map(|surface| {
FaceBuilder::new(surface)
.with_exterior(CycleBuilder::polygon(points, &mut services))
.build(&mut services)
Face::unbound(surface, &mut services).update_exterior(|_| {
Cycle::polygon(points, &mut services).insert(&mut services)
})
});

let intersection = FaceFaceIntersection::compute([&a, &b]);

assert!(intersection.is_none());

services.only_validate([a, b]);
}

#[test]
Expand All @@ -111,9 +113,9 @@ mod tests {
services.objects.surfaces.xz_plane(),
];
let [a, b] = surfaces.clone().map(|surface| {
FaceBuilder::new(surface)
.with_exterior(CycleBuilder::polygon(points, &mut services))
.build(&mut services)
Face::unbound(surface, &mut services).update_exterior(|_| {
Cycle::polygon(points, &mut services).insert(&mut services)
})
});

let intersection = FaceFaceIntersection::compute([&a, &b]);
Expand All @@ -131,5 +133,7 @@ mod tests {
intersection_intervals: expected_intervals
})
);

services.only_validate([a, b]);
}
}
139 changes: 90 additions & 49 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,131 +138,165 @@ mod tests {

use crate::{
algorithms::intersect::{face_point::FacePointIntersection, Intersect},
builder::{CycleBuilder, FaceBuilder},
objects::{Cycle, Face},
operations::{BuildCycle, BuildFace, Insert, UpdateFace},
services::Services,
};

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

let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [1., 1.], [0., 2.]],
&mut services,
))
.build(&mut services);
let face =
Face::unbound(services.objects.surfaces.xy_plane(), &mut services)
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [1., 1.], [0., 2.]],
&mut services,
)
.insert(&mut services)
});
let point = Point::from([2., 1.]);

let intersection = (&face, &point).intersect();
assert_eq!(intersection, None);

services.only_validate(face);
}

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

let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [2., 1.], [0., 2.]],
&mut services,
))
.build(&mut services);
let face =
Face::unbound(services.objects.surfaces.xy_plane(), &mut services)
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [2., 1.], [0., 2.]],
&mut services,
)
.insert(&mut services)
});
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
assert_eq!(
intersection,
Some(FacePointIntersection::PointIsInsideFace)
);

services.only_validate(face);
}

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

let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[4., 2.], [0., 4.], [0., 0.]],
&mut services,
))
.build(&mut services);
let face =
Face::unbound(services.objects.surfaces.xy_plane(), &mut services)
.update_exterior(|_| {
Cycle::polygon(
[[4., 2.], [0., 4.], [0., 0.]],
&mut services,
)
.insert(&mut services)
});
let point = Point::from([1., 2.]);

let intersection = (&face, &point).intersect();
assert_eq!(
intersection,
Some(FacePointIntersection::PointIsInsideFace)
);

services.only_validate(face);
}

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

let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [2., 1.], [3., 0.], [3., 4.]],
&mut services,
))
.build(&mut services);
let face =
Face::unbound(services.objects.surfaces.xy_plane(), &mut services)
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [2., 1.], [3., 0.], [3., 4.]],
&mut services,
)
.insert(&mut services)
});
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
assert_eq!(
intersection,
Some(FacePointIntersection::PointIsInsideFace)
);

services.only_validate(face);
}

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

let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [2., 1.], [3., 1.], [0., 2.]],
&mut services,
))
.build(&mut services);
let face =
Face::unbound(services.objects.surfaces.xy_plane(), &mut services)
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [2., 1.], [3., 1.], [0., 2.]],
&mut services,
)
.insert(&mut services)
});
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
assert_eq!(
intersection,
Some(FacePointIntersection::PointIsInsideFace)
);

services.only_validate(face);
}

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

let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]],
&mut services,
))
.build(&mut services);
let face =
Face::unbound(services.objects.surfaces.xy_plane(), &mut services)
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]],
&mut services,
)
.insert(&mut services)
});
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
assert_eq!(
intersection,
Some(FacePointIntersection::PointIsInsideFace)
);

services.only_validate(face);
}

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

let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [2., 0.], [0., 1.]],
&mut services,
))
.build(&mut services);
let face =
Face::unbound(services.objects.surfaces.xy_plane(), &mut services)
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [2., 0.], [0., 1.]],
&mut services,
)
.insert(&mut services)
});
let point = Point::from([1., 0.]);

let intersection = (&face, &point).intersect();
Expand All @@ -276,18 +310,23 @@ mod tests {
intersection,
Some(FacePointIntersection::PointIsOnEdge(edge.clone()))
);

services.only_validate(face);
}

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

let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [1., 0.], [0., 1.]],
&mut services,
))
.build(&mut services);
let face =
Face::unbound(services.objects.surfaces.xy_plane(), &mut services)
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [1., 0.], [0., 1.]],
&mut services,
)
.insert(&mut services)
});
let point = Point::from([1., 0.]);

let intersection = (&face, &point).intersect();
Expand All @@ -304,5 +343,7 @@ mod tests {
intersection,
Some(FacePointIntersection::PointIsOnVertex(vertex))
);

services.only_validate(face);
}
}
Loading

0 comments on commit fa02019

Please sign in to comment.