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

Continue preparing for next step of HalfEdge simplification #1632

Merged
merged 42 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
71912fc
Split `surface_vertices` field of `HalfEdge`
hannobraun Feb 28, 2023
71993b8
Add `HalfEdge::end_vertex`
hannobraun Feb 28, 2023
2831f0d
Update arguments of `HalfEdge::new`
hannobraun Feb 28, 2023
aea4d4f
Refactor
hannobraun Feb 28, 2023
299c6a2
Replace use of `HalfEdge::surface_vertices`
hannobraun Feb 28, 2023
8a6eb38
Replace use of `HalfEdge::surface_vertices`
hannobraun Feb 28, 2023
8d27d27
Replace uses of `HalfEdge::surface_vertices`
hannobraun Feb 28, 2023
dd9d40b
Replace use of `HalfEdge::surface_vertices`
hannobraun Feb 28, 2023
d2b34c7
Replace use of `HalfEdge::surface_vertices`
hannobraun Feb 28, 2023
b5589f6
Remove `HalfEdge::surface_vertices`
hannobraun Feb 28, 2023
1cc4f5b
Prepare code for follow-on change
hannobraun Feb 28, 2023
628cb9f
Prepare code for follow-on change
hannobraun Feb 28, 2023
62e2bfc
Splify `PartialHalfEdge`'s `surface_vertices`
hannobraun Feb 28, 2023
74d710e
Simplify assignments
hannobraun Feb 28, 2023
c037127
Simplify assignments
hannobraun Feb 28, 2023
9f29b88
Simplify builder methods
hannobraun Feb 28, 2023
896fe7b
Simplify assignment
hannobraun Feb 28, 2023
900af58
Remove redundant write to end vertex
hannobraun Feb 28, 2023
510a6ce
Simplify surface vertex setup for circle
hannobraun Feb 28, 2023
d9a9031
Inline redundant variable
hannobraun Feb 28, 2023
c511034
Make variable name more explicit
hannobraun Feb 28, 2023
f73f9fe
Split tuple
hannobraun Feb 28, 2023
1f72b56
Improve formatting
hannobraun Feb 28, 2023
03984c7
Prepare code for follow-on change
hannobraun Feb 28, 2023
6a3e546
Refactor
hannobraun Feb 28, 2023
9c6613f
Add dependency on `itertools` to `fj-operations`
hannobraun Feb 28, 2023
b2d3cb6
Replace use of `PartialHalfEdge`'s `end_vertex`
hannobraun Feb 28, 2023
8c839be
Replace use of `PartialHalfEdge`'s `end_vertex`
hannobraun Feb 28, 2023
53104aa
Prepare code for follow-on change
hannobraun Feb 28, 2023
0276b5b
Prepare code for follow-on change
hannobraun Feb 28, 2023
74188f9
Prepare code for follow-on change
hannobraun Feb 28, 2023
3ea6ce0
Replace use of `PartialHalfEdge`'s `end_vertex`
hannobraun Feb 28, 2023
0d5e713
Replace use of `PartialHalfEdge`'s `end_vertex`
hannobraun Feb 28, 2023
5c3bc74
Split tuple
hannobraun Feb 28, 2023
375e271
Remove redundant line
hannobraun Feb 28, 2023
3b354c1
Replace use of `PartialHalfEdge`'s `end_vertex`
hannobraun Feb 28, 2023
2eb6ea8
Prepare code for follow-on change
hannobraun Feb 28, 2023
ed6e008
Replace use of `PartialHalfEdge`'s `end_vertex`
hannobraun Feb 28, 2023
910bdf1
Prepare code for follow-on change
hannobraun Feb 28, 2023
93e3ada
Replace use of `PartialHalfEdge`'s `end_vertex`
hannobraun Feb 28, 2023
d2763cf
Prepare code for follow-on change
hannobraun Feb 28, 2023
9d25887
Prepare code for follow-on change
hannobraun Feb 28, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 28 additions & 7 deletions crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,14 @@ mod tests {
let half_edge = {
let mut half_edge = PartialHalfEdge::default();

half_edge.update_as_line_segment_from_points([[1., 1.], [2., 1.]]);
half_edge.infer_vertex_positions_if_necessary(&surface.geometry());
half_edge.update_as_line_segment_from_points(
[[1., 1.], [2., 1.]],
half_edge.end_vertex.clone(),
);
half_edge.infer_vertex_positions_if_necessary(
&surface.geometry(),
half_edge.end_vertex.clone(),
);

half_edge
.build(&mut services.objects)
Expand All @@ -273,8 +279,14 @@ mod tests {
let half_edge = {
let mut half_edge = PartialHalfEdge::default();

half_edge.update_as_line_segment_from_points([[1., 1.], [2., 1.]]);
half_edge.infer_vertex_positions_if_necessary(&surface.geometry());
half_edge.update_as_line_segment_from_points(
[[1., 1.], [2., 1.]],
half_edge.end_vertex.clone(),
);
half_edge.infer_vertex_positions_if_necessary(
&surface.geometry(),
half_edge.end_vertex.clone(),
);

half_edge
.build(&mut services.objects)
Expand All @@ -300,12 +312,18 @@ mod tests {
let half_edge = {
let mut half_edge = PartialHalfEdge::default();

half_edge.update_as_line_segment_from_points([[0., 1.], [1., 1.]]);
half_edge.update_as_line_segment_from_points(
[[0., 1.], [1., 1.]],
half_edge.end_vertex.clone(),
);

half_edge.boundary[0] = Some(range.boundary[0]);
half_edge.boundary[1] = Some(range.boundary[1]);

half_edge.infer_vertex_positions_if_necessary(&surface.geometry());
half_edge.infer_vertex_positions_if_necessary(
&surface.geometry(),
half_edge.end_vertex.clone(),
);

half_edge
.build(&mut services.objects)
Expand Down Expand Up @@ -338,7 +356,10 @@ mod tests {
let mut half_edge = PartialHalfEdge::default();

half_edge.update_as_circle_from_radius(1.);
half_edge.infer_vertex_positions_if_necessary(&surface.geometry());
half_edge.infer_vertex_positions_if_necessary(
&surface.geometry(),
half_edge.end_vertex.clone(),
);

half_edge
.build(&mut services.objects)
Expand Down
42 changes: 32 additions & 10 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ mod tests {
let curve = Curve::u_axis();
let half_edge = {
let mut half_edge = PartialHalfEdge::default();
half_edge.update_as_line_segment_from_points([[1., -1.], [1., 1.]]);
half_edge.infer_vertex_positions_if_necessary(&surface.geometry());
half_edge.update_as_line_segment_from_points(
[[1., -1.], [1., 1.]],
half_edge.end_vertex.clone(),
);
half_edge.infer_vertex_positions_if_necessary(
&surface.geometry(),
half_edge.end_vertex.clone(),
);

half_edge.build(&mut services.objects)
};
Expand All @@ -112,9 +118,14 @@ mod tests {
let curve = Curve::u_axis();
let half_edge = {
let mut half_edge = PartialHalfEdge::default();
half_edge
.update_as_line_segment_from_points([[-1., -1.], [-1., 1.]]);
half_edge.infer_vertex_positions_if_necessary(&surface.geometry());
half_edge.update_as_line_segment_from_points(
[[-1., -1.], [-1., 1.]],
half_edge.end_vertex.clone(),
);
half_edge.infer_vertex_positions_if_necessary(
&surface.geometry(),
half_edge.end_vertex.clone(),
);

half_edge.build(&mut services.objects)
};
Expand All @@ -137,9 +148,14 @@ mod tests {
let curve = Curve::u_axis();
let half_edge = {
let mut half_edge = PartialHalfEdge::default();
half_edge
.update_as_line_segment_from_points([[-1., -1.], [1., -1.]]);
half_edge.infer_vertex_positions_if_necessary(&surface.geometry());
half_edge.update_as_line_segment_from_points(
[[-1., -1.], [1., -1.]],
half_edge.end_vertex.clone(),
);
half_edge.infer_vertex_positions_if_necessary(
&surface.geometry(),
half_edge.end_vertex.clone(),
);

half_edge.build(&mut services.objects)
};
Expand All @@ -157,8 +173,14 @@ mod tests {
let curve = Curve::u_axis();
let half_edge = {
let mut half_edge = PartialHalfEdge::default();
half_edge.update_as_line_segment_from_points([[-1., 0.], [1., 0.]]);
half_edge.infer_vertex_positions_if_necessary(&surface.geometry());
half_edge.update_as_line_segment_from_points(
[[-1., 0.], [1., 0.]],
half_edge.end_vertex.clone(),
);
half_edge.infer_vertex_positions_if_necessary(
&surface.geometry(),
half_edge.end_vertex.clone(),
);

half_edge.build(&mut services.objects)
};
Expand Down
6 changes: 2 additions & 4 deletions crates/fj-kernel/src/algorithms/reverse/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ impl Reverse for Handle<Cycle> {
let [a, b] = current.boundary();
[b, a]
};
let surface_vertices =
[next.start_vertex(), current.start_vertex()]
.map(Clone::clone);

HalfEdge::new(
current.curve(),
boundary,
surface_vertices,
next.start_vertex().clone(),
current.start_vertex().clone(),
current.global_form().clone(),
)
.insert(objects)
Expand Down
21 changes: 13 additions & 8 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use fj_interop::{ext::ArrayExt, mesh::Color};
use fj_math::{Point, Scalar, Vector};
use itertools::Itertools;

use crate::{
builder::{CycleBuilder, HalfEdgeBuilder},
Expand Down Expand Up @@ -106,7 +107,7 @@ impl Sweep for (Handle<HalfEdge>, &Handle<SurfaceVertex>, &Surface, Color) {
// Writing to the start vertices is enough. Neighboring half-
// edges share surface vertices, so writing the start vertex of
// each half-edge writes to all vertices.
let mut vertex = half_edge.surface_vertices[0].write();
let mut vertex = half_edge.start_vertex.write();
vertex.position = Some(surface_point);
vertex.global_form = Partial::from(global_vertex);
},
Expand All @@ -118,13 +119,17 @@ impl Sweep for (Handle<HalfEdge>, &Handle<SurfaceVertex>, &Surface, Color) {
// even if the original edge was a circle, it's still going to be a line
// when projected into the new surface. For the side edges, because
// we're sweeping along a straight path.
for mut edge in [
edge_bottom.write(),
edge_up.write(),
edge_top.write(),
edge_down.write(),
] {
edge.update_as_line_segment();
for (mut edge, next) in [
edge_bottom.clone(),
edge_up.clone(),
edge_top.clone(),
edge_down.clone(),
]
.into_iter()
.circular_tuple_windows()
{
edge.write()
.update_as_line_segment(next.read().start_vertex.clone());
}

// Finally, we can make sure that all edges refer to the correct global
Expand Down
25 changes: 12 additions & 13 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,18 @@ impl Sweep for Handle<Face> {
.connect_to_closed_edges(top_edges, &top_surface.geometry());

for half_edge in &mut top_cycle.write().half_edges {
for surface_vertex in &mut half_edge.write().surface_vertices {
let mut surface_vertex = surface_vertex.write();
let global_point =
surface_vertex.global_form.read().position;

if surface_vertex.position.is_none() {
if let Some(global_point) = global_point {
surface_vertex.position = Some(
top_surface
.geometry()
.project_global_point(global_point),
);
}
let mut half_edge = half_edge.write();

let mut start_vertex = half_edge.start_vertex.write();
let global_point = start_vertex.global_form.read().position;

if start_vertex.position.is_none() {
if let Some(global_point) = global_point {
start_vertex.position = Some(
top_surface
.geometry()
.project_global_point(global_point),
);
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ impl TransformObject for HalfEdge {
// coordinates.
let curve = self.curve();
let boundary = self.boundary();
let surface_vertices = self.surface_vertices().map(|surface_vertex| {
surface_vertex
.clone()
.transform_with_cache(transform, objects, cache)
});
let start_vertex = self
.start_vertex()
.clone()
.transform_with_cache(transform, objects, cache);
let end_vertex = self
.end_vertex()
.clone()
.transform_with_cache(transform, objects, cache);
let global_form = self
.global_form()
.clone()
.transform_with_cache(transform, objects, cache);

Self::new(curve, boundary, surface_vertices, global_form)
Self::new(curve, boundary, start_vertex, end_vertex, global_form)
}
}

Expand Down
58 changes: 28 additions & 30 deletions crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fj_math::Point;
use itertools::Itertools;

use crate::{
geometry::surface::SurfaceGeometry,
Expand Down Expand Up @@ -102,29 +103,23 @@ impl CycleBuilder for PartialCycle {
};

{
let shared_surface_vertex = {
let [vertex, _] = &new_half_edge.read().surface_vertices;
vertex.clone()
};
let shared_surface_vertex =
new_half_edge.read().start_vertex.clone();

let mut last_half_edge = last_half_edge.write();

let [_, vertex] = &mut last_half_edge.surface_vertices;
*vertex = shared_surface_vertex;
last_half_edge.infer_global_form();
last_half_edge.end_vertex = shared_surface_vertex.clone();
last_half_edge.infer_global_form(shared_surface_vertex);
}

{
let shared_surface_vertex = {
let [vertex, _] = &first_half_edge.read().surface_vertices;
vertex.clone()
};
let shared_surface_vertex =
first_half_edge.read().start_vertex.clone();

let mut new_half_edge = new_half_edge.write();

let [_, vertex] = &mut new_half_edge.surface_vertices;
*vertex = shared_surface_vertex;
new_half_edge.infer_global_form();
new_half_edge.end_vertex = shared_surface_vertex.clone();
new_half_edge.infer_global_form(shared_surface_vertex);
}

self.half_edges.push(new_half_edge.clone());
Expand All @@ -136,12 +131,7 @@ impl CycleBuilder for PartialCycle {
point: impl Into<Point<2>>,
) -> Partial<HalfEdge> {
let mut half_edge = self.add_half_edge();

{
let [vertex, _] = &mut half_edge.write().surface_vertices;
vertex.write().position = Some(point.into());
}

half_edge.write().start_vertex.write().position = Some(point.into());
half_edge
}

Expand All @@ -150,12 +140,13 @@ impl CycleBuilder for PartialCycle {
point: impl Into<Point<3>>,
) -> Partial<HalfEdge> {
let mut half_edge = self.add_half_edge();

{
let [vertex, _] = &mut half_edge.write().surface_vertices;
vertex.write().global_form.write().position = Some(point.into());
}

half_edge
.write()
.start_vertex
.write()
.global_form
.write()
.position = Some(point.into());
half_edge
}

Expand All @@ -174,8 +165,12 @@ impl CycleBuilder for PartialCycle {
}

fn update_as_polygon(&mut self) {
for half_edge in &mut self.half_edges {
half_edge.write().update_as_line_segment();
for (mut half_edge, next) in
self.half_edges.iter().cloned().circular_tuple_windows()
{
half_edge
.write()
.update_as_line_segment(next.read().start_vertex.clone());
}
}

Expand All @@ -198,10 +193,13 @@ impl CycleBuilder for PartialCycle {
&mut self,
surface: &SurfaceGeometry,
) {
for half_edge in &mut self.half_edges {
for (mut half_edge, next_half_edge) in
self.half_edges.iter().cloned().circular_tuple_windows()
{
let next_vertex = next_half_edge.read().start_vertex.clone();
half_edge
.write()
.infer_vertex_positions_if_necessary(surface);
.infer_vertex_positions_if_necessary(surface, next_vertex);
}
}
}
Loading