Merge pull request #2303 from hannobraun/geometry

Don't implicitly copy geometry when returning it from geometry layer
This commit is contained in:
Hanno Braun 2024-03-27 12:21:04 +01:00 committed by GitHub
commit 9e67c4b8c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 44 additions and 49 deletions

View File

@ -32,7 +32,7 @@ impl Approx for (&Handle<Curve>, &HalfEdgeGeometry, &Handle<Surface>) {
None => { None => {
let approx = approx_curve( let approx = approx_curve(
&half_edge.path, &half_edge.path,
&geometry.of_surface(surface), geometry.of_surface(surface),
half_edge.boundary, half_edge.boundary,
tolerance, tolerance,
geometry, geometry,

View File

@ -48,16 +48,9 @@ impl Approx for (&Handle<HalfEdge>, &Handle<Surface>) {
let first = ApproxPoint::new(start_position_surface, start_position); let first = ApproxPoint::new(start_position_surface, start_position);
let rest = { let rest = {
let approx = ( let approx =
half_edge.curve(), (half_edge.curve(), geometry.of_half_edge(half_edge), surface)
&geometry.of_half_edge(half_edge), .approx_with_cache(tolerance, &mut cache.curve, geometry);
surface,
)
.approx_with_cache(
tolerance,
&mut cache.curve,
geometry,
);
approx.points.into_iter().map(|point| { approx.points.into_iter().map(|point| {
let point_surface = geometry let point_surface = geometry

View File

@ -80,10 +80,9 @@ impl Geometry {
pub fn of_half_edge( pub fn of_half_edge(
&self, &self,
half_edge: &Handle<HalfEdge>, half_edge: &Handle<HalfEdge>,
) -> HalfEdgeGeometry { ) -> &HalfEdgeGeometry {
self.half_edge self.half_edge
.get(half_edge) .get(half_edge)
.copied()
.expect("Expected geometry of half-edge to be defined") .expect("Expected geometry of half-edge to be defined")
} }
@ -92,25 +91,24 @@ impl Geometry {
/// ## Panics /// ## Panics
/// ///
/// Panics, if the geometry of the surface is not defined. /// Panics, if the geometry of the surface is not defined.
pub fn of_surface(&self, surface: &Handle<Surface>) -> SurfaceGeometry { pub fn of_surface(&self, surface: &Handle<Surface>) -> &SurfaceGeometry {
self.surface self.surface
.get(surface) .get(surface)
.copied()
.expect("Expected geometry of surface to be defined") .expect("Expected geometry of surface to be defined")
} }
/// Access the geometry of the xy-plane /// Access the geometry of the xy-plane
pub fn xy_plane(&self) -> SurfaceGeometry { pub fn xy_plane(&self) -> &SurfaceGeometry {
self.of_surface(&self.xy_plane) self.of_surface(&self.xy_plane)
} }
/// Access the geometry of the xz-plane /// Access the geometry of the xz-plane
pub fn xz_plane(&self) -> SurfaceGeometry { pub fn xz_plane(&self) -> &SurfaceGeometry {
self.of_surface(&self.xz_plane) self.of_surface(&self.xz_plane)
} }
/// Access the geometry of the yz-plane /// Access the geometry of the yz-plane
pub fn yz_plane(&self) -> SurfaceGeometry { pub fn yz_plane(&self) -> &SurfaceGeometry {
self.of_surface(&self.yz_plane) self.of_surface(&self.yz_plane)
} }
} }

View File

@ -29,7 +29,7 @@ pub trait BuildHalfEdge {
start_vertex: Handle<Vertex>, start_vertex: Handle<Vertex>,
core: &mut Core, core: &mut Core,
) -> Handle<HalfEdge> { ) -> Handle<HalfEdge> {
let mut geometry = core.layers.geometry.of_half_edge(sibling); let mut geometry = *core.layers.geometry.of_half_edge(sibling);
geometry.boundary = geometry.boundary.reverse(); geometry.boundary = geometry.boundary.reverse();
HalfEdge::new(sibling.curve().clone(), start_vertex) HalfEdge::new(sibling.curve().clone(), start_vertex)

View File

@ -102,7 +102,8 @@ pub trait BuildShell {
.update_curve(|_, _| curve, core) .update_curve(|_, _| curve, core)
.insert(core) .insert(core)
.set_geometry( .set_geometry(
core.layers *core
.layers
.geometry .geometry
.of_half_edge(&half_edge), .of_half_edge(&half_edge),
&mut core.layers.geometry, &mut core.layers.geometry,

View File

@ -68,7 +68,7 @@ impl AddHole for Shell {
[Cycle::empty().add_joined_edges( [Cycle::empty().add_joined_edges(
[( [(
entry.clone(), entry.clone(),
core.layers.geometry.of_half_edge(&entry), *core.layers.geometry.of_half_edge(&entry),
)], )],
core, core,
)], )],
@ -138,7 +138,7 @@ impl AddHole for Shell {
[Cycle::empty().add_joined_edges( [Cycle::empty().add_joined_edges(
[( [(
entry.clone(), entry.clone(),
core.layers.geometry.of_half_edge(&entry), *core.layers.geometry.of_half_edge(&entry),
)], )],
core, core,
)], )],
@ -159,7 +159,7 @@ impl AddHole for Shell {
[Cycle::empty().add_joined_edges( [Cycle::empty().add_joined_edges(
[( [(
exit.clone(), exit.clone(),
core.layers.geometry.of_half_edge(exit), *core.layers.geometry.of_half_edge(exit),
)], )],
core, core,
)], )],

View File

@ -137,7 +137,8 @@ impl JoinCycle for Cycle {
) )
.insert(core) .insert(core)
.set_geometry( .set_geometry(
core.layers *core
.layers
.geometry .geometry
.of_half_edge(half_edge), .of_half_edge(half_edge),
&mut core.layers.geometry, &mut core.layers.geometry,
@ -155,7 +156,8 @@ impl JoinCycle for Cycle {
) )
.insert(core) .insert(core)
.set_geometry( .set_geometry(
core.layers *core
.layers
.geometry .geometry
.of_half_edge(half_edge), .of_half_edge(half_edge),
&mut core.layers.geometry, &mut core.layers.geometry,

View File

@ -14,7 +14,7 @@ impl Reverse for Cycle {
.half_edges() .half_edges()
.pairs() .pairs()
.map(|(current, next)| { .map(|(current, next)| {
let mut geometry = core.layers.geometry.of_half_edge(current); let mut geometry = *core.layers.geometry.of_half_edge(current);
geometry.boundary = geometry.boundary.reverse(); geometry.boundary = geometry.boundary.reverse();
HalfEdge::new( HalfEdge::new(

View File

@ -9,7 +9,7 @@ use super::ReverseCurveCoordinateSystems;
impl ReverseCurveCoordinateSystems for Handle<HalfEdge> { impl ReverseCurveCoordinateSystems for Handle<HalfEdge> {
fn reverse_curve_coordinate_systems(&self, core: &mut Core) -> Self { fn reverse_curve_coordinate_systems(&self, core: &mut Core) -> Self {
let mut geometry = core.layers.geometry.of_half_edge(self); let mut geometry = *core.layers.geometry.of_half_edge(self);
geometry.path = geometry.path.reverse(); geometry.path = geometry.path.reverse();
geometry.boundary = geometry.boundary.reverse(); geometry.boundary = geometry.boundary.reverse();

View File

@ -51,7 +51,7 @@ impl SplitEdge for Shell {
) )
.insert(core) .insert(core)
.set_geometry( .set_geometry(
core.layers.geometry.of_half_edge(&sibling_b), *core.layers.geometry.of_half_edge(&sibling_b),
&mut core.layers.geometry, &mut core.layers.geometry,
); );

View File

@ -115,7 +115,7 @@ impl SplitFace for Shell {
.update_start_vertex(|_, _| b.start_vertex().clone(), core) .update_start_vertex(|_, _| b.start_vertex().clone(), core)
.insert(core) .insert(core)
.set_geometry( .set_geometry(
core.layers.geometry.of_half_edge(&half_edge), *core.layers.geometry.of_half_edge(&half_edge),
&mut core.layers.geometry, &mut core.layers.geometry,
) )
}; };

View File

@ -42,7 +42,7 @@ impl SplitHalfEdge for Handle<HalfEdge> {
) -> [Handle<HalfEdge>; 2] { ) -> [Handle<HalfEdge>; 2] {
let point = point.into(); let point = point.into();
let geometry = core.layers.geometry.of_half_edge(self); let geometry = *core.layers.geometry.of_half_edge(self);
let [start, end] = geometry.boundary.inner; let [start, end] = geometry.boundary.inner;
let a = let a =

View File

@ -77,7 +77,7 @@ impl SweepCycle for Cycle {
top_edges.push(( top_edges.push((
top_edge, top_edge,
core.layers.geometry.of_half_edge(bottom_half_edge), *core.layers.geometry.of_half_edge(bottom_half_edge),
)); ));
} }

View File

@ -58,12 +58,12 @@ impl SweepHalfEdge for Handle<HalfEdge> {
) -> (Face, Handle<HalfEdge>) { ) -> (Face, Handle<HalfEdge>) {
let path = path.into(); let path = path.into();
let geometry = core.layers.geometry.of_half_edge(self); let half_edge_geom = *core.layers.geometry.of_half_edge(self);
let surface = geometry.path.sweep_surface_path( let surface_geom = *core.layers.geometry.of_surface(&surface);
&core.layers.geometry.of_surface(&surface), let surface =
path, half_edge_geom
core, .path
); .sweep_surface_path(&surface_geom, path, core);
// Next, we need to define the boundaries of the face. Let's start with // Next, we need to define the boundaries of the face. Let's start with
// the global vertices and edges. // the global vertices and edges.
@ -85,7 +85,7 @@ impl SweepHalfEdge for Handle<HalfEdge> {
// Let's figure out the surface coordinates of the edge vertices. // Let's figure out the surface coordinates of the edge vertices.
let surface_points = { let surface_points = {
let [a, b] = geometry.boundary.inner; let [a, b] = half_edge_geom.boundary.inner;
[ [
[a.t, Scalar::ZERO], [a.t, Scalar::ZERO],
@ -103,7 +103,7 @@ impl SweepHalfEdge for Handle<HalfEdge> {
// Now, the boundaries of each edge. // Now, the boundaries of each edge.
let boundaries = { let boundaries = {
let [a, b] = geometry.boundary.inner; let [a, b] = half_edge_geom.boundary.inner;
let [c, d] = [0., 1.].map(|coord| Point::from([coord])); let [c, d] = [0., 1.].map(|coord| Point::from([coord]));
[[a, b], [c, d], [b, a], [d, c]] [[a, b], [c, d], [b, a], [d, c]]
@ -134,7 +134,7 @@ impl SweepHalfEdge for Handle<HalfEdge> {
}; };
half_edge.insert(core).set_geometry( half_edge.insert(core).set_geometry(
core.layers.geometry.of_half_edge(&line_segment), *core.layers.geometry.of_half_edge(&line_segment),
&mut core.layers.geometry, &mut core.layers.geometry,
) )
}; };

View File

@ -26,7 +26,7 @@ impl TransformObject for Handle<HalfEdge> {
core.layers.geometry.define_half_edge( core.layers.geometry.define_half_edge(
half_edge.clone(), half_edge.clone(),
core.layers.geometry.of_half_edge(self), *core.layers.geometry.of_half_edge(self),
); );
half_edge half_edge

View File

@ -150,18 +150,18 @@ impl ShellValidationError {
compare_curve_coords( compare_curve_coords(
edge_a, edge_a,
&geometry.of_surface(surface_a), geometry.of_surface(surface_a),
edge_b, edge_b,
&geometry.of_surface(surface_b), geometry.of_surface(surface_b),
geometry, geometry,
config, config,
&mut mismatches, &mut mismatches,
); );
compare_curve_coords( compare_curve_coords(
edge_b, edge_b,
&geometry.of_surface(surface_b), geometry.of_surface(surface_b),
edge_a, edge_a,
&geometry.of_surface(surface_a), geometry.of_surface(surface_a),
geometry, geometry,
config, config,
&mut mismatches, &mut mismatches,
@ -254,9 +254,9 @@ impl ShellValidationError {
// `distinct_min_distance`, that's a problem. // `distinct_min_distance`, that's a problem.
if distances( if distances(
half_edge_a.clone(), half_edge_a.clone(),
&geometry.of_surface(surface_a), geometry.of_surface(surface_a),
half_edge_b.clone(), half_edge_b.clone(),
&geometry.of_surface(surface_b), geometry.of_surface(surface_b),
geometry, geometry,
) )
.all(|d| d < config.distinct_min_distance) .all(|d| d < config.distinct_min_distance)
@ -453,7 +453,7 @@ mod tests {
cycle.update_half_edge( cycle.update_half_edge(
cycle.half_edges().nth_circular(0), cycle.half_edges().nth_circular(0),
|half_edge, core| { |half_edge, core| {
let mut geometry = core let mut geometry = *core
.layers .layers
.geometry .geometry
.of_half_edge(half_edge); .of_half_edge(half_edge);
@ -546,7 +546,8 @@ mod tests {
) )
.insert(core) .insert(core)
.set_geometry( .set_geometry(
core.layers *core
.layers
.geometry .geometry
.of_half_edge(half_edge), .of_half_edge(half_edge),
&mut core.layers.geometry, &mut core.layers.geometry,