Skip to content

Commit

Permalink
Bypass surface vertex, use global vertex directly
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Mar 2, 2023
1 parent 7bd721d commit 6b0eba0
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 130 deletions.
25 changes: 5 additions & 20 deletions crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Approx for (&Handle<HalfEdge>, &Surface) {

let first = ApproxPoint::new(
half_edge.start_position(),
half_edge.start_vertex().global_form().position(),
half_edge.start_vertex().position(),
)
.with_source((half_edge.clone(), half_edge.boundary()[0]));

Expand Down Expand Up @@ -252,12 +252,7 @@ mod tests {
.update_as_polygon_from_points([[1., 1.], [2., 1.], [1., 2.]]);
half_edge.write().infer_vertex_positions_if_necessary(
&surface.geometry(),
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
next_half_edge.read().start_vertex.clone(),
);

let half_edge = half_edge.read().clone();
Expand Down Expand Up @@ -289,12 +284,7 @@ mod tests {
.update_as_polygon_from_points([[1., 1.], [2., 1.], [1., 2.]]);
half_edge.write().infer_vertex_positions_if_necessary(
&surface.geometry(),
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
next_half_edge.read().start_vertex.clone(),
);

let half_edge = half_edge.read().clone();
Expand Down Expand Up @@ -330,12 +320,7 @@ mod tests {

half_edge.write().infer_vertex_positions_if_necessary(
&surface.geometry(),
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
next_half_edge.read().start_vertex.clone(),
);

let half_edge = half_edge.read().clone();
Expand Down Expand Up @@ -370,7 +355,7 @@ mod tests {
let mut half_edge = PartialHalfEdge::default();

half_edge.update_as_circle_from_radius(1.);
let next_vertex = half_edge.start_vertex.read().global_form.clone();
let next_vertex = half_edge.start_vertex.clone();
half_edge.infer_vertex_positions_if_necessary(
&surface.geometry(),
next_vertex,
Expand Down
28 changes: 4 additions & 24 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ mod tests {
.update_as_polygon_from_points([[1., -1.], [1., 1.], [0., 1.]]);
half_edge.write().infer_vertex_positions_if_necessary(
&surface.geometry(),
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
next_half_edge.read().start_vertex.clone(),
);

half_edge.build(&mut services.objects)
Expand Down Expand Up @@ -131,12 +126,7 @@ mod tests {
]);
half_edge.write().infer_vertex_positions_if_necessary(
&surface.geometry(),
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
next_half_edge.read().start_vertex.clone(),
);

half_edge.build(&mut services.objects)
Expand Down Expand Up @@ -169,12 +159,7 @@ mod tests {
]);
half_edge.write().infer_vertex_positions_if_necessary(
&surface.geometry(),
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
next_half_edge.read().start_vertex.clone(),
);

half_edge.build(&mut services.objects)
Expand All @@ -198,12 +183,7 @@ mod tests {
.update_as_polygon_from_points([[-1., 0.], [1., 0.], [1., 1.]]);
half_edge.write().infer_vertex_positions_if_necessary(
&surface.geometry(),
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
next_half_edge.read().start_vertex.clone(),
);

half_edge.build(&mut services.objects)
Expand Down
17 changes: 5 additions & 12 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ impl Sweep for (Handle<HalfEdge>, &Handle<GlobalVertex>, &Surface, Color) {
//
// Let's start with the global vertices and edges.
let (global_vertices, global_edges) = {
let [a, b] = [edge.start_vertex().global_form(), next_vertex]
.map(Clone::clone);
let [a, b] = [edge.start_vertex(), next_vertex].map(Clone::clone);
let (edge_right, [_, c]) =
b.clone().sweep_with_cache(path, cache, objects);
let (edge_left, [_, d]) =
Expand Down Expand Up @@ -103,8 +102,7 @@ impl Sweep for (Handle<HalfEdge>, &Handle<GlobalVertex>, &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.start_vertex.write();
vertex.global_form = Partial::from(global_vertex);
half_edge.start_vertex = Partial::from(global_vertex);
});

// With the vertices set, we can now update the curves.
Expand All @@ -124,14 +122,9 @@ impl Sweep for (Handle<HalfEdge>, &Handle<GlobalVertex>, &Surface, Color) {
.circular_tuple_windows()
{
half_edge.write().update_as_line_segment(start, end);
half_edge.write().infer_global_form(
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
);
half_edge
.write()
.infer_global_form(next_half_edge.read().start_vertex.clone());
}

// Finally, we can make sure that all edges refer to the correct global
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Sweep for Handle<Face> {
{
let (face, top_edge) = (
half_edge.clone(),
next.start_vertex().global_form(),
next.start_vertex(),
self.surface().deref(),
self.color(),
)
Expand Down
17 changes: 4 additions & 13 deletions crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,15 @@ impl CycleBuilder for PartialCycle {

{
let shared_surface_vertex =
new_half_edge.read().start_vertex.read().global_form.clone();
new_half_edge.read().start_vertex.clone();
last_half_edge
.write()
.infer_global_form(shared_surface_vertex);
}

{
let shared_surface_vertex = first_half_edge
.read()
.start_vertex
.read()
.global_form
.clone();
let shared_surface_vertex =
first_half_edge.read().start_vertex.clone();
new_half_edge
.write()
.infer_global_form(shared_surface_vertex);
Expand Down Expand Up @@ -142,12 +138,7 @@ impl CycleBuilder for PartialCycle {
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
.read()
.global_form
.clone();
let next_vertex = next_half_edge.read().start_vertex.clone();
half_edge
.write()
.infer_vertex_positions_if_necessary(surface, next_vertex);
Expand Down
22 changes: 8 additions & 14 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
*point_boundary = Some(point_curve);
}

let next_vertex = self.start_vertex.read().global_form.clone();
let next_vertex = self.start_vertex.clone();
self.infer_global_form(next_vertex);

path
Expand Down Expand Up @@ -156,8 +156,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
next_vertex: Partial<GlobalVertex>,
) -> Partial<GlobalEdge> {
self.global_form.write().vertices =
[&self.start_vertex.read().global_form, &next_vertex]
.map(|vertex| vertex.clone());
[&self.start_vertex, &next_vertex].map(|vertex| vertex.clone());

self.global_form.clone()
}
Expand All @@ -174,10 +173,10 @@ impl HalfEdgeBuilder for PartialHalfEdge {
panic!("Can't infer vertex positions with undefined path");
};

for (boundary_point, mut vertex) in self.boundary.zip_ext([
self.start_vertex.read().global_form.clone(),
next_vertex,
]) {
for (boundary_point, mut vertex) in self
.boundary
.zip_ext([self.start_vertex.clone(), next_vertex])
{
let position_curve = boundary_point
.expect("Can't infer surface position without curve position");
let position_surface = path.point_from_path_coords(position_curve);
Expand Down Expand Up @@ -272,13 +271,8 @@ impl HalfEdgeBuilder for PartialHalfEdge {
}
});

self.start_vertex.write().global_form.write().position = other_prev
.read()
.start_vertex
.read()
.global_form
.read()
.position;
self.start_vertex.write().position =
other_prev.read().start_vertex.read().position;
}
}

Expand Down
26 changes: 6 additions & 20 deletions crates/fj-kernel/src/objects/full/edge.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use fj_math::Point;

use crate::{
geometry::curve::Curve,
objects::{GlobalVertex, SurfaceVertex},
storage::Handle,
};
use crate::{geometry::curve::Curve, objects::GlobalVertex, storage::Handle};

/// A directed edge, defined in a surface's 2D space
///
Expand Down Expand Up @@ -46,7 +42,7 @@ use crate::{
pub struct HalfEdge {
curve: Curve,
boundary: [Point<1>; 2],
start_vertex: Handle<SurfaceVertex>,
start_vertex: Handle<GlobalVertex>,
global_form: Handle<GlobalEdge>,
}

Expand All @@ -55,7 +51,7 @@ impl HalfEdge {
pub fn new(
curve: Curve,
boundary: [Point<1>; 2],
start_vertex: Handle<SurfaceVertex>,
start_vertex: Handle<GlobalVertex>,
global_form: Handle<GlobalEdge>,
) -> Self {
Self {
Expand Down Expand Up @@ -87,7 +83,7 @@ impl HalfEdge {
}

/// Access the vertex from where this half-edge starts
pub fn start_vertex(&self) -> &Handle<SurfaceVertex> {
pub fn start_vertex(&self) -> &Handle<GlobalVertex> {
&self.start_vertex
}

Expand Down Expand Up @@ -191,12 +187,7 @@ mod tests {
cycle.update_as_polygon_from_points([a, b, c]);
half_edge.write().infer_vertex_positions_if_necessary(
&surface.geometry(),
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
next_half_edge.read().start_vertex.clone(),
);

half_edge.build(&mut services.objects)
Expand All @@ -208,12 +199,7 @@ mod tests {
cycle.update_as_polygon_from_points([b, a, c]);
half_edge.write().infer_vertex_positions_if_necessary(
&surface.geometry(),
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
next_half_edge.read().start_vertex.clone(),
);

half_edge.build(&mut services.objects)
Expand Down
13 changes: 4 additions & 9 deletions crates/fj-kernel/src/partial/objects/edge.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fj_math::Point;

use crate::{
objects::{GlobalEdge, GlobalVertex, HalfEdge, Objects, SurfaceVertex},
objects::{GlobalEdge, GlobalVertex, HalfEdge, Objects},
partial::{FullToPartialCache, MaybeCurve, Partial, PartialObject},
services::Service,
};
Expand All @@ -16,7 +16,7 @@ pub struct PartialHalfEdge {
pub boundary: [Option<Point<1>>; 2],

/// The surface vertex where the half-edge starts
pub start_vertex: Partial<SurfaceVertex>,
pub start_vertex: Partial<GlobalVertex>,

/// The global form of the half-edge
pub global_form: Partial<GlobalEdge>,
Expand Down Expand Up @@ -88,13 +88,8 @@ impl Default for PartialHalfEdge {
let start_vertex = Partial::default();
let end_vertex = Partial::default();

let global_vertices = [&start_vertex, &end_vertex].map(
|vertex: &Partial<SurfaceVertex>| {
let surface_vertex = vertex.clone();
let global_vertex = surface_vertex.read().global_form.clone();
global_vertex
},
);
let global_vertices = [&start_vertex, &end_vertex]
.map(|vertex: &Partial<GlobalVertex>| vertex.clone());

let global_form = Partial::from_partial(PartialGlobalEdge {
vertices: global_vertices,
Expand Down
17 changes: 3 additions & 14 deletions crates/fj-kernel/src/validate/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ impl HalfEdgeValidationError {
half_edge: &HalfEdge,
errors: &mut Vec<ValidationError>,
) {
let global_vertex_from_half_edge =
half_edge.start_vertex().global_form().clone();
let global_vertex_from_half_edge = half_edge.start_vertex().clone();
let global_vertices_from_global_form = half_edge
.global_form()
.vertices()
Expand Down Expand Up @@ -149,12 +148,7 @@ mod tests {
.update_as_polygon_from_points([[0., 0.], [1., 0.], [1., 1.]]);
half_edge.write().infer_vertex_positions_if_necessary(
&surface.geometry(),
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
next_half_edge.read().start_vertex.clone(),
);

half_edge.build(&mut services.objects)
Expand Down Expand Up @@ -208,12 +202,7 @@ mod tests {
.update_as_polygon_from_points([[0., 0.], [1., 0.], [1., 1.]]);
half_edge.write().infer_vertex_positions_if_necessary(
&surface.geometry(),
next_half_edge
.read()
.start_vertex
.read()
.global_form
.clone(),
next_half_edge.read().start_vertex.clone(),
);

half_edge.build(&mut services.objects)
Expand Down
Loading

0 comments on commit 6b0eba0

Please sign in to comment.