Skip to content

Commit

Permalink
Merge pull request #2456 from hannobraun/path
Browse files Browse the repository at this point in the history
Merge `SurfacePath` and `GlobalPath` into `Path`
  • Loading branch information
hannobraun authored Aug 15, 2024
2 parents 07ffb0f + 0b5c3c3 commit d833dff
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 143 deletions.
32 changes: 14 additions & 18 deletions crates/fj-core/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::BTreeMap;
use fj_math::{Circle, Line, Point};

use crate::{
geometry::{CurveBoundary, Geometry, GlobalPath, SurfaceGeom, SurfacePath},
geometry::{CurveBoundary, Geometry, Path, SurfaceGeom},
storage::Handle,
topology::{Curve, Surface},
};
Expand Down Expand Up @@ -43,22 +43,20 @@ pub fn approx_curve_with_cache(
}

fn approx_curve(
path: &SurfacePath,
path: &Path<2>,
surface: &SurfaceGeom,
boundary: CurveBoundary<Point<1>>,
tolerance: impl Into<Tolerance>,
) -> CurveApprox {
let SurfaceGeom { u, .. } = surface;
let points = match (path, u) {
(SurfacePath::Circle(_), GlobalPath::Circle(_)) => {
approx_circle_on_curved_surface()
}
(SurfacePath::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,
)
}
(SurfacePath::Line(line), _) => {
(Path::Line(line), _) => {
approx_line_on_any_surface(line, boundary, surface, tolerance)
}
};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -199,7 +197,7 @@ mod tests {
algorithms::approx::{
circle::approx_circle, curve::approx_curve, ApproxPoint,
},
geometry::{CurveBoundary, GlobalPath, SurfaceGeom, SurfacePath},
geometry::{CurveBoundary, Path, SurfaceGeom},
operations::build::BuildSurface,
topology::Surface,
Core,
Expand All @@ -210,8 +208,7 @@ mod tests {
let core = Core::new();

let surface = core.layers.geometry.xz_plane();
let (path, boundary) =
SurfacePath::line_from_points([[1., 1.], [2., 1.]]);
let (path, boundary) = Path::line_from_points([[1., 1.], [2., 1.]]);
let boundary = CurveBoundary::from(boundary);

let tolerance = 1.;
Expand All @@ -223,11 +220,10 @@ 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) =
SurfacePath::line_from_points([[1., 1.], [2., 1.]]);
let (path, boundary) = Path::line_from_points([[1., 1.], [2., 1.]]);
let boundary = CurveBoundary::from(boundary);

let tolerance = 1.;
Expand All @@ -241,13 +237,13 @@ 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.]),
};
let surface = Surface::from_geometry(surface_geom, &mut core);
let path = SurfacePath::line_from_points_with_coords([
let path = Path::line_from_points_with_coords([
([0.], [0., 1.]),
([TAU], [TAU, 1.]),
]);
Expand Down Expand Up @@ -278,7 +274,7 @@ mod tests {
let surface_geom = *core.layers.geometry.xz_plane();
let surface = Surface::from_geometry(surface_geom, &mut core);
let circle = Circle::from_center_and_radius([0., 0.], 1.);
let path = SurfacePath::Circle(circle);
let path = Path::Circle(circle);
let boundary = CurveBoundary::from([[0.], [TAU]]);

let tolerance = 1.;
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-core/src/algorithms/bounding_volume/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use fj_math::{Aabb, Vector};

use crate::{
algorithms::approx::Tolerance,
geometry::{Geometry, GlobalPath, SurfaceGeom},
geometry::{Geometry, Path, SurfaceGeom},
topology::Face,
};

Expand All @@ -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.
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-core/src/algorithms/bounding_volume/half_edge.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fj_math::{Aabb, Vector};

use crate::{
geometry::{Geometry, SurfacePath},
geometry::{Geometry, Path},
storage::Handle,
topology::{HalfEdge, Surface, Vertex},
};
Expand All @@ -20,7 +20,7 @@ impl super::BoundingVolume<2>
.path;

match path {
SurfacePath::Circle(circle) => {
Path::Circle(circle) => {
// Just calculate the AABB of the whole circle. This is not the
// most precise, but it should do for now.

Expand All @@ -32,7 +32,7 @@ impl super::BoundingVolume<2>
max: circle.center() + center_to_min_max,
})
}
SurfacePath::Line(_) => {
Path::Line(_) => {
let points =
[half_edge.start_vertex(), end_vertex].map(|vertex| {
let point_curve = geometry
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/geometry/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::BTreeMap;

use crate::{storage::Handle, topology::Surface};

use super::SurfacePath;
use super::Path;

/// The geometric definition of a curve
#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -40,5 +40,5 @@ impl CurveGeom {
#[derive(Clone, Debug)]
pub struct LocalCurveGeom {
/// The path that defines the curve on its surface
pub path: SurfacePath,
pub path: Path<2>,
}
10 changes: 5 additions & 5 deletions crates/fj-core/src/geometry/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
},
);
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/geometry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use self::{
boundary::{CurveBoundary, CurveBoundaryElement},
curve::{CurveGeom, LocalCurveGeom},
geometry::Geometry,
path::{GlobalPath, SurfacePath},
path::Path,
surface::SurfaceGeom,
vertex::{LocalVertexGeom, VertexGeom},
};
Loading

0 comments on commit d833dff

Please sign in to comment.