Skip to content

Commit

Permalink
Merge pull request #2340 from hannobraun/geometry
Browse files Browse the repository at this point in the history
Set curve geometry in shell validation test
  • Loading branch information
hannobraun authored Apr 30, 2024
2 parents 5f648b0 + b345881 commit eb6ac63
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
22 changes: 22 additions & 0 deletions crates/fj-core/src/operations/geometry/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
23 changes: 7 additions & 16 deletions crates/fj-core/src/operations/transform/curve.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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()
}
Expand Down
14 changes: 9 additions & 5 deletions crates/fj-core/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ mod tests {
assert_contains_err,
operations::{
build::BuildShell,
geometry::UpdateHalfEdgeGeometry,
geometry::{UpdateCurveGeometry, UpdateHalfEdgeGeometry},
insert::Insert,
update::{
UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateRegion,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eb6ac63

Please sign in to comment.