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

Add BuildSurface::plane_from_uv #2239

Merged
merged 2 commits into from
Feb 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
18 changes: 5 additions & 13 deletions crates/fj-core/src/objects/stores.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use fj_math::Vector;

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

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

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

Self {
Expand Down
17 changes: 14 additions & 3 deletions crates/fj-core/src/operations/build/surface.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fj_math::{Point, Scalar};
use fj_math::{Point, Scalar, Vector};

use crate::{
geometry::{GlobalPath, SurfaceGeometry},
Expand All @@ -20,8 +20,7 @@ pub trait BuildSurface {
let (u, u_line) = GlobalPath::line_from_points([a, b]);
let v = c - a;

let geometry = SurfaceGeometry { u, v };
let surface = Surface::new(geometry);
let surface = Surface::plane_from_uv(u, v);

let points_surface = {
let [a, b] =
Expand All @@ -33,6 +32,18 @@ pub trait BuildSurface {

(surface, points_surface)
}

/// Build a plane from the provided `u` and `v`
fn plane_from_uv(
u: impl Into<GlobalPath>,
v: impl Into<Vector<3>>,
) -> Surface {
let geometry = SurfaceGeometry {
u: u.into(),
v: v.into(),
};
Surface::new(geometry)
}
}

impl BuildSurface for Surface {}
3 changes: 2 additions & 1 deletion crates/fj-core/src/operations/sweep/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use fj_math::{Circle, Line, Vector};
use crate::{
geometry::{GlobalPath, SurfaceGeometry, SurfacePath},
objects::Surface,
operations::build::BuildSurface,
};

/// # Sweep a [`SurfacePath`]
Expand Down Expand Up @@ -79,6 +80,6 @@ impl SweepSurfacePath for SurfacePath {
}
};

Surface::new(SurfaceGeometry { u, v: path.into() })
Surface::plane_from_uv(u, path)
}
}
52 changes: 26 additions & 26 deletions crates/fj-core/src/validate/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ impl SolidValidationError {
mod tests {
use crate::{
assert_contains_err,
geometry::{GlobalPath, SurfaceGeometry},
geometry::GlobalPath,
objects::{Cycle, Face, HalfEdge, Region, Shell, Solid, Surface},
operations::{
build::{BuildFace, BuildHalfEdge},
build::{BuildFace, BuildHalfEdge, BuildSurface},
insert::Insert,
},
validate::{
Expand All @@ -193,10 +193,10 @@ mod tests {
let mut core = Core::new();

let shared_face = Face::new(
Surface::new(SurfaceGeometry {
u: GlobalPath::circle_from_radius(1.),
v: [0., 1., 1.].into(),
})
Surface::plane_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 1., 1.],
)
.insert(&mut core),
Region::new(
Cycle::new(vec![
Expand Down Expand Up @@ -255,19 +255,19 @@ mod tests {

let invalid_solid = Solid::new(vec![Shell::new(vec![
Face::new(
Surface::new(SurfaceGeometry {
u: GlobalPath::circle_from_radius(1.),
v: [0., 1., 1.].into(),
})
Surface::plane_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 1., 1.],
)
.insert(&mut core),
shared_region.clone(),
)
.insert(&mut core),
Face::new(
Surface::new(SurfaceGeometry {
u: GlobalPath::circle_from_radius(1.),
v: [0., 0., 1.].into(),
})
Surface::plane_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 0., 1.],
)
.insert(&mut core),
shared_region.clone(),
)
Expand Down Expand Up @@ -304,19 +304,19 @@ mod tests {

let invalid_solid = Solid::new(vec![Shell::new(vec![
Face::new(
Surface::new(SurfaceGeometry {
u: GlobalPath::circle_from_radius(1.),
v: [0., 1., 1.].into(),
})
Surface::plane_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 1., 1.],
)
.insert(&mut core),
Region::new(shared_cycle.clone(), vec![]).insert(&mut core),
)
.insert(&mut core),
Face::new(
Surface::new(SurfaceGeometry {
u: GlobalPath::circle_from_radius(1.),
v: [0., 0., 1.].into(),
})
Surface::plane_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 0., 1.],
)
.insert(&mut core),
Region::new(shared_cycle, vec![]).insert(&mut core),
)
Expand Down Expand Up @@ -349,10 +349,10 @@ mod tests {
HalfEdge::circle([0., 0.], 1., &mut core).insert(&mut core);

let invalid_solid = Solid::new(vec![Shell::new(vec![Face::new(
Surface::new(SurfaceGeometry {
u: GlobalPath::circle_from_radius(1.),
v: [0., 0., 1.].into(),
})
Surface::plane_from_uv(
GlobalPath::circle_from_radius(1.),
[0., 0., 1.],
)
.insert(&mut core),
Region::new(
Cycle::new(vec![shared_edge.clone()]).insert(&mut core),
Expand Down