Skip to content

Commit

Permalink
Merge pull request #1632 from hannobraun/edge
Browse files Browse the repository at this point in the history
Continue preparing for next step of `HalfEdge` simplification
  • Loading branch information
hannobraun authored Feb 28, 2023
2 parents 0bc4284 + 9d25887 commit a324a15
Show file tree
Hide file tree
Showing 17 changed files with 324 additions and 214 deletions.
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

0 comments on commit a324a15

Please sign in to comment.