Skip to content

Commit

Permalink
Merge pull request #1883 from hannobraun/region
Browse files Browse the repository at this point in the history
Promote `Region` to an object
  • Loading branch information
hannobraun authored Jun 13, 2023
2 parents 2b15b91 + f8450c3 commit d899c4a
Show file tree
Hide file tree
Showing 33 changed files with 494 additions and 333 deletions.
9 changes: 5 additions & 4 deletions crates/fj-core/src/algorithms/approx/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ impl Approx for &Face {
// would need to provide its own approximation, as the edges that bound
// it have nothing to do with its curvature.

let exterior = (self.exterior().deref(), self.surface().deref())
.approx_with_cache(tolerance, cache);
let exterior =
(self.region().exterior().deref(), self.surface().deref())
.approx_with_cache(tolerance, cache);

let mut interiors = BTreeSet::new();
for cycle in self.interiors() {
for cycle in self.region().interiors() {
let cycle = (cycle.deref(), self.surface().deref())
.approx_with_cache(tolerance, cache);
interiors.insert(cycle);
Expand All @@ -98,7 +99,7 @@ impl Approx for &Face {
FaceApprox {
exterior,
interiors,
color: self.color(),
color: self.region().color(),
coord_handedness: self.coord_handedness(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/algorithms/bounding_volume/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{geometry::curve::GlobalPath, objects::Face};

impl super::BoundingVolume<3> for Face {
fn aabb(&self) -> Option<Aabb<3>> {
self.exterior().aabb().map(|aabb2| {
self.region().exterior().aabb().map(|aabb2| {
let surface = self.surface().geometry();

match surface.u {
Expand Down
27 changes: 17 additions & 10 deletions crates/fj-core/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ impl CurveFaceIntersection {

/// Compute the intersection
pub fn compute(curve: &Curve, face: &Face) -> Self {
let half_edges = face.all_cycles().flat_map(|cycle| cycle.half_edges());
let half_edges = face
.region()
.all_cycles()
.flat_map(|cycle| cycle.half_edges());

let mut intersections = Vec::new();

Expand Down Expand Up @@ -152,7 +155,7 @@ mod tests {
use crate::{
geometry::curve::Curve,
objects::{Cycle, Face},
operations::{BuildCycle, BuildFace, Insert, UpdateFace},
operations::{BuildCycle, BuildFace, Insert, UpdateFace, UpdateRegion},
services::Services,
};

Expand Down Expand Up @@ -181,15 +184,19 @@ mod tests {

let face =
Face::unbound(services.objects.surfaces.xy_plane(), &mut services)
.update_exterior(|_| {
Cycle::polygon(exterior_points, &mut services)
.update_region(|region| {
region
.update_exterior(|_| {
Cycle::polygon(exterior_points, &mut services)
.insert(&mut services)
})
.add_interiors([Cycle::polygon(
interior_points,
&mut services,
)
.insert(&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.]]]);
Expand Down
20 changes: 15 additions & 5 deletions crates/fj-core/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod tests {
algorithms::intersect::CurveFaceIntersection,
geometry::curve::Curve,
objects::{Cycle, Face},
operations::{BuildCycle, BuildFace, Insert, UpdateFace},
operations::{BuildCycle, BuildFace, Insert, UpdateFace, UpdateRegion},
services::Services,
};

Expand All @@ -86,8 +86,13 @@ mod tests {
services.objects.surfaces.xz_plane(),
]
.map(|surface| {
Face::unbound(surface, &mut services).update_exterior(|_| {
Cycle::polygon(points, &mut services).insert(&mut services)
Face::unbound(surface, &mut services).update_region(|region| {
region
.update_exterior(|_| {
Cycle::polygon(points, &mut services)
.insert(&mut services)
})
.insert(&mut services)
})
});

Expand All @@ -113,8 +118,13 @@ mod tests {
services.objects.surfaces.xz_plane(),
];
let [a, b] = surfaces.clone().map(|surface| {
Face::unbound(surface, &mut services).update_exterior(|_| {
Cycle::polygon(points, &mut services).insert(&mut services)
Face::unbound(surface, &mut services).update_region(|region| {
region
.update_exterior(|_| {
Cycle::polygon(points, &mut services)
.insert(&mut services)
})
.insert(&mut services)
})
});

Expand Down
140 changes: 90 additions & 50 deletions crates/fj-core/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Intersect for (&Face, &Point<2>) {

let mut num_hits = 0;

for cycle in face.all_cycles() {
for cycle in face.region().all_cycles() {
// We need to properly detect the ray passing the boundary at the
// "seam" of the polygon, i.e. the vertex between the last and the
// first segment. The logic in the loop properly takes care of that,
Expand Down Expand Up @@ -139,7 +139,7 @@ mod tests {
use crate::{
algorithms::intersect::{face_point::FacePointIntersection, Intersect},
objects::{Cycle, Face},
operations::{BuildCycle, BuildFace, Insert, UpdateFace},
operations::{BuildCycle, BuildFace, Insert, UpdateFace, UpdateRegion},
services::Services,
};

Expand All @@ -149,12 +149,16 @@ mod tests {

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)
.update_region(|region| {
region
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [1., 1.], [0., 2.]],
&mut services,
)
.insert(&mut services)
})
.insert(&mut services)
});
let point = Point::from([2., 1.]);

Expand All @@ -170,12 +174,16 @@ mod tests {

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)
.update_region(|region| {
region
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [2., 1.], [0., 2.]],
&mut services,
)
.insert(&mut services)
})
.insert(&mut services)
});
let point = Point::from([1., 1.]);

Expand All @@ -194,12 +202,16 @@ mod tests {

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)
.update_region(|region| {
region
.update_exterior(|_| {
Cycle::polygon(
[[4., 2.], [0., 4.], [0., 0.]],
&mut services,
)
.insert(&mut services)
})
.insert(&mut services)
});
let point = Point::from([1., 2.]);

Expand All @@ -218,12 +230,16 @@ mod tests {

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)
.update_region(|region| {
region
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [2., 1.], [3., 0.], [3., 4.]],
&mut services,
)
.insert(&mut services)
})
.insert(&mut services)
});
let point = Point::from([1., 1.]);

Expand All @@ -242,12 +258,16 @@ mod tests {

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)
.update_region(|region| {
region
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [2., 1.], [3., 1.], [0., 2.]],
&mut services,
)
.insert(&mut services)
})
.insert(&mut services)
});
let point = Point::from([1., 1.]);

Expand All @@ -266,12 +286,22 @@ mod tests {

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)
.update_region(|region| {
region
.update_exterior(|_| {
Cycle::polygon(
[
[0., 0.],
[2., 1.],
[3., 1.],
[4., 0.],
[4., 5.],
],
&mut services,
)
.insert(&mut services)
})
.insert(&mut services)
});
let point = Point::from([1., 1.]);

Expand All @@ -290,18 +320,23 @@ mod tests {

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)
.update_region(|region| {
region
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [2., 0.], [0., 1.]],
&mut services,
)
.insert(&mut services)
})
.insert(&mut services)
});
let point = Point::from([1., 0.]);

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

let edge = face
.region()
.exterior()
.half_edges()
.find(|edge| edge.start_position() == Point::from([0., 0.]))
Expand All @@ -320,18 +355,23 @@ mod tests {

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)
.update_region(|region| {
region
.update_exterior(|_| {
Cycle::polygon(
[[0., 0.], [1., 0.], [0., 1.]],
&mut services,
)
.insert(&mut services)
})
.insert(&mut services)
});
let point = Point::from([1., 0.]);

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

let vertex = face
.region()
.exterior()
.half_edges()
.find(|half_edge| {
Expand Down
Loading

0 comments on commit d899c4a

Please sign in to comment.