Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define curve geometry when building half-edges #2325

Merged
merged 8 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions crates/fj-core/src/algorithms/triangulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,19 @@ mod tests {
let c = [2., 2.];
let d = [0., 1.];

let face =
Face::unbound(core.layers.topology.surfaces.xy_plane(), &mut core)
.update_region(
|region, core| {
region.update_exterior(
|_, core| Cycle::polygon([a, b, c, d], core),
core,
)
},
&mut core,
)
.insert(&mut core);
let surface = core.layers.topology.surfaces.xy_plane();

let face = Face::unbound(surface.clone(), &mut core)
.update_region(
|region, core| {
region.update_exterior(
|_, core| Cycle::polygon([a, b, c, d], surface, core),
core,
)
},
&mut core,
)
.insert(&mut core);

let a = Point::from(a).to_xyz();
let b = Point::from(b).to_xyz();
Expand Down Expand Up @@ -151,11 +152,21 @@ mod tests {
|region, core| {
region
.update_exterior(
|_, core| Cycle::polygon([a, b, c, d], core),
|_, core| {
Cycle::polygon(
[a, b, c, d],
surface.clone(),
core,
)
},
core,
)
.add_interiors(
[Cycle::polygon([e, f, g, h], core)],
[Cycle::polygon(
[e, f, g, h],
surface.clone(),
core,
)],
core,
)
},
Expand Down Expand Up @@ -244,7 +255,13 @@ mod tests {
.update_region(
|region, core| {
region.update_exterior(
|_, core| Cycle::polygon([a, b, c, d, e], core),
|_, core| {
Cycle::polygon(
[a, b, c, d, e],
surface.clone(),
core,
)
},
core,
)
},
Expand Down
19 changes: 15 additions & 4 deletions crates/fj-core/src/operations/build/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use itertools::Itertools;

use crate::{
operations::{build::BuildHalfEdge, update::UpdateCycle},
topology::{Cycle, HalfEdge},
storage::Handle,
topology::{Cycle, HalfEdge, Surface},
Core,
};

Expand All @@ -22,14 +23,19 @@ pub trait BuildCycle {
fn circle(
center: impl Into<Point<2>>,
radius: impl Into<Scalar>,
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, 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 @@ -40,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
6 changes: 4 additions & 2 deletions crates/fj-core/src/operations/build/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub trait BuildFace {
radius: impl Into<Scalar>,
core: &mut Core,
) -> Face {
let region = Region::circle(center, radius, core).insert(core);
let region =
Region::circle(center, radius, surface.clone(), core).insert(core);
Face::new(surface, region)
}

Expand Down Expand Up @@ -81,7 +82,8 @@ pub trait BuildFace {
Ps: IntoIterator<Item = P>,
Ps::IntoIter: Clone + ExactSizeIterator,
{
let region = Region::polygon(points, core).insert(core);
let region =
Region::polygon(points, surface.clone(), core).insert(core);
Face::new(surface, region)
}
}
Expand Down
21 changes: 19 additions & 2 deletions crates/fj-core/src/operations/build/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use fj_interop::ext::ArrayExt;
use fj_math::{Arc, Point, Scalar};

use crate::{
geometry::{HalfEdgeGeom, SurfacePath},
geometry::{CurveGeom, 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>,
surface: Handle<Surface>,
core: &mut Core,
) -> Handle<HalfEdge> {
let angle_rad = angle_rad.into();
Expand All @@ -61,6 +62,11 @@ pub trait BuildHalfEdge {
[arc.start_angle, arc.end_angle].map(|coord| Point::from([coord]));

let half_edge = HalfEdge::unjoined(core).insert(core);

core.layers.geometry.define_curve(
half_edge.curve().clone(),
CurveGeom::from_path_and_surface(path, surface),
);
core.layers.geometry.define_half_edge(
half_edge.clone(),
HalfEdgeGeom {
Expand All @@ -76,13 +82,19 @@ pub trait BuildHalfEdge {
fn circle(
center: impl Into<Point<2>>,
radius: impl Into<Scalar>,
surface: Handle<Surface>,
core: &mut Core,
) -> Handle<HalfEdge> {
let path = SurfacePath::circle_from_center_and_radius(center, radius);
let boundary =
[Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord]));

let half_edge = HalfEdge::unjoined(core).insert(core);

core.layers.geometry.define_curve(
half_edge.curve().clone(),
CurveGeom::from_path_and_surface(path, surface),
);
core.layers.geometry.define_half_edge(
half_edge.clone(),
HalfEdgeGeom {
Expand All @@ -98,6 +110,7 @@ pub trait BuildHalfEdge {
fn line_segment(
points_surface: [impl Into<Point<2>>; 2],
boundary: Option<[Point<1>; 2]>,
surface: Handle<Surface>,
core: &mut Core,
) -> Handle<HalfEdge> {
let boundary =
Expand All @@ -108,6 +121,10 @@ pub trait BuildHalfEdge {

let half_edge = HalfEdge::unjoined(core).insert(core);

core.layers.geometry.define_curve(
half_edge.curve().clone(),
CurveGeom::from_path_and_surface(path, surface),
);
core.layers.geometry.define_half_edge(
half_edge.clone(),
HalfEdgeGeom {
Expand Down
15 changes: 11 additions & 4 deletions crates/fj-core/src/operations/build/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use fj_math::{Point, Scalar};

use crate::{
operations::{build::BuildCycle, insert::Insert},
topology::{Cycle, Region},
storage::Handle,
topology::{Cycle, Region, Surface},
Core,
};

Expand All @@ -24,20 +25,26 @@ pub trait BuildRegion {
fn circle(
center: impl Into<Point<2>>,
radius: impl Into<Scalar>,
surface: Handle<Surface>,
core: &mut Core,
) -> Region {
let exterior = Cycle::circle(center, radius, core).insert(core);
let exterior =
Cycle::circle(center, radius, surface, core).insert(core);
Region::new(exterior, [])
}

/// Build a polygon
fn polygon<P, Ps>(points: Ps, core: &mut Core) -> Region
fn polygon<P, Ps>(
points: Ps,
surface: Handle<Surface>,
core: &mut Core,
) -> Region
where
P: Into<Point<2>>,
Ps: IntoIterator<Item = P>,
Ps::IntoIter: Clone + ExactSizeIterator,
{
let exterior = Cycle::polygon(points, core).insert(core);
let exterior = Cycle::polygon(points, surface, core).insert(core);
Region::new(exterior, [])
}
}
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
Loading