Merge pull request #2340 from hannobraun/geometry

Set curve geometry in shell validation test
This commit is contained in:
Hanno Braun 2024-04-30 13:20:34 +02:00 committed by GitHub
commit eb6ac63e03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 21 deletions

View File

@ -10,6 +10,13 @@ use crate::{
/// Update the geometry of a [`Curve`]
pub trait UpdateCurveGeometry {
/// Copy the geometry of the provided curve
fn copy_geometry_from(
self,
curve: &Handle<Curve>,
geometry: &mut Layer<Geometry>,
) -> Self;
/// Define the geometry as a path on a surface
fn make_path_on_surface(
self,
@ -35,6 +42,21 @@ pub trait UpdateCurveGeometry {
}
impl UpdateCurveGeometry for Handle<Curve> {
fn copy_geometry_from(
self,
curve: &Handle<Curve>,
geometry: &mut Layer<Geometry>,
) -> Self {
let curve_geom = geometry.of_curve(curve).cloned();
if let Some(curve_geom) = curve_geom {
for (surface, local_definition) in curve_geom.definitions {
geometry.define_curve(self.clone(), surface, local_definition);
}
}
self
}
fn make_path_on_surface(
self,
path: SurfacePath,

View File

@ -1,7 +1,10 @@
use fj_math::Transform;
use crate::{
operations::insert::Insert, storage::Handle, topology::Curve, Core,
operations::{geometry::UpdateCurveGeometry, insert::Insert},
storage::Handle,
topology::Curve,
Core,
};
use super::{TransformCache, TransformObject};
@ -20,21 +23,9 @@ impl TransformObject for Handle<Curve> {
// geometry is locally defined on a surface. We need to set that
// geometry for the new object though, that we created here to
// represent the transformed curve.
let curve = Curve::new().insert(core);
let curve_geom = core.layers.geometry.of_curve(self).cloned();
if let Some(curve_geom) = curve_geom {
for (surface, local_definition) in curve_geom.definitions {
core.layers.geometry.define_curve(
curve.clone(),
surface,
local_definition,
);
}
}
curve
Curve::new()
.insert(core)
.copy_geometry_from(self, &mut core.layers.geometry)
})
.clone()
}

View File

@ -423,7 +423,7 @@ mod tests {
assert_contains_err,
operations::{
build::BuildShell,
geometry::UpdateHalfEdgeGeometry,
geometry::{UpdateCurveGeometry, UpdateHalfEdgeGeometry},
insert::Insert,
update::{
UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateRegion,
@ -539,11 +539,15 @@ mod tests {
cycle.update_half_edge(
cycle.half_edges().nth_circular(0),
|half_edge, core| {
let curve = Curve::new()
.insert(core)
.copy_geometry_from(
half_edge.curve(),
&mut core.layers.geometry,
);
[half_edge
.update_curve(
|_, _| Curve::new(),
core,
)
.update_curve(|_, _| curve, core)
.insert(core)
.set_geometry(
*core