diff --git a/crates/fj-core/src/algorithms/approx/curve.rs b/crates/fj-core/src/algorithms/approx/curve.rs index 084849d07..1808f139b 100644 --- a/crates/fj-core/src/algorithms/approx/curve.rs +++ b/crates/fj-core/src/algorithms/approx/curve.rs @@ -48,7 +48,7 @@ fn approx_curve( boundary: CurveBoundary>, tolerance: impl Into, ) -> CurveApprox { - let SurfaceGeom { u, .. } = surface; + let SurfaceGeom::Basic { u, .. } = surface; let points = match (path, u) { (SurfacePath::Circle(_), GlobalPath::Circle(_)) => { approx_circle_on_curved_surface() @@ -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), @@ -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.]), }; @@ -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.]), }; diff --git a/crates/fj-core/src/algorithms/bounding_volume/face.rs b/crates/fj-core/src/algorithms/bounding_volume/face.rs index e1f7c46a4..2de9af4d0 100644 --- a/crates/fj-core/src/algorithms/bounding_volume/face.rs +++ b/crates/fj-core/src/algorithms/bounding_volume/face.rs @@ -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 diff --git a/crates/fj-core/src/geometry/geometry.rs b/crates/fj-core/src/geometry/geometry.rs index 511734ce8..796ddb269 100644 --- a/crates/fj-core/src/geometry/geometry.rs +++ b/crates/fj-core/src/geometry/geometry.rs @@ -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(), }, diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index 56e9066eb..9a42809bd 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -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, +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 - pub v: Vector<3>, + /// The v-axis of the surface + v: Vector<3>, + }, } impl SurfaceGeom { @@ -21,7 +32,7 @@ impl SurfaceGeom { point: impl Into>, ) -> 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]) } @@ -32,19 +43,19 @@ impl SurfaceGeom { vector: impl Into>, ) -> 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<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") @@ -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 } } } @@ -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.]), @@ -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.]), diff --git a/crates/fj-core/src/operations/build/surface.rs b/crates/fj-core/src/operations/build/surface.rs index 76e90495c..ef55d1e27 100644 --- a/crates/fj-core/src/operations/build/surface.rs +++ b/crates/fj-core/src/operations/build/surface.rs @@ -35,7 +35,7 @@ pub trait BuildSurface { core: &mut Core, ) -> Handle { Self::from_geometry( - SurfaceGeom { + SurfaceGeom::Basic { u: u.into(), v: v.into(), }, diff --git a/crates/fj-core/src/operations/sweep/path.rs b/crates/fj-core/src/operations/sweep/path.rs index c3d89fe7e..36ce34751 100644 --- a/crates/fj-core/src/operations/sweep/path.rs +++ b/crates/fj-core/src/operations/sweep/path.rs @@ -39,7 +39,7 @@ impl SweepSurfacePath for SurfacePath { path: impl Into>, core: &mut Core, ) -> Handle { - let SurfaceGeom { u, .. } = surface; + let SurfaceGeom::Basic { u, .. } = surface; match u { GlobalPath::Circle(_) => { // Sweeping a `Curve` creates a `Surface`. The u-axis of that diff --git a/crates/fj-core/src/operations/sweep/sketch.rs b/crates/fj-core/src/operations/sweep/sketch.rs index 92b965100..497f202aa 100644 --- a/crates/fj-core/src/operations/sweep/sketch.rs +++ b/crates/fj-core/src/operations/sweep/sketch.rs @@ -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 = {