Merge pull request #2351 from hannobraun/geometry

Define curve geometry in `JoinCycle::join_to`
This commit is contained in:
Hanno Braun 2024-05-07 15:09:27 +02:00 committed by GitHub
commit 21e246efea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 152 additions and 108 deletions

View File

@ -166,7 +166,9 @@ pub trait BuildShell {
let [a, b, c, d] = points.map(Into::into); let [a, b, c, d] = points.map(Into::into);
let abc = Face::triangle([a, b, c], core); let abc = Face::triangle([a, b, c], core);
let bad = Face::triangle([b, a, d], core).update_region( let bad = {
let bad = Face::triangle([b, a, d], core);
bad.update_region(
|region, core| { |region, core| {
region.update_exterior( region.update_exterior(
|cycle, core| { |cycle, core| {
@ -174,8 +176,9 @@ pub trait BuildShell {
.update_half_edge( .update_half_edge(
cycle.half_edges().nth_circular(0), cycle.half_edges().nth_circular(0),
|edge, core| { |edge, core| {
[edge [edge.reverse_curve_coordinate_systems(
.reverse_curve_coordinate_systems(core)] core,
)]
}, },
core, core,
) )
@ -183,6 +186,7 @@ pub trait BuildShell {
abc.face.region().exterior(), abc.face.region().exterior(),
0..=0, 0..=0,
0..=0, 0..=0,
bad.face.surface().clone(),
core, core,
) )
}, },
@ -190,8 +194,12 @@ pub trait BuildShell {
) )
}, },
core, core,
); )
let dac = Face::triangle([d, a, c], core).update_region( };
let dac =
{
let dac = Face::triangle([d, a, c], core);
dac.update_region(
|region, core| { |region, core| {
region.update_exterior( region.update_exterior(
|cycle, core| { |cycle, core| {
@ -208,6 +216,7 @@ pub trait BuildShell {
abc.face.region().exterior(), abc.face.region().exterior(),
1..=1, 1..=1,
2..=2, 2..=2,
dac.face.surface().clone(),
core, core,
) )
.update_half_edge( .update_half_edge(
@ -222,6 +231,7 @@ pub trait BuildShell {
bad.face.region().exterior(), bad.face.region().exterior(),
0..=0, 0..=0,
1..=1, 1..=1,
dac.face.surface().clone(),
core, core,
) )
}, },
@ -229,8 +239,12 @@ pub trait BuildShell {
) )
}, },
core, core,
); )
let cbd = Face::triangle([c, b, d], core).update_region( };
let cbd =
{
let cbd = Face::triangle([c, b, d], core);
cbd.update_region(
|region, core| { |region, core| {
region.update_exterior( region.update_exterior(
|cycle, core| { |cycle, core| {
@ -263,18 +277,21 @@ pub trait BuildShell {
abc.face.region().exterior(), abc.face.region().exterior(),
0..=0, 0..=0,
1..=1, 1..=1,
cbd.face.surface().clone(),
core, core,
) )
.join_to( .join_to(
bad.face.region().exterior(), bad.face.region().exterior(),
1..=1, 1..=1,
2..=2, 2..=2,
cbd.face.surface().clone(),
core, core,
) )
.join_to( .join_to(
dac.face.region().exterior(), dac.face.region().exterior(),
2..=2, 2..=2,
2..=2, 2..=2,
cbd.face.surface().clone(),
core, core,
) )
}, },
@ -282,7 +299,8 @@ pub trait BuildShell {
) )
}, },
core, core,
); )
};
let triangles = let triangles =
[abc, bad, dac, cbd].map(|triangle| triangle.insert(core)); [abc, bad, dac, cbd].map(|triangle| triangle.insert(core));

View File

@ -84,6 +84,7 @@ pub trait JoinCycle {
other: &Cycle, other: &Cycle,
range: RangeInclusive<usize>, range: RangeInclusive<usize>,
other_range: RangeInclusive<usize>, other_range: RangeInclusive<usize>,
surface_self: Handle<Surface>,
core: &mut Core, core: &mut Core,
) -> Self; ) -> Self;
} }
@ -131,6 +132,7 @@ impl JoinCycle for Cycle {
other: &Cycle, other: &Cycle,
range: RangeInclusive<usize>, range: RangeInclusive<usize>,
range_other: RangeInclusive<usize>, range_other: RangeInclusive<usize>,
surface_self: Handle<Surface>,
core: &mut Core, core: &mut Core,
) -> Self { ) -> Self {
assert_eq!( assert_eq!(
@ -148,6 +150,30 @@ impl JoinCycle for Cycle {
.update_half_edge( .update_half_edge(
self.half_edges().nth_circular(index), self.half_edges().nth_circular(index),
|half_edge, core| { |half_edge, core| {
// The curve of the other half-edge we're joining
// this one to already has a curve geometry,
// presumably. But it might not have a local
// definition for the surface that *this* half-edge
// is in.
//
// We need to make sure that any local definition
// that our current curve already has, moves over to
// the new one.
let curve_geom = core
.layers
.geometry
.of_curve(half_edge.curve())
.and_then(|curve_geom| {
curve_geom.local_on(&surface_self)
});
if let Some(curve_geom) = curve_geom {
core.layers.geometry.define_curve(
edge_other.curve().clone(),
surface_self.clone(),
curve_geom.clone(),
);
}
[half_edge [half_edge
.update_curve( .update_curve(
|_, _| edge_other.curve().clone(), |_, _| edge_other.curve().clone(),