diff --git a/crates/fj-core/src/algorithms/approx/curve.rs b/crates/fj-core/src/algorithms/approx/curve.rs index 7f4c679a0..e27ca58c6 100644 --- a/crates/fj-core/src/algorithms/approx/curve.rs +++ b/crates/fj-core/src/algorithms/approx/curve.rs @@ -203,7 +203,7 @@ mod tests { let (surface_path, boundary) = SurfacePath::line_from_points([[1., 1.], [2., 1.]]); let boundary = CurveBoundary::from(boundary); - let surface = core.layers.objects.surfaces.xz_plane().geometry(); + let surface = core.layers.geometry.xz_plane(); let tolerance = 1.; let approx = (&curve, surface_path, &surface, boundary) @@ -274,7 +274,7 @@ mod tests { let surface_path = SurfacePath::circle_from_center_and_radius([0., 0.], 1.); let boundary = CurveBoundary::from([[0.], [TAU]]); - let surface = core.layers.objects.surfaces.xz_plane().geometry(); + let surface = core.layers.geometry.xz_plane(); let tolerance = 1.; let approx = (&curve, surface_path, &surface, boundary) diff --git a/crates/fj-core/src/geometry/geometry.rs b/crates/fj-core/src/geometry/geometry.rs index b2e68dea0..3b8f4ee00 100644 --- a/crates/fj-core/src/geometry/geometry.rs +++ b/crates/fj-core/src/geometry/geometry.rs @@ -11,8 +11,11 @@ use super::{GlobalPath, SurfaceGeometry}; /// Geometric data that is associated with topological objects pub struct Geometry { - /// The geometry of surfaces - pub surface: BTreeMap, SurfaceGeometry>, + surface: BTreeMap, SurfaceGeometry>, + + xy_plane: Handle, + xz_plane: Handle, + yz_plane: Handle, } impl Geometry { @@ -20,24 +23,28 @@ impl Geometry { pub fn new(objects: &Objects) -> Self { let mut self_ = Self { surface: BTreeMap::new(), + + xy_plane: objects.surfaces.xy_plane(), + xz_plane: objects.surfaces.xz_plane(), + yz_plane: objects.surfaces.yz_plane(), }; self_.define_surface_inner( - objects.surfaces.xy_plane(), + self_.xy_plane.clone(), SurfaceGeometry { u: GlobalPath::x_axis(), v: Vector::unit_y(), }, ); self_.define_surface_inner( - objects.surfaces.xz_plane(), + self_.xz_plane.clone(), SurfaceGeometry { u: GlobalPath::x_axis(), v: Vector::unit_z(), }, ); self_.define_surface_inner( - objects.surfaces.yz_plane(), + self_.yz_plane.clone(), SurfaceGeometry { u: GlobalPath::y_axis(), v: Vector::unit_z(), @@ -54,4 +61,31 @@ impl Geometry { ) { self.surface.insert(surface.clone().into(), geometry); } + + /// # Access the geometry of the provided surface + /// + /// ## Panics + /// + /// Panics, if the geometry of surface is not defined. + pub fn of_surface(&self, surface: &Handle) -> SurfaceGeometry { + self.surface + .get(&surface.clone().into()) + .copied() + .expect("Expected geometry of surface to be defined") + } + + /// Access the geometry of the xy-plane + pub fn xy_plane(&self) -> SurfaceGeometry { + self.of_surface(&self.xy_plane) + } + + /// Access the geometry of the xz-plane + pub fn xz_plane(&self) -> SurfaceGeometry { + self.of_surface(&self.xz_plane) + } + + /// Access the geometry of the yz-plane + pub fn yz_plane(&self) -> SurfaceGeometry { + self.of_surface(&self.yz_plane) + } } diff --git a/crates/fj-core/src/objects/any_object.rs b/crates/fj-core/src/objects/any_object.rs index 6c047e2e2..989f363f9 100644 --- a/crates/fj-core/src/objects/any_object.rs +++ b/crates/fj-core/src/objects/any_object.rs @@ -36,8 +36,8 @@ macro_rules! any_object { /// Validate the object with a pre-defined validation configuration pub fn validate(&self, - config: &ValidationConfig, - errors: &mut Vec + config: &ValidationConfig, + errors: &mut Vec, ) { match self { $(