Skip to content

Commit

Permalink
Merge pull request #1939 from hannobraun/path
Browse files Browse the repository at this point in the history
Rename `Curve` to `SurfacePath`
  • Loading branch information
hannobraun authored Jul 13, 2023
2 parents c2fea02 + 0da2c8d commit f415bde
Show file tree
Hide file tree
Showing 30 changed files with 120 additions and 117 deletions.
28 changes: 14 additions & 14 deletions crates/fj-core/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::collections::BTreeMap;
use fj_math::Point;

use crate::{
geometry::curve::{Curve, GlobalPath},
geometry::{GlobalPath, SurfacePath},
objects::{GlobalEdge, HalfEdge, Surface, Vertex},
storage::{Handle, ObjectId},
};
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Approx for (&HalfEdge, &Surface) {
Some(approx) => approx,
None => {
let approx = approx_edge(
&half_edge.curve(),
&half_edge.path(),
surface,
range,
tolerance,
Expand All @@ -111,7 +111,7 @@ impl Approx for (&HalfEdge, &Surface) {
.into_iter()
.map(|point| {
let point_surface = half_edge
.curve()
.path()
.point_from_path_coords(point.local_form);

ApproxPoint::new(point_surface, point.global_form)
Expand Down Expand Up @@ -146,7 +146,7 @@ impl HalfEdgeApprox {
}

fn approx_edge(
curve: &Curve,
path: &SurfacePath,
surface: &Surface,
range: RangeOnPath,
tolerance: impl Into<Tolerance>,
Expand All @@ -157,14 +157,14 @@ fn approx_edge(
// This will probably all be unified eventually, as `SurfacePath` and
// `GlobalPath` grow APIs that are better suited to implementing this code
// in a more abstract way.
let points = match (curve, surface.geometry().u) {
(Curve::Circle(_), GlobalPath::Circle(_)) => {
let points = match (path, surface.geometry().u) {
(SurfacePath::Circle(_), GlobalPath::Circle(_)) => {
todo!(
"Approximating a circle on a curved surface not supported yet."
)
}
(Curve::Circle(_), GlobalPath::Line(_)) => {
(curve, range)
(SurfacePath::Circle(_), GlobalPath::Line(_)) => {
(path, range)
.approx_with_cache(tolerance, &mut ())
.into_iter()
.map(|(point_curve, point_surface)| {
Expand All @@ -190,10 +190,10 @@ fn approx_edge(
})
.collect()
}
(Curve::Line(line), _) => {
(SurfacePath::Line(line), _) => {
let range_u =
RangeOnPath::from(range.boundary.map(|point_curve| {
[curve.point_from_path_coords(point_curve).u]
[path.point_from_path_coords(point_curve).u]
}));

let approx_u = (surface.geometry().u, range_u)
Expand All @@ -202,7 +202,7 @@ fn approx_edge(
let mut points = Vec::new();
for (u, _) in approx_u {
let t = (u.t - line.origin().u) / line.direction().u;
let point_surface = curve.point_from_path_coords([t]);
let point_surface = path.point_from_path_coords([t]);
let point_global =
surface.geometry().point_from_surface_coords(point_surface);
points.push((u, point_global));
Expand Down Expand Up @@ -304,7 +304,7 @@ mod tests {

use crate::{
algorithms::approx::{path::RangeOnPath, Approx, ApproxPoint},
geometry::{curve::GlobalPath, surface::SurfaceGeometry},
geometry::{GlobalPath, SurfaceGeometry},
objects::{HalfEdge, Surface},
operations::BuildHalfEdge,
services::Services,
Expand Down Expand Up @@ -366,7 +366,7 @@ mod tests {
.into_iter()
.map(|(point_local, _)| {
let point_surface =
half_edge.curve().point_from_path_coords(point_local);
half_edge.path().point_from_path_coords(point_local);
let point_global =
surface.geometry().point_from_surface_coords(point_surface);
ApproxPoint::new(point_surface, point_global)
Expand All @@ -386,7 +386,7 @@ mod tests {
let approx = (&half_edge, surface.deref()).approx(tolerance);

let expected_approx =
(&half_edge.curve(), RangeOnPath::from([[0.], [TAU]]))
(&half_edge.path(), RangeOnPath::from([[0.], [TAU]]))
.approx(tolerance)
.into_iter()
.map(|(_, point_surface)| {
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-core/src/algorithms/approx/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ use std::iter;

use fj_math::{Circle, Point, Scalar, Sign};

use crate::geometry::curve::{Curve, GlobalPath};
use crate::geometry::{GlobalPath, SurfacePath};

use super::{Approx, Tolerance};

impl Approx for (&Curve, RangeOnPath) {
impl Approx for (&SurfacePath, RangeOnPath) {
type Approximation = Vec<(Point<1>, Point<2>)>;
type Cache = ();

Expand All @@ -48,10 +48,10 @@ impl Approx for (&Curve, RangeOnPath) {
let (path, range) = self;

match path {
Curve::Circle(circle) => {
SurfacePath::Circle(circle) => {
approx_circle(circle, range, tolerance.into())
}
Curve::Line(_) => vec![],
SurfacePath::Line(_) => vec![],
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/fj-core/src/algorithms/bounding_volume/edge.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use fj_math::{Aabb, Vector};

use crate::{geometry::curve::Curve, objects::HalfEdge};
use crate::{geometry::SurfacePath, objects::HalfEdge};

impl super::BoundingVolume<2> for HalfEdge {
fn aabb(&self) -> Option<Aabb<2>> {
match self.curve() {
Curve::Circle(circle) => {
match self.path() {
SurfacePath::Circle(circle) => {
// Just calculate the AABB of the whole circle. This is not the
// most precise, but it should do for now.

Expand All @@ -17,9 +17,9 @@ impl super::BoundingVolume<2> for HalfEdge {
max: circle.center() + center_to_min_max,
})
}
Curve::Line(_) => {
SurfacePath::Line(_) => {
let points = self.boundary().map(|point_curve| {
self.curve().point_from_path_coords(point_curve)
self.path().point_from_path_coords(point_curve)
});

Some(Aabb::<2>::from_points(points))
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
@@ -1,6 +1,6 @@
use fj_math::Aabb;

use crate::{geometry::curve::GlobalPath, objects::Face};
use crate::{geometry::GlobalPath, objects::Face};

impl super::BoundingVolume<3> for Face {
fn aabb(&self) -> Option<Aabb<3>> {
Expand Down
34 changes: 17 additions & 17 deletions crates/fj-core/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use fj_math::{Point, Segment};

use crate::{geometry::curve::Curve, objects::HalfEdge};
use crate::{geometry::SurfacePath, objects::HalfEdge};

use super::LineSegmentIntersection;

Expand Down Expand Up @@ -28,29 +28,29 @@ impl CurveEdgeIntersection {
/// Currently, only intersections between lines and line segments can be
/// computed. Panics, if a different type of curve or [`HalfEdge`] is
/// passed.
pub fn compute(curve: &Curve, half_edge: &HalfEdge) -> Option<Self> {
let curve_as_line = match curve {
Curve::Line(line) => line,
pub fn compute(path: &SurfacePath, half_edge: &HalfEdge) -> Option<Self> {
let path_as_line = match path {
SurfacePath::Line(line) => line,
_ => todo!("Curve-edge intersection only supports lines"),
};

let edge_as_segment = {
let edge_curve_as_line = match half_edge.curve() {
Curve::Line(line) => line,
let edge_path_as_line = match half_edge.path() {
SurfacePath::Line(line) => line,
_ => {
todo!("Curve-edge intersection only supports line segments")
}
};

let edge_vertices = half_edge
.boundary()
.map(|point| edge_curve_as_line.point_from_line_coords(point));
.map(|point| edge_path_as_line.point_from_line_coords(point));

Segment::from_points(edge_vertices)
};

let intersection =
LineSegmentIntersection::compute(curve_as_line, &edge_as_segment)?;
LineSegmentIntersection::compute(path_as_line, &edge_as_segment)?;

let intersection = match intersection {
LineSegmentIntersection::Point { point_on_line } => Self::Point {
Expand All @@ -72,7 +72,7 @@ mod tests {
use fj_math::Point;

use crate::{
geometry::curve::Curve, objects::HalfEdge, operations::BuildHalfEdge,
geometry::SurfacePath, objects::HalfEdge, operations::BuildHalfEdge,
services::Services,
};

Expand All @@ -82,11 +82,11 @@ mod tests {
fn compute_edge_in_front_of_curve_origin() {
let mut services = Services::new();

let curve = Curve::u_axis();
let path = SurfacePath::u_axis();
let half_edge =
HalfEdge::line_segment([[1., -1.], [1., 1.]], None, &mut services);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);
let intersection = CurveEdgeIntersection::compute(&path, &half_edge);

assert_eq!(
intersection,
Expand All @@ -100,14 +100,14 @@ mod tests {
fn compute_edge_behind_curve_origin() {
let mut services = Services::new();

let curve = Curve::u_axis();
let path = SurfacePath::u_axis();
let half_edge = HalfEdge::line_segment(
[[-1., -1.], [-1., 1.]],
None,
&mut services,
);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);
let intersection = CurveEdgeIntersection::compute(&path, &half_edge);

assert_eq!(
intersection,
Expand All @@ -121,14 +121,14 @@ mod tests {
fn compute_edge_parallel_to_curve() {
let mut services = Services::new();

let curve = Curve::u_axis();
let path = SurfacePath::u_axis();
let half_edge = HalfEdge::line_segment(
[[-1., -1.], [1., -1.]],
None,
&mut services,
);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);
let intersection = CurveEdgeIntersection::compute(&path, &half_edge);

assert!(intersection.is_none());
}
Expand All @@ -137,11 +137,11 @@ mod tests {
fn compute_edge_on_curve() {
let mut services = Services::new();

let curve = Curve::u_axis();
let path = SurfacePath::u_axis();
let half_edge =
HalfEdge::line_segment([[-1., 0.], [1., 0.]], None, &mut services);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);
let intersection = CurveEdgeIntersection::compute(&path, &half_edge);

assert_eq!(
intersection,
Expand Down
12 changes: 6 additions & 6 deletions crates/fj-core/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::vec;
use fj_interop::ext::SliceExt;
use fj_math::Point;

use crate::{geometry::curve::Curve, objects::Face};
use crate::{geometry::SurfacePath, objects::Face};

use super::CurveEdgeIntersection;

Expand All @@ -28,7 +28,7 @@ impl CurveFaceIntersection {
}

/// Compute the intersection
pub fn compute(curve: &Curve, face: &Face) -> Self {
pub fn compute(path: &SurfacePath, face: &Face) -> Self {
let half_edges = face
.region()
.all_cycles()
Expand All @@ -37,7 +37,7 @@ impl CurveFaceIntersection {
let mut intersections = Vec::new();

for half_edge in half_edges {
let intersection = CurveEdgeIntersection::compute(curve, half_edge);
let intersection = CurveEdgeIntersection::compute(path, half_edge);

if let Some(intersection) = intersection {
match intersection {
Expand Down Expand Up @@ -153,7 +153,7 @@ where
#[cfg(test)]
mod tests {
use crate::{
geometry::curve::Curve,
geometry::SurfacePath,
objects::{Cycle, Face},
operations::{BuildCycle, BuildFace, Insert, UpdateFace, UpdateRegion},
services::Services,
Expand All @@ -165,7 +165,7 @@ mod tests {
fn compute() {
let mut services = Services::new();

let (curve, _) = Curve::line_from_points([[-3., 0.], [-2., 0.]]);
let (path, _) = SurfacePath::line_from_points([[-3., 0.], [-2., 0.]]);

#[rustfmt::skip]
let exterior_points = [
Expand Down Expand Up @@ -200,7 +200,7 @@ mod tests {

let expected =
CurveFaceIntersection::from_intervals([[[1.], [2.]], [[4.], [5.]]]);
assert_eq!(CurveFaceIntersection::compute(&curve, &face), expected);
assert_eq!(CurveFaceIntersection::compute(&path, &face), expected);

services.only_validate(face);
}
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-core/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fj_interop::ext::ArrayExt;
use iter_fixed::IntoIteratorFixed;

use crate::{geometry::curve::Curve, objects::Face};
use crate::{geometry::SurfacePath, objects::Face};

use super::{CurveFaceIntersection, SurfaceSurfaceIntersection};

Expand All @@ -14,7 +14,7 @@ pub struct FaceFaceIntersection {
/// representation of the intersection on the respective face's surface.
///
/// They both represent the same global curve.
pub intersection_curves: [Curve; 2],
pub intersection_curves: [SurfacePath; 2],

/// The interval of this intersection, in curve coordinates
///
Expand Down Expand Up @@ -62,7 +62,7 @@ mod tests {

use crate::{
algorithms::intersect::CurveFaceIntersection,
geometry::curve::Curve,
geometry::SurfacePath,
objects::{Cycle, Face},
operations::{BuildCycle, BuildFace, Insert, UpdateFace, UpdateRegion},
services::Services,
Expand Down Expand Up @@ -131,7 +131,7 @@ mod tests {
let intersection = FaceFaceIntersection::compute([&a, &b]);

let expected_curves = surfaces.map(|_| {
let (path, _) = Curve::line_from_points([[0., 0.], [1., 0.]]);
let (path, _) = SurfacePath::line_from_points([[0., 0.], [1., 0.]]);
path
});
let expected_intervals =
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-core/src/algorithms/intersect/ray_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use fj_math::Segment;

use crate::{
algorithms::intersect::{HorizontalRayToTheRight, Intersect},
geometry::curve::Curve,
geometry::SurfacePath,
objects::HalfEdge,
storage::Handle,
};
Expand All @@ -17,9 +17,9 @@ impl Intersect for (&HorizontalRayToTheRight<2>, &Handle<HalfEdge>) {
fn intersect(self) -> Option<Self::Intersection> {
let (ray, edge) = self;

let line = match edge.curve() {
Curve::Line(line) => line,
Curve::Circle(_) => {
let line = match edge.path() {
SurfacePath::Line(line) => line,
SurfacePath::Circle(_) => {
todo!("Casting rays against circles is not supported yet")
}
};
Expand Down
Loading

0 comments on commit f415bde

Please sign in to comment.