Skip to content

Commit

Permalink
Merge pull request #2415 from hannobraun/split
Browse files Browse the repository at this point in the history
Implement `SplitHalfEdge` for `Cycle`
  • Loading branch information
hannobraun authored Jul 9, 2024
2 parents ff1e7e6 + 5110eeb commit 3ba6cd8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
9 changes: 6 additions & 3 deletions crates/fj-core/src/operations/split/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
geometry::UpdateHalfEdgeGeometry, insert::Insert,
replace::ReplaceHalfEdge, split::SplitHalfEdge, update::UpdateHalfEdge,
},
queries::SiblingOfHalfEdge,
queries::{CycleOfHalfEdge, SiblingOfHalfEdge},
storage::Handle,
topology::{HalfEdge, Shell},
Core,
Expand Down Expand Up @@ -40,11 +40,14 @@ impl SplitEdge for Shell {
.get_sibling_of(half_edge)
.expect("Expected half-edge and its sibling to be part of shell");

let [half_edge_a, half_edge_b] = half_edge.split_half_edge(point, core);
let [half_edge_a, half_edge_b] = self
.find_cycle_of_half_edge(half_edge)
.expect("Expected half-edge to be part of shell")
.split_half_edge(half_edge, point, core);

let siblings = {
let [sibling_a, sibling_b] =
sibling.sibling.split_half_edge(point, core);
sibling.cycle.split_half_edge(&sibling.sibling, point, core);
let sibling_b = sibling_b
.update_start_vertex(
|_, _| half_edge_b.start_vertex().clone(),
Expand Down
43 changes: 25 additions & 18 deletions crates/fj-core/src/operations/split/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
derive::DeriveFrom, geometry::UpdateHalfEdgeGeometry, insert::Insert,
},
storage::Handle,
topology::{HalfEdge, Vertex},
topology::{Cycle, HalfEdge, Vertex},
Core,
};

Expand All @@ -30,37 +30,44 @@ pub trait SplitHalfEdge {
#[must_use]
fn split_half_edge(
&self,
half_edge: &Handle<HalfEdge>,
point: impl Into<Point<1>>,
core: &mut Core,
) -> [Handle<HalfEdge>; 2];
}

impl SplitHalfEdge for Handle<HalfEdge> {
impl SplitHalfEdge for Cycle {
fn split_half_edge(
&self,
half_edge: &Handle<HalfEdge>,
point: impl Into<Point<1>>,
core: &mut Core,
) -> [Handle<HalfEdge>; 2] {
let point = point.into();

let geometry = *core.layers.geometry.of_half_edge(self);
let geometry = *core.layers.geometry.of_half_edge(half_edge);
let [start, end] = geometry.boundary.inner;

let a =
HalfEdge::new(self.curve().clone(), self.start_vertex().clone())
.insert(core)
.derive_from(self, core)
.set_geometry(
geometry.with_boundary([start, point]),
&mut core.layers.geometry,
);
let b = HalfEdge::new(self.curve().clone(), Vertex::new().insert(core))
.insert(core)
.derive_from(self, core)
.set_geometry(
geometry.with_boundary([point, end]),
&mut core.layers.geometry,
);
let a = HalfEdge::new(
half_edge.curve().clone(),
half_edge.start_vertex().clone(),
)
.insert(core)
.derive_from(half_edge, core)
.set_geometry(
geometry.with_boundary([start, point]),
&mut core.layers.geometry,
);
let b = HalfEdge::new(
half_edge.curve().clone(),
Vertex::new().insert(core),
)
.insert(core)
.derive_from(half_edge, core)
.set_geometry(
geometry.with_boundary([point, end]),
&mut core.layers.geometry,
);

core.layers.geometry.define_vertex(
b.start_vertex().clone(),
Expand Down

0 comments on commit 3ba6cd8

Please sign in to comment.