Skip to content

Commit

Permalink
Prepare SurfaceGeom for better geometry repr
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Jul 26, 2024
1 parent 2ca54ec commit 5beee30
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
8 changes: 4 additions & 4 deletions crates/fj-core/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn approx_curve(
boundary: CurveBoundary<Point<1>>,
tolerance: impl Into<Tolerance>,
) -> CurveApprox {
let SurfaceGeom { u, .. } = surface;
let SurfaceGeom::Basic { u, .. } = surface;
let points = match (path, u) {
(SurfacePath::Circle(_), GlobalPath::Circle(_)) => {
approx_circle_on_curved_surface()
Expand Down Expand Up @@ -111,7 +111,7 @@ fn approx_line_on_any_surface(
.map(|point_curve| [line.point_from_line_coords(point_curve).u]),
);

let SurfaceGeom { u, .. } = surface;
let SurfaceGeom::Basic { u, .. } = surface;
let approx_u = match u {
GlobalPath::Circle(circle) => approx_circle(circle, range_u, tolerance),
GlobalPath::Line(line) => approx_line(line),
Expand Down Expand Up @@ -216,7 +216,7 @@ mod tests {

#[test]
fn approx_line_on_curved_surface_but_not_along_curve() {
let surface = SurfaceGeom {
let surface = SurfaceGeom::Basic {
u: GlobalPath::circle_from_radius(1.),
v: Vector::from([0., 0., 1.]),
};
Expand All @@ -236,7 +236,7 @@ mod tests {

let circle = Circle::from_center_and_radius(Point::origin(), 1.);
let global_path = GlobalPath::Circle(circle);
let surface_geom = SurfaceGeom {
let surface_geom = SurfaceGeom::Basic {
u: global_path,
v: Vector::from([0., 0., 1.]),
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/algorithms/bounding_volume/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl super::BoundingVolume<3> for &Face {
.map(|aabb2| {
let surface = geometry.of_surface(self.surface());

let SurfaceGeom { u, v } = surface;
let SurfaceGeom::Basic { u, v } = surface;
match u {
GlobalPath::Circle(circle) => {
// This is not the most precise way to calculate the
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-core/src/geometry/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ impl Geometry {

self_.define_surface_inner(
self_.xy_plane.clone(),
SurfaceGeom {
SurfaceGeom::Basic {
u: GlobalPath::x_axis(),
v: Vector::unit_y(),
},
);
self_.define_surface_inner(
self_.xz_plane.clone(),
SurfaceGeom {
SurfaceGeom::Basic {
u: GlobalPath::x_axis(),
v: Vector::unit_z(),
},
);
self_.define_surface_inner(
self_.yz_plane.clone(),
SurfaceGeom {
SurfaceGeom::Basic {
u: GlobalPath::y_axis(),
v: Vector::unit_z(),
},
Expand Down
39 changes: 25 additions & 14 deletions crates/fj-core/src/geometry/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ use super::GlobalPath;

/// The geometry that defines a surface
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct SurfaceGeom {
/// The u-axis of the surface
pub u: GlobalPath,

/// The v-axis of the surface
pub v: Vector<3>,
pub enum SurfaceGeom {
/// # Basic definition of surface geometry
///
/// ## Implementation Note
///
/// At the time of writing, this is the sole variant of `SurfaceGeom`.
/// `SurfaceGeom` simply used to be a struct, identical to this variant.
///
/// This was changed as part of a transition to a new, less basic and more
/// flexible, representation of surface geometry.
Basic {
/// The u-axis of the surface
u: GlobalPath,

/// The v-axis of the surface
v: Vector<3>,
},
}

impl SurfaceGeom {
Expand All @@ -21,7 +32,7 @@ impl SurfaceGeom {
point: impl Into<Point<2>>,
) -> Point<3> {
let point = point.into();
let Self { u, .. } = self;
let Self::Basic { u, .. } = self;
u.point_from_path_coords([point.u])
+ self.path_to_line().vector_from_line_coords([point.v])
}
Expand All @@ -32,19 +43,19 @@ impl SurfaceGeom {
vector: impl Into<Vector<2>>,
) -> Vector<3> {
let vector = vector.into();
let Self { u, .. } = self;
let Self::Basic { u, .. } = self;
u.vector_from_path_coords([vector.u])
+ self.path_to_line().vector_from_line_coords([vector.v])
}

fn path_to_line(&self) -> Line<3> {
let Self { u, v } = self;
let Self::Basic { u, v } = self;
Line::from_origin_and_direction(u.origin(), *v)
}

/// Project the global point into the surface
pub fn project_global_point(&self, point: impl Into<Point<3>>) -> Point<2> {
let Self { u, v } = self;
let Self::Basic { u, v } = self;

let GlobalPath::Line(line) = u else {
todo!("Projecting point into non-plane surface is not supported")
Expand All @@ -57,11 +68,11 @@ impl SurfaceGeom {
/// Transform the surface geometry
#[must_use]
pub fn transform(self, transform: &Transform) -> Self {
let Self { u, v } = self;
let Self::Basic { u, v } = self;

let u = u.transform(transform);
let v = transform.transform_vector(&v);
Self { u, v }
Self::Basic { u, v }
}
}

Expand All @@ -74,7 +85,7 @@ mod tests {

#[test]
fn point_from_surface_coords() {
let surface = SurfaceGeom {
let surface = SurfaceGeom::Basic {
u: GlobalPath::Line(Line::from_origin_and_direction(
Point::from([1., 1., 1.]),
Vector::from([0., 2., 0.]),
Expand All @@ -90,7 +101,7 @@ mod tests {

#[test]
fn vector_from_surface_coords() {
let surface = SurfaceGeom {
let surface = SurfaceGeom::Basic {
u: GlobalPath::Line(Line::from_origin_and_direction(
Point::from([1., 0., 0.]),
Vector::from([0., 2., 0.]),
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/build/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub trait BuildSurface {
core: &mut Core,
) -> Handle<Surface> {
Self::from_geometry(
SurfaceGeom {
SurfaceGeom::Basic {
u: u.into(),
v: v.into(),
},
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/sweep/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl SweepSurfacePath for SurfacePath {
path: impl Into<Vector<3>>,
core: &mut Core,
) -> Handle<Surface> {
let SurfaceGeom { u, .. } = surface;
let SurfaceGeom::Basic { u, .. } = surface;
match u {
GlobalPath::Circle(_) => {
// Sweeping a `Curve` creates a `Surface`. The u-axis of that
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/sweep/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl SweepSketch for Sketch {
.winding(&core.layers.geometry, self.surface())
.is_ccw());

let SurfaceGeom { u, v } =
let SurfaceGeom::Basic { u, v } =
core.layers.geometry.of_surface(&surface);

let is_negative_sweep = {
Expand Down

0 comments on commit 5beee30

Please sign in to comment.