Skip to content

Commit

Permalink
Provide surface to BuildHalfEdge methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Apr 26, 2024
1 parent 143e12b commit 23684c2
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 20 deletions.
17 changes: 13 additions & 4 deletions crates/fj-core/src/operations/build/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ pub trait BuildCycle {
fn circle(
center: impl Into<Point<2>>,
radius: impl Into<Scalar>,
_: Handle<Surface>,
surface: Handle<Surface>,
core: &mut Core,
) -> Cycle {
let circle = HalfEdge::circle(center, radius, core);
let circle = HalfEdge::circle(center, radius, surface, core);
Cycle::empty().add_half_edges([circle], core)
}

/// Build a polygon
fn polygon<P, Ps>(points: Ps, _: Handle<Surface>, core: &mut Core) -> Cycle
fn polygon<P, Ps>(
points: Ps,
surface: Handle<Surface>,
core: &mut Core,
) -> Cycle
where
P: Into<Point<2>>,
Ps: IntoIterator<Item = P>,
Expand All @@ -42,7 +46,12 @@ pub trait BuildCycle {
.map(Into::into)
.circular_tuple_windows()
.map(|(start, end)| {
HalfEdge::line_segment([start, end], None, core)
HalfEdge::line_segment(
[start, end],
None,
surface.clone(),
core,
)
});

Cycle::new(edges)
Expand Down
5 changes: 4 additions & 1 deletion crates/fj-core/src/operations/build/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
geometry::{HalfEdgeGeom, SurfacePath},
operations::{geometry::UpdateHalfEdgeGeometry, insert::Insert},
storage::Handle,
topology::{Curve, HalfEdge, Vertex},
topology::{Curve, HalfEdge, Surface, Vertex},
Core,
};

Expand Down Expand Up @@ -46,6 +46,7 @@ pub trait BuildHalfEdge {
start: impl Into<Point<2>>,
end: impl Into<Point<2>>,
angle_rad: impl Into<Scalar>,
_: Handle<Surface>,
core: &mut Core,
) -> Handle<HalfEdge> {
let angle_rad = angle_rad.into();
Expand Down Expand Up @@ -76,6 +77,7 @@ pub trait BuildHalfEdge {
fn circle(
center: impl Into<Point<2>>,
radius: impl Into<Scalar>,
_: Handle<Surface>,
core: &mut Core,
) -> Handle<HalfEdge> {
let path = SurfacePath::circle_from_center_and_radius(center, radius);
Expand All @@ -98,6 +100,7 @@ pub trait BuildHalfEdge {
fn line_segment(
points_surface: [impl Into<Point<2>>; 2],
boundary: Option<[Point<1>; 2]>,
_: Handle<Surface>,
core: &mut Core,
) -> Handle<HalfEdge> {
let boundary =
Expand Down
1 change: 1 addition & 0 deletions crates/fj-core/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub trait BuildShell {
let half_edge = HalfEdge::line_segment(
positions,
Some(boundary.reverse().inner),
surface.clone(),
core,
);
half_edge
Expand Down
14 changes: 12 additions & 2 deletions crates/fj-core/src/operations/holes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ impl AddHole for Shell {
path: impl Into<Vector<3>>,
core: &mut Core,
) -> Self {
let entry = HalfEdge::circle(location.position, radius, core);
let entry = HalfEdge::circle(
location.position,
radius,
location.face.surface().clone(),
core,
);
let hole = Region::empty(core)
.update_exterior(
|_, core| Cycle::empty().add_half_edges([entry.clone()], core),
Expand Down Expand Up @@ -91,7 +96,12 @@ impl AddHole for Shell {
) -> Self {
let radius = radius.into();

let entry = HalfEdge::circle(entry_location.position, radius, core);
let entry = HalfEdge::circle(
entry_location.position,
radius,
entry_location.face.surface().clone(),
core,
);

let path = {
let point = |location: &HoleLocation| {
Expand Down
1 change: 1 addition & 0 deletions crates/fj-core/src/operations/split/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl SplitFace for Shell {
core.layers.geometry.of_half_edge(&d).start_position(),
],
None,
face.surface().clone(),
core,
);
half_edge
Expand Down
1 change: 1 addition & 0 deletions crates/fj-core/src/operations/sweep/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ impl SweepHalfEdge for Handle<HalfEdge> {
let line_segment = HalfEdge::line_segment(
[start, end],
Some(boundary),
surface.clone(),
core,
);
let half_edge = line_segment
Expand Down
9 changes: 6 additions & 3 deletions crates/fj-core/src/validate/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ mod tests {

let surface = core.layers.topology.surfaces.space_2d();

let valid_outer_circle = HalfEdge::circle([0., 0.], 1., &mut core);
let valid_outer_circle =
HalfEdge::circle([0., 0.], 1., surface.clone(), &mut core);
let valid_exterior =
Cycle::new(vec![valid_outer_circle.clone()]).insert(&mut core);
let valid_sketch = Sketch::new(
Expand Down Expand Up @@ -259,8 +260,10 @@ mod tests {

let surface = core.layers.topology.surfaces.space_2d();

let outer_circle = HalfEdge::circle([0., 0.], 2., &mut core);
let inner_circle = HalfEdge::circle([0., 0.], 1., &mut core);
let outer_circle =
HalfEdge::circle([0., 0.], 2., surface.clone(), &mut core);
let inner_circle =
HalfEdge::circle([0., 0.], 1., surface.clone(), &mut core);
let cw_inner_circle = HalfEdge::from_sibling(
&inner_circle,
Vertex::new().insert(&mut core),
Expand Down
35 changes: 27 additions & 8 deletions crates/fj-core/src/validate/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,13 @@ mod tests {
&mut core,
),
Region::new(
Cycle::new(vec![HalfEdge::circle([0., 0.], 1., &mut core)])
.insert(&mut core),
Cycle::new(vec![HalfEdge::circle(
[0., 0.],
1.,
core.layers.topology.surfaces.space_2d(),
&mut core,
)])
.insert(&mut core),
vec![],
)
.insert(&mut core),
Expand Down Expand Up @@ -249,8 +254,13 @@ mod tests {
let mut core = Core::new();

let shared_region = Region::new(
Cycle::new(vec![HalfEdge::circle([0., 0.], 1., &mut core)])
.insert(&mut core),
Cycle::new(vec![HalfEdge::circle(
[0., 0.],
1.,
core.layers.topology.surfaces.space_2d(),
&mut core,
)])
.insert(&mut core),
vec![],
)
.insert(&mut core);
Expand Down Expand Up @@ -299,9 +309,13 @@ mod tests {
fn should_find_cycle_multiple_references() -> anyhow::Result<()> {
let mut core = Core::new();

let shared_cycle =
Cycle::new(vec![HalfEdge::circle([0., 0.], 1., &mut core)])
.insert(&mut core);
let shared_cycle = Cycle::new(vec![HalfEdge::circle(
[0., 0.],
1.,
core.layers.topology.surfaces.space_2d(),
&mut core,
)])
.insert(&mut core);

let invalid_solid = Solid::new(vec![Shell::new(vec![
Face::new(
Expand Down Expand Up @@ -347,7 +361,12 @@ mod tests {
fn should_find_half_edge_multiple_references() -> anyhow::Result<()> {
let mut core = Core::new();

let shared_edge = HalfEdge::circle([0., 0.], 1., &mut core);
let shared_edge = HalfEdge::circle(
[0., 0.],
1.,
core.layers.topology.surfaces.space_2d(),
&mut core,
);

let invalid_solid = Solid::new(vec![Shell::new(vec![Face::new(
Surface::from_uv(
Expand Down
8 changes: 6 additions & 2 deletions crates/fj-core/src/validation/checks/half_edge_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ mod tests {

// We're only testing for `Face` here, not `Sketch`. Should be fine, as
// most of the code is shared.
let valid =
Face::polygon(surface, [[0., 0.], [1., 0.], [1., 1.]], &mut core);
let valid = Face::polygon(
surface.clone(),
[[0., 0.], [1., 0.], [1., 1.]],
&mut core,
);
AdjacentHalfEdgesNotConnected::check_and_return_first_error(
&valid,
&core.layers.geometry,
Expand All @@ -164,6 +167,7 @@ mod tests {
[HalfEdge::line_segment(
[[0., 0.], [2., 0.]],
None,
surface,
core,
)]
},
Expand Down

0 comments on commit 23684c2

Please sign in to comment.