From f5fc4991f9a361525ef0885b61b2c61f9fbf6d92 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Aug 2024 19:54:50 +0200 Subject: [PATCH] Merge `GlobalPath` into `Path` --- crates/fj-core/src/algorithms/approx/curve.rs | 24 +++++++++---------- .../src/algorithms/bounding_volume/face.rs | 6 ++--- crates/fj-core/src/geometry/geometry.rs | 10 ++++---- crates/fj-core/src/geometry/mod.rs | 2 +- crates/fj-core/src/geometry/path.rs | 14 ++--------- crates/fj-core/src/geometry/surface.rs | 18 +++++++------- .../fj-core/src/operations/build/surface.rs | 6 ++--- crates/fj-core/src/operations/sweep/path.rs | 10 ++++---- 8 files changed, 40 insertions(+), 50 deletions(-) diff --git a/crates/fj-core/src/algorithms/approx/curve.rs b/crates/fj-core/src/algorithms/approx/curve.rs index bfbb37594..82e26f389 100644 --- a/crates/fj-core/src/algorithms/approx/curve.rs +++ b/crates/fj-core/src/algorithms/approx/curve.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use fj_math::{Circle, Line, Point}; use crate::{ - geometry::{CurveBoundary, Geometry, GlobalPath, Path, SurfaceGeom}, + geometry::{CurveBoundary, Geometry, Path, SurfaceGeom}, storage::Handle, topology::{Curve, Surface}, }; @@ -50,10 +50,8 @@ fn approx_curve( ) -> CurveApprox { let SurfaceGeom { u, .. } = surface; let points = match (path, u) { - (Path::Circle(_), GlobalPath::Circle(_)) => { - approx_circle_on_curved_surface() - } - (Path::Circle(circle), GlobalPath::Line(_)) => { + (Path::Circle(_), Path::Circle(_)) => approx_circle_on_curved_surface(), + (Path::Circle(circle), Path::Line(_)) => { approx_circle_on_straight_surface( circle, boundary, surface, tolerance, ) @@ -118,8 +116,8 @@ fn approx_line_on_any_surface( let SurfaceGeom { u, .. } = surface; let approx_u = match u { - GlobalPath::Circle(circle) => approx_circle(circle, range_u, tolerance), - GlobalPath::Line(line) => approx_line(line), + Path::Circle(circle) => approx_circle(circle, range_u, tolerance), + Path::Line(line) => approx_line(line), }; let mut points = Vec::new(); @@ -199,7 +197,7 @@ mod tests { algorithms::approx::{ circle::approx_circle, curve::approx_curve, ApproxPoint, }, - geometry::{CurveBoundary, GlobalPath, Path, SurfaceGeom}, + geometry::{CurveBoundary, Path, SurfaceGeom}, operations::build::BuildSurface, topology::Surface, Core, @@ -210,7 +208,8 @@ mod tests { let core = Core::new(); let surface = core.layers.geometry.xz_plane(); - let (path, boundary) = Path::line_from_points([[1., 1.], [2., 1.]]); + let (path, boundary) = + Path::<2>::line_from_points([[1., 1.], [2., 1.]]); let boundary = CurveBoundary::from(boundary); let tolerance = 1.; @@ -222,10 +221,11 @@ mod tests { #[test] fn approx_line_on_curved_surface_but_not_along_curve() { let surface = SurfaceGeom { - u: GlobalPath::circle_from_radius(1.), + u: Path::circle_from_radius(1.), v: Vector::from([0., 0., 1.]), }; - let (path, boundary) = Path::line_from_points([[1., 1.], [2., 1.]]); + let (path, boundary) = + Path::<2>::line_from_points([[1., 1.], [2., 1.]]); let boundary = CurveBoundary::from(boundary); let tolerance = 1.; @@ -239,7 +239,7 @@ mod tests { let mut core = Core::new(); let circle = Circle::from_center_and_radius(Point::origin(), 1.); - let global_path = GlobalPath::Circle(circle); + let global_path = Path::Circle(circle); let surface_geom = SurfaceGeom { 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 98f24c5fd..e0f36a082 100644 --- a/crates/fj-core/src/algorithms/bounding_volume/face.rs +++ b/crates/fj-core/src/algorithms/bounding_volume/face.rs @@ -4,7 +4,7 @@ use fj_math::{Aabb, Vector}; use crate::{ algorithms::approx::Tolerance, - geometry::{Geometry, GlobalPath, SurfaceGeom}, + geometry::{Geometry, Path, SurfaceGeom}, topology::Face, }; @@ -17,7 +17,7 @@ impl super::BoundingVolume<3> for &Face { let SurfaceGeom { u, v } = surface; match u { - GlobalPath::Circle(circle) => { + Path::Circle(circle) => { // This is not the most precise way to calculate the // AABB, doing it for the whole circle, but it should // do. @@ -30,7 +30,7 @@ impl super::BoundingVolume<3> for &Face { aabb_bottom.merged(&aabb_top) } - GlobalPath::Line(_) => { + Path::Line(_) => { // A bounding volume must include the body it bounds, // but does not need to match it precisely. So it's // okay, if it's a bit larger. diff --git a/crates/fj-core/src/geometry/geometry.rs b/crates/fj-core/src/geometry/geometry.rs index 511734ce8..4a4ab9caf 100644 --- a/crates/fj-core/src/geometry/geometry.rs +++ b/crates/fj-core/src/geometry/geometry.rs @@ -8,8 +8,8 @@ use crate::{ }; use super::{ - vertex::LocalVertexGeom, CurveGeom, GlobalPath, LocalCurveGeom, - SurfaceGeom, VertexGeom, + vertex::LocalVertexGeom, CurveGeom, LocalCurveGeom, Path, SurfaceGeom, + VertexGeom, }; /// Geometric data that is associated with topological objects @@ -43,21 +43,21 @@ impl Geometry { self_.define_surface_inner( self_.xy_plane.clone(), SurfaceGeom { - u: GlobalPath::x_axis(), + u: Path::x_axis(), v: Vector::unit_y(), }, ); self_.define_surface_inner( self_.xz_plane.clone(), SurfaceGeom { - u: GlobalPath::x_axis(), + u: Path::x_axis(), v: Vector::unit_z(), }, ); self_.define_surface_inner( self_.yz_plane.clone(), SurfaceGeom { - u: GlobalPath::y_axis(), + u: Path::y_axis(), v: Vector::unit_z(), }, ); diff --git a/crates/fj-core/src/geometry/mod.rs b/crates/fj-core/src/geometry/mod.rs index 0bf329cc8..108db3a92 100644 --- a/crates/fj-core/src/geometry/mod.rs +++ b/crates/fj-core/src/geometry/mod.rs @@ -11,7 +11,7 @@ pub use self::{ boundary::{CurveBoundary, CurveBoundaryElement}, curve::{CurveGeom, LocalCurveGeom}, geometry::Geometry, - path::{GlobalPath, Path}, + path::Path, surface::SurfaceGeom, vertex::{LocalVertexGeom, VertexGeom}, }; diff --git a/crates/fj-core/src/geometry/path.rs b/crates/fj-core/src/geometry/path.rs index 6d62c5870..d8fcd7007 100644 --- a/crates/fj-core/src/geometry/path.rs +++ b/crates/fj-core/src/geometry/path.rs @@ -1,6 +1,6 @@ //! Paths through 2D and 3D space //! -//! See [`Path`] and [`GlobalPath`]. +//! See [`Path`]. use fj_math::{Circle, Line, Point, Scalar, Transform, Vector}; @@ -79,17 +79,7 @@ impl Path<2> { } } -/// A path through global (3D) space -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] -pub enum GlobalPath { - /// A circle - Circle(Circle<3>), - - /// A line - Line(Line<3>), -} - -impl GlobalPath { +impl Path<3> { /// Construct a `GlobalPath` that represents the x-axis pub fn x_axis() -> Self { Self::Line(Line::from_origin_and_direction( diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index 85b715fa7..d06cfb352 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -4,13 +4,13 @@ use fj_math::{Point, Scalar, Transform, Triangle, Vector}; use crate::algorithms::approx::{PathApproxParams, Tolerance}; -use super::GlobalPath; +use super::Path; /// 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 u: Path<3>, /// The v-axis of the surface pub v: Vector<3>, @@ -21,8 +21,8 @@ impl SurfaceGeom { pub fn origin(&self) -> Point<3> { let Self { u, .. } = self; match u { - GlobalPath::Circle(circle) => circle.center(), - GlobalPath::Line(line) => line.origin(), + Path::Circle(circle) => circle.center(), + Path::Line(line) => line.origin(), } } @@ -71,7 +71,7 @@ impl SurfaceGeom { let Self { u, v } = self; match u { - GlobalPath::Circle(circle) => { + Path::Circle(circle) => { let params = PathApproxParams::for_circle(circle, tolerance); let a = point_surface.u - params.increment(); @@ -93,7 +93,7 @@ impl SurfaceGeom { (triangle, barycentric_coords) } - GlobalPath::Line(line) => { + Path::Line(line) => { let a = line.direction(); let b = *v; @@ -152,13 +152,13 @@ mod tests { use crate::{ algorithms::approx::Tolerance, - geometry::{GlobalPath, SurfaceGeom}, + geometry::{Path, SurfaceGeom}, }; #[test] fn point_from_surface_coords() { let surface = SurfaceGeom { - u: GlobalPath::Line(Line::from_origin_and_direction( + u: Path::Line(Line::from_origin_and_direction( Point::from([1., 1., 1.]), Vector::from([0., 2., 0.]), )), @@ -177,7 +177,7 @@ mod tests { #[test] fn vector_from_surface_coords() { let surface = SurfaceGeom { - u: GlobalPath::Line(Line::from_origin_and_direction( + u: Path::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..44ad80ebc 100644 --- a/crates/fj-core/src/operations/build/surface.rs +++ b/crates/fj-core/src/operations/build/surface.rs @@ -1,7 +1,7 @@ use fj_math::{Point, Scalar, Vector}; use crate::{ - geometry::{GlobalPath, SurfaceGeom}, + geometry::{Path, SurfaceGeom}, operations::insert::Insert, storage::Handle, topology::Surface, @@ -30,7 +30,7 @@ pub trait BuildSurface { /// Build a surface from the provided `u` and `v` fn from_uv( - u: impl Into, + u: impl Into>, v: impl Into>, core: &mut Core, ) -> Handle { @@ -50,7 +50,7 @@ pub trait BuildSurface { ) -> (Handle, [Point<2>; 3]) { let [a, b, c] = points.map(Into::into); - let (u, u_line) = GlobalPath::line_from_points([a, b]); + let (u, u_line) = Path::<3>::line_from_points([a, b]); let v = c - a; let surface = Surface::from_uv(u, v, core); diff --git a/crates/fj-core/src/operations/sweep/path.rs b/crates/fj-core/src/operations/sweep/path.rs index 2287179df..c004a09b1 100644 --- a/crates/fj-core/src/operations/sweep/path.rs +++ b/crates/fj-core/src/operations/sweep/path.rs @@ -1,7 +1,7 @@ use fj_math::{Circle, Line, Vector}; use crate::{ - geometry::{GlobalPath, Path, SurfaceGeom}, + geometry::{Path, SurfaceGeom}, operations::build::BuildSurface, storage::Handle, topology::Surface, @@ -41,7 +41,7 @@ impl SweepSurfacePath for Path<2> { ) -> Handle { let SurfaceGeom { u, .. } = surface; match u { - GlobalPath::Circle(_) => { + Path::Circle(_) => { // Sweeping a `Curve` creates a `Surface`. The u-axis of that // `Surface` is a `GlobalPath`, which we are computing below. // That computation might or might not work with an arbitrary @@ -58,7 +58,7 @@ impl SweepSurfacePath for Path<2> { not supported yet." ) } - GlobalPath::Line(_) => { + Path::Line(_) => { // We're sweeping from a curve on a flat surface, which is // supported. Carry on. } @@ -77,7 +77,7 @@ impl SweepSurfacePath for Path<2> { let circle = Circle::new(center, a, b); - GlobalPath::Circle(circle) + Path::Circle(circle) } Path::Line(line) => { let origin = surface @@ -89,7 +89,7 @@ impl SweepSurfacePath for Path<2> { let line = Line::from_origin_and_direction(origin, direction); - GlobalPath::Line(line) + Path::Line(line) } };