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

Promote Region to an object #1883

Merged
merged 28 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
21b14ab
Move `Region` to `objects` module
hannobraun Jun 13, 2023
7878816
Extract non-trivial expression to improve clarity
hannobraun Jun 13, 2023
52be355
Simplify argument
hannobraun Jun 13, 2023
4944355
Expect `Region` in `Face::new`
hannobraun Jun 13, 2023
82e28e3
Add store for `Region`
hannobraun Jun 13, 2023
f703bd9
Fix typo in comment
hannobraun Jun 13, 2023
97b167b
Fix formatting
hannobraun Jun 13, 2023
527bebb
Implement `Validate` for `Region`
hannobraun Jun 13, 2023
495d2af
Add `Region` to `Object`
hannobraun Jun 13, 2023
c0ad486
Implement `Insert` for `Region`
hannobraun Jun 13, 2023
e4f0be6
Make argument name more explicit
hannobraun Jun 13, 2023
a37f9c7
Simplify docs to prepare for follow-on change
hannobraun Jun 13, 2023
01c0feb
Remove `Region::face`
hannobraun Jun 13, 2023
0943f41
Refactor to prepare for follow-on change
hannobraun Jun 13, 2023
b20d7c1
Expect `Handle<Region>` in `UpdateSketch` method
hannobraun Jun 13, 2023
d2a7c8e
Store `Handle<Region>` in `Sketch`
hannobraun Jun 13, 2023
1ba2e99
Improve formatting
hannobraun Jun 13, 2023
a0da720
Add `Face::region`
hannobraun Jun 13, 2023
3a5ce57
Remove redundant method `Face::exterior`
hannobraun Jun 13, 2023
0d26fc7
Remove redundant method `Face::interiors`
hannobraun Jun 13, 2023
61d8918
Remove redundant method `Face::all_cycles`
hannobraun Jun 13, 2023
7062276
Remove redundant method `Face::color`
hannobraun Jun 13, 2023
1c3f87e
Add `UpdateFace::update_region`
hannobraun Jun 13, 2023
da9d7ef
Add `UpdateRegion`
hannobraun Jun 13, 2023
0bec0c3
Remove redundant `UpdateFace::update_exterior`
hannobraun Jun 13, 2023
2335812
Remove redundant `UpdateFace::add_interiors`
hannobraun Jun 13, 2023
c24ebc6
Store `Handle<Region>` in `Face`
hannobraun Jun 13, 2023
f8450c3
Make `UpdateFace::update_region` more flexible
hannobraun Jun 13, 2023
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
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