Merge pull request #2339 from hannobraun/geometry

Set curve geometry when transforming curve
This commit is contained in:
Hanno Braun 2024-04-30 12:47:38 +02:00 committed by GitHub
commit 5f648b031a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 12 deletions

View File

@ -108,10 +108,8 @@ impl Geometry {
/// ## Panics
///
/// Panics, if the geometry of the curve is not defined.
pub fn of_curve(&self, curve: &Handle<Curve>) -> &CurveGeom {
self.curve
.get(curve)
.expect("Expected geometry of half-edge to be defined")
pub fn of_curve(&self, curve: &Handle<Curve>) -> Option<&CurveGeom> {
self.curve.get(curve)
}
/// # Access the geometry of the provided half-edge

View File

@ -133,6 +133,7 @@ pub trait BuildHalfEdge {
.layers
.geometry
.of_curve(half_edge.curve())
.expect("Curve geometry was just defined in same function")
.local_on(&surface)
.path,
boundary: boundary.unwrap_or_default(),

View File

@ -107,6 +107,10 @@ pub trait BuildShell {
.layers
.geometry
.of_curve(&curve)
.expect(
"Curve geometry was just \
defined in same function",
)
.local_on(&surface)
.path,
boundary,

View File

@ -1,19 +1,41 @@
use fj_math::Transform;
use crate::{topology::Curve, Core};
use crate::{
operations::insert::Insert, storage::Handle, topology::Curve, Core,
};
use super::{TransformCache, TransformObject};
impl TransformObject for Curve {
impl TransformObject for Handle<Curve> {
fn transform_with_cache(
&self,
_: &Transform,
_: &mut Core,
_: &mut TransformCache,
core: &mut Core,
cache: &mut TransformCache,
) -> Self {
// There's nothing to actually transform here, as `Curve` holds no data.
// We still need this implementation though, as a new `Curve` object
// must be created to represent the new and transformed curve.
Self::new()
cache
.entry(self)
.or_insert_with(|| {
// We don't actually need to transform the curve, as its
// 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
})
.clone()
}
}