Skip to content

Commit

Permalink
Merge pull request hannobraun#2241 from hannobraun/surface
Browse files Browse the repository at this point in the history
Return `Handle<Surface>` from `BuildSurface` methods
  • Loading branch information
hannobraun authored Feb 27, 2024
2 parents 51b96b7 + 0dddf0d commit fb77fed
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 29 deletions.
18 changes: 13 additions & 5 deletions crates/fj-core/src/objects/stores.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use fj_math::Vector;

use crate::{
geometry::GlobalPath,
operations::build::BuildSurface,
geometry::{GlobalPath, SurfaceGeometry},
storage::{Handle, Store},
};

Expand Down Expand Up @@ -95,18 +94,27 @@ impl Default for Surfaces {
let xy_plane = store.reserve();
store.insert(
xy_plane.clone(),
Surface::surface_from_uv(GlobalPath::x_axis(), Vector::unit_y()),
Surface::new(SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_y(),
}),
);

let xz_plane = store.reserve();
store.insert(
xz_plane.clone(),
Surface::surface_from_uv(GlobalPath::x_axis(), Vector::unit_z()),
Surface::new(SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_z(),
}),
);
let yz_plane = store.reserve();
store.insert(
yz_plane.clone(),
Surface::surface_from_uv(GlobalPath::y_axis(), Vector::unit_z()),
Surface::new(SurfaceGeometry {
u: GlobalPath::y_axis(),
v: Vector::unit_z(),
}),
);

Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/build/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub trait BuildFace {
points: [impl Into<Point<3>>; 3],
core: &mut Core,
) -> Polygon<3> {
let (surface, points_surface) = Surface::plane_from_points(points);
let surface = surface.insert(core);
let (surface, points_surface) =
Surface::plane_from_points(points, core);

let face = Face::polygon(surface, points_surface, core);

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pub trait BuildShell {

let (surface, _) = Surface::plane_from_points(
[a_pos, b_pos, c_pos].map(Clone::clone),
core,
);
let surface = surface.insert(core);

let curves_and_boundaries =
[[a, b], [b, c], [c, a]].map(|vertices| {
Expand Down
13 changes: 9 additions & 4 deletions crates/fj-core/src/operations/build/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use fj_math::{Point, Scalar, Vector};
use crate::{
geometry::{GlobalPath, SurfaceGeometry},
objects::Surface,
operations::insert::Insert,
storage::Handle,
Core,
};

/// Build a [`Surface`]
Expand All @@ -14,13 +17,14 @@ pub trait BuildSurface {
/// Build a plane from the provided points
fn plane_from_points(
points: [impl Into<Point<3>>; 3],
) -> (Surface, [Point<2>; 3]) {
core: &mut Core,
) -> (Handle<Surface>, [Point<2>; 3]) {
let [a, b, c] = points.map(Into::into);

let (u, u_line) = GlobalPath::line_from_points([a, b]);
let v = c - a;

let surface = Surface::surface_from_uv(u, v);
let surface = Surface::surface_from_uv(u, v, core);

let points_surface = {
let [a, b] =
Expand All @@ -37,12 +41,13 @@ pub trait BuildSurface {
fn surface_from_uv(
u: impl Into<GlobalPath>,
v: impl Into<Vector<3>>,
) -> Surface {
core: &mut Core,
) -> Handle<Surface> {
let geometry = SurfaceGeometry {
u: u.into(),
v: v.into(),
};
Surface::new(geometry)
Surface::new(geometry).insert(core)
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/fj-core/src/operations/sweep/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ impl SweepHalfEdge for HalfEdge {
) -> (Face, Handle<HalfEdge>) {
let path = path.into();

let surface =
self.path().sweep_surface_path(surface, path).insert(core);
let surface = self.path().sweep_surface_path(surface, path, core);

// Next, we need to define the boundaries of the face. Let's start with
// the global vertices and edges.
Expand Down
10 changes: 7 additions & 3 deletions crates/fj-core/src/operations/sweep/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::{
geometry::{GlobalPath, SurfaceGeometry, SurfacePath},
objects::Surface,
operations::build::BuildSurface,
storage::Handle,
Core,
};

/// # Sweep a [`SurfacePath`]
Expand All @@ -26,15 +28,17 @@ pub trait SweepSurfacePath {
&self,
surface: &SurfaceGeometry,
path: impl Into<Vector<3>>,
) -> Surface;
core: &mut Core,
) -> Handle<Surface>;
}

impl SweepSurfacePath for SurfacePath {
fn sweep_surface_path(
&self,
surface: &SurfaceGeometry,
path: impl Into<Vector<3>>,
) -> Surface {
core: &mut Core,
) -> Handle<Surface> {
match surface.u {
GlobalPath::Circle(_) => {
// Sweeping a `Curve` creates a `Surface`. The u-axis of that
Expand Down Expand Up @@ -80,6 +84,6 @@ impl SweepSurfacePath for SurfacePath {
}
};

Surface::surface_from_uv(u, path)
Surface::surface_from_uv(u, path, core)
}
}
24 changes: 12 additions & 12 deletions crates/fj-core/src/validate/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ mod tests {
Surface::surface_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 1., 1.],
)
.insert(&mut core),
&mut core,
),
Region::new(
Cycle::new(vec![
HalfEdge::circle([0., 0.], 1., &mut core).insert(&mut core)
Expand Down Expand Up @@ -258,17 +258,17 @@ mod tests {
Surface::surface_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 1., 1.],
)
.insert(&mut core),
&mut core,
),
shared_region.clone(),
)
.insert(&mut core),
Face::new(
Surface::surface_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 0., 1.],
)
.insert(&mut core),
&mut core,
),
shared_region.clone(),
)
.insert(&mut core),
Expand Down Expand Up @@ -307,17 +307,17 @@ mod tests {
Surface::surface_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 1., 1.],
)
.insert(&mut core),
&mut core,
),
Region::new(shared_cycle.clone(), vec![]).insert(&mut core),
)
.insert(&mut core),
Face::new(
Surface::surface_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 0., 1.],
)
.insert(&mut core),
&mut core,
),
Region::new(shared_cycle, vec![]).insert(&mut core),
)
.insert(&mut core),
Expand Down Expand Up @@ -352,8 +352,8 @@ mod tests {
Surface::surface_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 0., 1.],
)
.insert(&mut core),
&mut core,
),
Region::new(
Cycle::new(vec![shared_edge.clone()]).insert(&mut core),
vec![Cycle::new(vec![shared_edge.clone()]).insert(&mut core)],
Expand Down

0 comments on commit fb77fed

Please sign in to comment.