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

Replace all reads of half-edge geometry with reads of vertex geometry #2417

Merged
merged 17 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 19 additions & 4 deletions crates/fj-core/src/algorithms/approx/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use fj_math::Segment;

use crate::{
geometry::Geometry,
geometry::{CurveBoundary, Geometry},
storage::Handle,
topology::{Cycle, Surface},
};
Expand All @@ -28,9 +28,24 @@ pub fn approx_cycle(

let half_edges = cycle
.half_edges()
.iter()
.map(|half_edge| {
let boundary = geometry.of_half_edge(half_edge).boundary;
.pairs()
.map(|(half_edge, next_half_edge)| {
let boundary = CurveBoundary {
inner: [
geometry
.of_vertex(half_edge.start_vertex())
.unwrap()
.local_on(half_edge.curve())
.unwrap()
.position,
geometry
.of_vertex(next_half_edge.start_vertex())
.unwrap()
.local_on(half_edge.curve())
.unwrap()
.position,
],
};
let [start_position_curve, _] = boundary.inner;

let start = approx_vertex(
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/algorithms/bounding_volume/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ impl super::BoundingVolume<2> for (&Cycle, &Handle<Surface>) {

let mut aabb: Option<Aabb<2>> = None;

for half_edge in cycle.half_edges() {
let new_aabb = (half_edge, surface)
for (half_edge, half_edge_next) in cycle.half_edges().pairs() {
let new_aabb = (half_edge, half_edge_next.start_vertex(), surface)
.aabb(geometry)
.expect("`HalfEdge` can always compute AABB");
aabb = Some(aabb.map_or(new_aabb, |aabb| aabb.merged(&new_aabb)));
Expand Down
23 changes: 16 additions & 7 deletions crates/fj-core/src/algorithms/bounding_volume/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use fj_math::{Aabb, Vector};
use crate::{
geometry::{Geometry, SurfacePath},
storage::Handle,
topology::{HalfEdge, Surface},
topology::{HalfEdge, Surface, Vertex},
};

impl super::BoundingVolume<2> for (&Handle<HalfEdge>, &Handle<Surface>) {
impl super::BoundingVolume<2>
for (&Handle<HalfEdge>, &Handle<Vertex>, &Handle<Surface>)
{
fn aabb(self, geometry: &Geometry) -> Option<Aabb<2>> {
let (half_edge, surface) = self;
let (half_edge, end_vertex, surface) = self;

let half_edge_geom = geometry.of_half_edge(half_edge);
let path = geometry
.of_curve(half_edge.curve())
.unwrap()
Expand All @@ -32,9 +33,17 @@ impl super::BoundingVolume<2> for (&Handle<HalfEdge>, &Handle<Surface>) {
})
}
SurfacePath::Line(_) => {
let points = half_edge_geom.boundary.inner.map(|point_curve| {
path.point_from_path_coords(point_curve)
});
let points =
[half_edge.start_vertex(), end_vertex].map(|vertex| {
let point_curve = geometry
.of_vertex(vertex)
.unwrap()
.local_on(half_edge.curve())
.unwrap()
.position;

path.point_from_path_coords(point_curve)
});

Some(Aabb::<2>::from_points(points))
}
Expand Down
58 changes: 36 additions & 22 deletions crates/fj-core/src/operations/split/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,43 @@ impl SplitFace for Shell {

// Build the edge that's going to divide the new faces.
let dividing_half_edge_a_to_d = {
let start = core
.layers
.geometry
.of_curve(b.curve())
.unwrap()
.local_on(face.surface())
.unwrap()
.path
.point_from_path_coords(
core.layers
.geometry
.of_vertex(b.start_vertex())
.unwrap()
.local_on(b.curve())
.unwrap()
.position,
);
let end = core
.layers
.geometry
.of_curve(d.curve())
.unwrap()
.local_on(face.surface())
.unwrap()
.path
.point_from_path_coords(
core.layers
.geometry
.of_vertex(d.start_vertex())
.unwrap()
.local_on(d.curve())
.unwrap()
.position,
);

let (half_edge, boundary) = HalfEdge::line_segment(
[
core.layers.geometry.of_half_edge(&b).start_position(
&core
.layers
.geometry
.of_curve(b.curve())
.unwrap()
.local_on(face.surface())
.unwrap()
.path,
),
core.layers.geometry.of_half_edge(&d).start_position(
&core
.layers
.geometry
.of_curve(d.curve())
.unwrap()
.local_on(face.surface())
.unwrap()
.path,
),
],
[start, end],
face.surface().clone(),
core,
);
Expand Down
22 changes: 21 additions & 1 deletion crates/fj-core/src/operations/split/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,27 @@ impl SplitHalfEdge for Cycle {
let point = point.into();

let geometry = *core.layers.geometry.of_half_edge(half_edge);
let [start, end] = geometry.boundary.inner;
let [start, end] = [
core.layers
.geometry
.of_vertex(half_edge.start_vertex())
.unwrap()
.local_on(half_edge.curve())
.unwrap()
.position,
core.layers
.geometry
.of_vertex(
self.half_edges()
.after(half_edge)
.expect("Expected half-edge to be in cycle")
.start_vertex(),
)
.unwrap()
.local_on(half_edge.curve())
.unwrap()
.position,
];

let a = HalfEdge::new(
half_edge.curve().clone(),
Expand Down
21 changes: 18 additions & 3 deletions crates/fj-core/src/operations/sweep/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,22 @@ impl SweepHalfEdge for Handle<HalfEdge> {
) -> SweptHalfEdge {
let path = path.into();

let half_edge_geom = *core.layers.geometry.of_half_edge(self);
let boundary = [
core.layers
.geometry
.of_vertex(self.start_vertex())
.unwrap()
.local_on(self.curve())
.unwrap()
.position,
core.layers
.geometry
.of_vertex(&end_vertex)
.unwrap()
.local_on(self.curve())
.unwrap()
.position,
];
let curve_geom = core
.layers
.geometry
Expand Down Expand Up @@ -94,7 +109,7 @@ impl SweepHalfEdge for Handle<HalfEdge> {

// Let's figure out the surface coordinates of the edge vertices.
let surface_points = {
let [a, b] = half_edge_geom.boundary.inner;
let [a, b] = boundary;

[
[a.t, Scalar::ZERO],
Expand All @@ -112,7 +127,7 @@ impl SweepHalfEdge for Handle<HalfEdge> {

// Now, the boundaries of each edge.
let boundaries = {
let [a, b] = half_edge_geom.boundary.inner;
let [a, b] = boundary;
let [c, d] = [0., 1.].map(|coord| Point::from([coord]));

[[a, b], [c, d], [b, a], [d, c]]
Expand Down
47 changes: 37 additions & 10 deletions crates/fj-core/src/topology/objects/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,36 @@ impl Cycle {
.next()
.expect("Invalid cycle: expected at least one edge");

let half_edge_geom = geometry.of_half_edge(first);
let curve_geom = geometry
.of_curve(first.curve())
.unwrap()
.local_on(surface)
.unwrap()
.clone();

let [a, b] = half_edge_geom.boundary.inner;
let [a, b] = [
curve_geom.path.point_from_path_coords(
geometry
.of_vertex(first.start_vertex())
.unwrap()
.local_on(first.curve())
.unwrap()
.position,
),
curve_geom.path.point_from_path_coords(
geometry
.of_vertex(
self.half_edges()
.after(first)
.expect("Just got half-edge from this cycle")
.start_vertex(),
)
.unwrap()
.local_on(first.curve())
.unwrap()
.position,
),
];
let edge_direction_positive = a < b;

let circle = match curve_geom.path {
Expand All @@ -80,14 +101,20 @@ impl Cycle {

for (a, b) in self.half_edges().pairs() {
let [a, b] = [a, b].map(|half_edge| {
geometry.of_half_edge(half_edge).start_position(
&geometry
.of_curve(half_edge.curve())
.unwrap()
.local_on(surface)
.unwrap()
.path,
)
geometry
.of_curve(half_edge.curve())
.unwrap()
.local_on(surface)
.unwrap()
.path
.point_from_path_coords(
geometry
.of_vertex(half_edge.start_vertex())
.unwrap()
.local_on(half_edge.curve())
.unwrap()
.position,
)
});

sum += (b.u - a.u) * (b.v + a.v);
Expand Down
11 changes: 8 additions & 3 deletions crates/fj-core/src/validate/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@ impl SolidValidationError {

Some((
geometry.of_surface(s).point_from_surface_coords(
geometry
.of_half_edge(&h)
.start_position(&local_curve_geometry.path),
local_curve_geometry.path.point_from_path_coords(
geometry
.of_vertex(h.start_vertex())
.unwrap()
.local_on(h.curve())
.unwrap()
.position,
),
),
h.start_vertex().clone(),
))
Expand Down
Loading