Skip to content

Commit

Permalink
Merge pull request #1081 from hannobraun/path
Browse files Browse the repository at this point in the history
Replace `CurveKind` with `SurfacePath`/`GlobalPath`
  • Loading branch information
hannobraun authored Sep 13, 2022
2 parents d556e19 + 05a99e5 commit cb3c7e0
Show file tree
Hide file tree
Showing 21 changed files with 289 additions and 220 deletions.
15 changes: 10 additions & 5 deletions crates/fj-kernel/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use std::cmp::max;

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

use crate::objects::{Curve, CurveKind, GlobalCurve, Vertex};
use crate::{
objects::{Curve, GlobalCurve, Vertex},
path::GlobalPath,
};

use super::{Approx, ApproxPoint, Tolerance};

Expand All @@ -28,7 +31,7 @@ impl Approx for (&Curve, RangeOnCurve) {
.into_iter()
.map(|point| {
let point_surface =
curve.kind().point_from_curve_coords(point.local_form);
curve.path().point_from_path_coords(point.local_form);
ApproxPoint::new(point_surface, point.global_form)
.with_source((*curve, point.local_form))
})
Expand All @@ -44,9 +47,11 @@ impl Approx for (&GlobalCurve, RangeOnCurve) {
fn approx(self, tolerance: Tolerance) -> Self::Approximation {
let (curve, range) = self;

match curve.kind() {
CurveKind::Circle(curve) => approx_circle(curve, range, tolerance),
CurveKind::Line(_) => vec![],
match curve.path() {
GlobalPath::Circle(circle) => {
approx_circle(&circle, range, tolerance)
}
GlobalPath::Line(_) => vec![],
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use fj_math::{Point, Segment};

use crate::objects::{Curve, CurveKind, HalfEdge};
use crate::{
objects::{Curve, HalfEdge},
path::SurfacePath,
};

use super::LineSegmentIntersection;

Expand Down Expand Up @@ -29,14 +32,14 @@ impl CurveEdgeIntersection {
/// 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.kind() {
CurveKind::Line(line) => line,
let curve_as_line = match curve.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().kind() {
CurveKind::Line(line) => line,
let edge_curve_as_line = match half_edge.curve().path() {
SurfacePath::Line(line) => line,
_ => {
todo!("Curve-edge intersection only supports line segments")
}
Expand All @@ -50,7 +53,7 @@ impl CurveEdgeIntersection {
};

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

let intersection = match intersection {
LineSegmentIntersection::Point { point_on_line } => Self::Point {
Expand Down
9 changes: 5 additions & 4 deletions crates/fj-kernel/src/algorithms/intersect/ray_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use fj_math::Segment;

use crate::{
algorithms::intersect::{HorizontalRayToTheRight, Intersect},
objects::{CurveKind, HalfEdge},
objects::HalfEdge,
path::SurfacePath,
};

use super::ray_segment::RaySegmentIntersection;
Expand All @@ -15,9 +16,9 @@ impl Intersect for (&HorizontalRayToTheRight<2>, &HalfEdge) {
fn intersect(self) -> Option<Self::Intersection> {
let (ray, edge) = self;

let line = match edge.curve().kind() {
CurveKind::Line(line) => line,
CurveKind::Circle(_) => {
let line = match edge.curve().path() {
SurfacePath::Line(line) => line,
SurfacePath::Circle(_) => {
todo!("Casting rays against circles is not supported yet")
}
};
Expand Down
7 changes: 4 additions & 3 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use fj_math::{Point, Scalar, Vector};

use crate::{
algorithms::intersect::face_point::FacePointIntersection,
objects::{CurveKind, Face, HalfEdge, Vertex},
objects::{Face, HalfEdge, Vertex},
path::GlobalPath,
};

use super::{HorizontalRayToTheRight, Intersect};
Expand All @@ -17,10 +18,10 @@ impl Intersect for (&HorizontalRayToTheRight<3>, &Face) {

let (plane_origin, plane_direction_1, plane_direction_2) =
match face.surface().u() {
CurveKind::Circle(_) => todo!(
GlobalPath::Circle(_) => todo!(
"Casting a ray against a swept circle is not supported yet"
),
CurveKind::Line(line) => {
GlobalPath::Line(line) => {
(line.origin(), line.direction(), face.surface().v())
}
};
Expand Down
15 changes: 9 additions & 6 deletions crates/fj-kernel/src/algorithms/intersect/surface_surface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use fj_math::{Line, Point, Scalar, Vector};

use crate::objects::{Curve, CurveKind, GlobalCurve, Surface};
use crate::{
objects::{Curve, GlobalCurve, Surface},
path::{GlobalPath, SurfacePath},
};

/// The intersection between two surfaces
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
Expand Down Expand Up @@ -49,11 +52,11 @@ impl SurfaceSurfaceIntersection {

let curves = planes_parametric.map(|(surface, plane)| {
let local = project_line_into_plane(&line, &plane);
let global = CurveKind::Line(Line::from_origin_and_direction(
let global = GlobalPath::Line(Line::from_origin_and_direction(
origin, direction,
));

Curve::new(surface, local, GlobalCurve::from_kind(global))
Curve::new(surface, local, GlobalCurve::from_path(global))
});

Some(Self {
Expand All @@ -74,7 +77,7 @@ impl PlaneParametric {
pub fn extract_from_surface(surface: &Surface) -> Self {
let (line, path) = {
let line = match surface.u() {
CurveKind::Line(line) => line,
GlobalPath::Line(line) => line,
_ => todo!(
"Only plane-plane intersection is currently supported."
),
Expand Down Expand Up @@ -120,7 +123,7 @@ impl PlaneConstantNormal {
fn project_line_into_plane(
line: &Line<3>,
plane: &PlaneParametric,
) -> CurveKind<2> {
) -> SurfacePath {
let line_origin_relative_to_plane = line.origin() - plane.origin;
let line_origin_in_plane = Vector::from([
plane
Expand All @@ -143,7 +146,7 @@ fn project_line_into_plane(
line_direction_in_plane,
);

CurveKind::Line(line)
SurfacePath::Line(line)
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ impl Sweep for GlobalCurve {
type Swept = Surface;

fn sweep(self, path: impl Into<Vector<3>>) -> Self::Swept {
Surface::new(*self.kind(), path.into())
Surface::new(self.path(), path.into())
}
}
26 changes: 14 additions & 12 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use fj_math::{Line, Scalar, Vector};
use crate::{
algorithms::{reverse::Reverse, transform::TransformObject},
objects::{
Curve, CurveKind, Cycle, Face, GlobalEdge, HalfEdge, SurfaceVertex,
Vertex,
Curve, Cycle, Face, GlobalEdge, HalfEdge, SurfaceVertex, Vertex,
},
path::SurfacePath,
};

use super::Sweep;
Expand All @@ -32,13 +32,14 @@ impl Sweep for (HalfEdge, Color) {

let curve = {
// Please note that creating a line here is correct, even if the
// global curve is a circle. Projected into the side surface, it is
// going to be a line either way.
let kind = CurveKind::Line(Line::from_points_with_line_coords(
points_curve_and_surface,
));
// global curve is a circle. Projected into the side surface, it
// is going to be a line either way.
let path =
SurfacePath::Line(Line::from_points_with_line_coords(
points_curve_and_surface,
));

Curve::new(surface, kind, *edge.curve().global_form())
Curve::new(surface, path, *edge.curve().global_form())
};

let vertices = {
Expand Down Expand Up @@ -93,11 +94,12 @@ impl Sweep for (HalfEdge, Color) {
// Please note that creating a line here is correct, even if the
// global curve is a circle. Projected into the side surface, it
// is going to be a line either way.
let kind = CurveKind::Line(Line::from_points_with_line_coords(
points_curve_and_surface,
));
let path =
SurfacePath::Line(Line::from_points_with_line_coords(
points_curve_and_surface,
));

Curve::new(surface, kind, global)
Curve::new(surface, path, global)
};

let global = GlobalEdge::new(*curve.global_form(), global_vertices);
Expand Down
7 changes: 4 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use fj_math::{Scalar, Vector};

use crate::{
algorithms::{reverse::Reverse, transform::TransformObject},
objects::{CurveKind, Face, Shell},
objects::{Face, Shell},
path::GlobalPath,
};

use super::Sweep;
Expand All @@ -17,11 +18,11 @@ impl Sweep for Face {

let is_negative_sweep = {
let a = match self.surface().u() {
CurveKind::Circle(_) => todo!(
GlobalPath::Circle(_) => todo!(
"Sweeping from faces defined in round surfaces is not \
supported"
),
CurveKind::Line(line) => line.direction(),
GlobalPath::Line(line) => line.direction(),
};
let b = self.surface().v();

Expand Down
13 changes: 8 additions & 5 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use fj_math::{Line, Point, Scalar, Vector};

use crate::objects::{
Curve, CurveKind, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Surface,
SurfaceVertex, Vertex,
use crate::{
objects::{
Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Surface,
SurfaceVertex, Vertex,
},
path::SurfacePath,
};

use super::Sweep;
Expand Down Expand Up @@ -46,7 +49,7 @@ impl Sweep for (Vertex, Surface) {
//
// Let's make sure that these requirements are met.
{
assert_eq!(vertex.curve().global_form().kind(), &surface.u());
assert_eq!(vertex.curve().global_form().path(), surface.u());
assert_eq!(path, surface.v());
}

Expand Down Expand Up @@ -78,7 +81,7 @@ impl Sweep for (Vertex, Surface) {
// `Edge` is straight-forward.
let curve = {
let line = Line::from_points(points_surface);
Curve::new(surface, CurveKind::Line(line), *edge_global.curve())
Curve::new(surface, SurfacePath::Line(line), *edge_global.curve())
};

// And now the vertices. Again, nothing wild here.
Expand Down
25 changes: 19 additions & 6 deletions crates/fj-kernel/src/algorithms/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
use fj_math::{Transform, Vector};

use crate::objects::{
Curve, Cycle, Face, Faces, GlobalCurve, GlobalVertex, HalfEdge, Shell,
Sketch, Solid, Surface, SurfaceVertex, Vertex,
use crate::{
objects::{
Curve, Cycle, Face, Faces, GlobalCurve, GlobalVertex, HalfEdge, Shell,
Sketch, Solid, Surface, SurfaceVertex, Vertex,
},
path::GlobalPath,
};

/// Transform an object
Expand Down Expand Up @@ -40,7 +43,7 @@ impl TransformObject for Curve {
let global = self.global_form().transform(transform);

// Don't need to transform `self.kind`, as that's in local form.
Curve::new(surface, *self.kind(), global)
Curve::new(surface, self.path(), global)
}
}

Expand Down Expand Up @@ -80,8 +83,18 @@ impl TransformObject for Faces {

impl TransformObject for GlobalCurve {
fn transform(self, transform: &Transform) -> Self {
let kind = self.kind().transform(transform);
GlobalCurve::from_kind(kind)
GlobalCurve::from_path(self.path().transform(transform))
}
}

impl TransformObject for GlobalPath {
fn transform(self, transform: &Transform) -> Self {
match self {
Self::Circle(curve) => {
Self::Circle(transform.transform_circle(&curve))
}
Self::Line(curve) => Self::Line(transform.transform_line(&curve)),
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/fj-kernel/src/algorithms/validate/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ pub fn validate_curve(
let points_curve = [-2., -1., 0., 1., 2.].map(|point| Point::from([point]));

for point_curve in points_curve {
let point_surface = curve.kind().point_from_curve_coords(point_curve);
let point_surface = curve.path().point_from_path_coords(point_curve);
let point_surface_as_global =
curve.surface().point_from_surface_coords(point_surface);
let point_global = curve
.global_form()
.kind()
.point_from_curve_coords(point_curve);
.path()
.point_from_path_coords(point_curve);

let distance = (point_surface_as_global - point_global).magnitude();

Expand Down Expand Up @@ -51,8 +51,8 @@ pub fn validate_vertex(
let local_as_global = vertex
.curve()
.global_form()
.kind()
.point_from_curve_coords(local);
.path()
.point_from_path_coords(local);
let global = vertex.global_form().position();
let distance = (local_as_global - global).magnitude();

Expand Down
Loading

0 comments on commit cb3c7e0

Please sign in to comment.