#[non_exhaustive]pub enum Curve {
Line(Line),
Circle(Circle),
Ellipse(Ellipse),
Parabola(Parabola),
Hyperbola(Hyperbola),
BSpline(BSplineCurve),
}Expand description
Enum adaptor unifying the concrete 3D curve types behind a single value
type, so callers can build a heterogeneous collection of curves and
evaluate them uniformly through ParametricCurve.
Marked #[non_exhaustive]: future tasks add further variants (e.g. a
B-spline curve) without that being a breaking change.
§Examples
use geomcore::curves::{Curve, ParametricCurve};
use geomcore::{Circle, Line, Point, Vector};
let curves: Vec<Curve> = vec![
Line::new(Point::ORIGIN, Vector::X).unwrap().into(),
Circle::new(Point::ORIGIN, Vector::Z, 1.0).unwrap().into(),
];
let points: Vec<Point> = curves.iter().map(|c| c.eval_point(0.0)).collect();
assert_eq!(points[0], Point::ORIGIN);
assert_eq!(points[1], Point::new(1.0, 0.0, 0.0));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Line(Line)
A Line curve.
Circle(Circle)
A Circle curve.
Ellipse(Ellipse)
An Ellipse curve.
Parabola(Parabola)
A Parabola curve.
Hyperbola(Hyperbola)
A Hyperbola curve.
BSpline(BSplineCurve)
A BSplineCurve curve.
Implementations§
Source§impl Curve
impl Curve
Sourcepub fn to_bspline(&self) -> Result<BSplineCurve, BSplineConversionError>
pub fn to_bspline(&self) -> Result<BSplineCurve, BSplineConversionError>
The whole curve as a B-spline: a B-spline is cloned, an elementary
curve converted by ElementaryCurve::to_bspline.
§Errors
Returns BSplineConversionError::Unbounded for a line, parabola
or hyperbola.
§Examples
use geomcore::curves::{BSplineConversionError, Curve};
use geomcore::{Ellipse, Parabola, Point, Vector};
let ellipse = Ellipse::new(Point::ORIGIN, Vector::Z, Vector::X, 2.0, 1.0).unwrap();
let bspline = Curve::from(ellipse).to_bspline().unwrap();
assert_eq!(Curve::from(bspline.clone()).to_bspline(), Ok(bspline));
let parabola = Parabola::new(Point::ORIGIN, Vector::Z, Vector::X, 1.0).unwrap();
assert_eq!(
Curve::from(parabola).to_bspline().err(),
Some(BSplineConversionError::Unbounded)
);Source§impl Curve
impl Curve
Sourcepub fn project_point(&self, point: Point, tol: Tolerance) -> CurveProjection
pub fn project_point(&self, point: Point, tol: Tolerance) -> CurveProjection
Projects point onto the curve: the closest parameter, the closest
point and the distance. Distances within tol.confusion snap to
0.0.
§Examples
use geomcore::curves::Curve;
use geomcore::{Line, Point, Tolerance, Vector};
let curve = Curve::from(Line::new(Point::ORIGIN, Vector::X).unwrap());
let projection = curve.project_point(Point::new(2.0, 1.0, 0.0), Tolerance::DEFAULT);
assert_eq!(projection.point, Point::new(2.0, 0.0, 0.0));
assert_eq!(projection.distance, 1.0);Sourcepub fn project_points(
&self,
points: &[Point],
tol: Tolerance,
) -> Vec<CurveProjection>
pub fn project_points( &self, points: &[Point], tol: Tolerance, ) -> Vec<CurveProjection>
Projects each point in points onto the curve.
Sourcepub fn parameter_of(&self, point: Point) -> f64
pub fn parameter_of(&self, point: Point) -> f64
The parameter of the point of the curve closest to point.
An elementary curve uses its closed form (see
ElementaryCurve::parameter_of). A B-spline projects the point
with Tolerance::DEFAULT and returns the projection’s parameter;
call project_point to choose the
tolerance.
§Examples
use geomcore::curves::Curve;
use geomcore::{Circle, Point, Vector};
let curve = Curve::from(Circle::new(Point::ORIGIN, Vector::Z, 2.0).unwrap());
let parameter = curve.parameter_of(Point::new(0.0, 2.0, 0.0));
assert!((parameter - std::f64::consts::FRAC_PI_2).abs() < 1e-12);Sourcepub fn as_elementary(&self) -> Option<ElementaryCurve>
pub fn as_elementary(&self) -> Option<ElementaryCurve>
The curve as an ElementaryCurve, or None for a B-spline.
Trait Implementations§
Source§impl From<BSplineCurve> for Curve
impl From<BSplineCurve> for Curve
Source§fn from(curve: BSplineCurve) -> Curve
fn from(curve: BSplineCurve) -> Curve
Wraps a BSplineCurve as a Curve::BSpline.
Source§impl From<ElementaryCurve> for Curve
impl From<ElementaryCurve> for Curve
Source§fn from(curve: ElementaryCurve) -> Curve
fn from(curve: ElementaryCurve) -> Curve
Wraps an ElementaryCurve as the matching Curve variant.
Source§impl HasBoundingBox for Curve
impl HasBoundingBox for Curve
Source§fn bounding_box(&self) -> Option<BoundingBox>
fn bounding_box(&self) -> Option<BoundingBox>
None if the shape is
unbounded.Source§impl Intersect for Curve
impl Intersect for Curve
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<BSplineCurve> for Curve
impl Intersect<BSplineCurve> for Curve
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§fn intersect(
&self,
other: &BSplineCurve,
tol: Tolerance,
) -> CurveCurveIntersection
fn intersect( &self, other: &BSplineCurve, tol: Tolerance, ) -> CurveCurveIntersection
self with other, deciding tangency and coincidence
with tol.Source§impl Intersect<BSplineSurface> for Curve
impl Intersect<BSplineSurface> for Curve
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§fn intersect(
&self,
other: &BSplineSurface,
tol: Tolerance,
) -> CurveSurfaceIntersection
fn intersect( &self, other: &BSplineSurface, tol: Tolerance, ) -> CurveSurfaceIntersection
self with other, deciding tangency and coincidence
with tol.Source§impl Intersect<Circle> for Curve
impl Intersect<Circle> for Curve
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Cone> for Curve
impl Intersect<Cone> for Curve
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Curve> for Plane
impl Intersect<Curve> for Plane
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Curve> for Cylinder
impl Intersect<Curve> for Cylinder
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Curve> for Cone
impl Intersect<Curve> for Cone
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Curve> for Sphere
impl Intersect<Curve> for Sphere
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Curve> for Torus
impl Intersect<Curve> for Torus
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Curve> for BSplineSurface
impl Intersect<Curve> for BSplineSurface
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Curve> for Surface
impl Intersect<Curve> for Surface
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Curve> for ElementarySurface
impl Intersect<Curve> for ElementarySurface
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Curve> for Line
impl Intersect<Curve> for Line
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Curve> for Circle
impl Intersect<Curve> for Circle
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Curve> for Ellipse
impl Intersect<Curve> for Ellipse
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Curve> for Parabola
impl Intersect<Curve> for Parabola
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Curve> for Hyperbola
impl Intersect<Curve> for Hyperbola
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Curve> for BSplineCurve
impl Intersect<Curve> for BSplineCurve
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Curve> for ElementaryCurve
impl Intersect<Curve> for ElementaryCurve
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl<X: CurveOperand> Intersect<Curve> for TrimmedCurve<X>
impl<X: CurveOperand> Intersect<Curve> for TrimmedCurve<X>
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Cylinder> for Curve
impl Intersect<Cylinder> for Curve
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<ElementaryCurve> for Curve
impl Intersect<ElementaryCurve> for Curve
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§fn intersect(
&self,
other: &ElementaryCurve,
tol: Tolerance,
) -> CurveCurveIntersection
fn intersect( &self, other: &ElementaryCurve, tol: Tolerance, ) -> CurveCurveIntersection
self with other, deciding tangency and coincidence
with tol.Source§impl Intersect<ElementarySurface> for Curve
impl Intersect<ElementarySurface> for Curve
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§fn intersect(
&self,
other: &ElementarySurface,
tol: Tolerance,
) -> CurveSurfaceIntersection
fn intersect( &self, other: &ElementarySurface, tol: Tolerance, ) -> CurveSurfaceIntersection
self with other, deciding tangency and coincidence
with tol.Source§impl Intersect<Ellipse> for Curve
impl Intersect<Ellipse> for Curve
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Hyperbola> for Curve
impl Intersect<Hyperbola> for Curve
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Line> for Curve
impl Intersect<Line> for Curve
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Parabola> for Curve
impl Intersect<Parabola> for Curve
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§impl Intersect<Plane> for Curve
impl Intersect<Plane> for Curve
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Sphere> for Curve
impl Intersect<Sphere> for Curve
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Surface> for Curve
impl Intersect<Surface> for Curve
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl Intersect<Torus> for Curve
impl Intersect<Torus> for Curve
Source§type Output = CurveSurfaceIntersection
type Output = CurveSurfaceIntersection
Self with Rhs.Source§impl<X: CurveOperand> Intersect<TrimmedCurve<X>> for Curvewhere
<Curve as CurveOperand>::Basis: ExactCurveCurve<X::Basis>,
impl<X: CurveOperand> Intersect<TrimmedCurve<X>> for Curvewhere
<Curve as CurveOperand>::Basis: ExactCurveCurve<X::Basis>,
Source§type Output = CurveCurveIntersection
type Output = CurveCurveIntersection
Self with Rhs.Source§fn intersect(
&self,
other: &TrimmedCurve<X>,
tol: Tolerance,
) -> CurveCurveIntersection
fn intersect( &self, other: &TrimmedCurve<X>, tol: Tolerance, ) -> CurveCurveIntersection
self with other, deciding tangency and coincidence
with tol.Source§impl IntersectExact for Curve
impl IntersectExact for Curve
Source§fn intersect_exact(
&self,
other: &Curve,
tol: Tolerance,
) -> ExactCurveCurveIntersection
fn intersect_exact( &self, other: &Curve, tol: Tolerance, ) -> ExactCurveCurveIntersection
Dispatches to the exact intersection of the pair, or reports
ExactCurveCurveIntersection::NotAnalytic when either is a B-spline.
Source§type Output = ExactCurveCurveIntersection
type Output = ExactCurveCurveIntersection
Self with Rhs.Source§impl IntersectExact<Curve> for Surface
impl IntersectExact<Curve> for Surface
Source§fn intersect_exact(
&self,
other: &Curve,
tol: Tolerance,
) -> ExactCurveSurfaceIntersection
fn intersect_exact( &self, other: &Curve, tol: Tolerance, ) -> ExactCurveSurfaceIntersection
The same result as in the other argument order.
Source§type Output = ExactCurveSurfaceIntersection
type Output = ExactCurveSurfaceIntersection
Self with Rhs.Source§impl IntersectExact<Surface> for Curve
impl IntersectExact<Surface> for Curve
Source§fn intersect_exact(
&self,
other: &Surface,
tol: Tolerance,
) -> ExactCurveSurfaceIntersection
fn intersect_exact( &self, other: &Surface, tol: Tolerance, ) -> ExactCurveSurfaceIntersection
Dispatches to the exact intersection of the pair, or reports
ExactCurveSurfaceIntersection::NotAnalytic when either is a
B-spline.
Source§type Output = ExactCurveSurfaceIntersection
type Output = ExactCurveSurfaceIntersection
Self with Rhs.Source§impl ParametricCurve for Curve
impl ParametricCurve for Curve
Source§fn eval_point(&self, u: f64) -> Point
fn eval_point(&self, u: f64) -> Point
u.Source§fn eval_derivative(&self, u: f64, order: u32) -> Vector
fn eval_derivative(&self, u: f64, order: u32) -> Vector
order at parameter u.Source§fn eval_d1(&self, u: f64) -> (Point, Vector)
fn eval_d1(&self, u: f64) -> (Point, Vector)
u. Read moreSource§fn eval_d2(&self, u: f64) -> (Point, Vector, Vector)
fn eval_d2(&self, u: f64) -> (Point, Vector, Vector)
u. Read moreSource§fn bounds(&self) -> (f64, f64)
fn bounds(&self) -> (f64, f64)
(first, last). Unbounded
curves use (f64::NEG_INFINITY, f64::INFINITY).Source§fn period(&self) -> Option<f64>
fn period(&self) -> Option<f64>
None if the curve is not periodic.Source§fn eval_points(&self, us: &[f64]) -> Vec<Point>
fn eval_points(&self, us: &[f64]) -> Vec<Point>
us. Read moreSource§fn is_closed(&self, tol: Tolerance) -> bool
fn is_closed(&self, tol: Tolerance) -> bool
Source§fn continuity(&self, u: f64, tol: Tolerance) -> Continuity
fn continuity(&self, u: f64, tol: Tolerance) -> Continuity
Source§fn min_continuity(&self) -> Continuity
fn min_continuity(&self) -> Continuity
Continuity over bounds, ends
excluded (Smooth when no knot constrains it): the lowest
continuity anywhere on the curve. Default
implementation: smooth.Source§fn as_bspline(&self) -> Option<&BSplineCurve>
fn as_bspline(&self) -> Option<&BSplineCurve>
Source§fn as_elementary(&self) -> Option<ElementaryCurve>
fn as_elementary(&self) -> Option<ElementaryCurve>
Source§fn tangent(&self, u: f64, tol: Tolerance) -> Option<Vector>
fn tangent(&self, u: f64, tol: Tolerance) -> Option<Vector>
C'/|C'| at parameter u, or None where the speed
vanishes (a cusp or a stop). The speed counts as zero when the
distance |C'| × width it would cover across the parameter range
(width = last - first of bounds, the model size
tol.confusion / tol.angular when unbounded) is within
tol.confusion, so rescaling the parameter does not change the
result (see ADR 0010). Read moreSource§fn curvature_center(&self, u: f64, tol: Tolerance) -> Option<Point>
fn curvature_center(&self, u: f64, tol: Tolerance) -> Option<Point>
P + N/κ at parameter u (N the principal
normal, κ the curvature), or None where the speed vanishes or
the curve runs straight, so the centre is at infinity. The curve
runs straight where its second derivative is parallel to the first
within tol.angular, or where the part of it that turns away from
the first, |C' × C''| / |C'|, is negligible: the distance it
would cover across the parameter range, times width², is within
tol.confusion, by the rule of tangent. Both
tests are unchanged by rescaling the parameter. Together they catch
a straight B-spline whose rounding leaves a curvature of order
1e-16 rather than zero, including where its second derivative is
small and its rounding error points in an arbitrary direction. Read moreSource§fn is_periodic(&self) -> bool
fn is_periodic(&self) -> bool
period is Some.Source§impl PointExtrema for Curve
impl PointExtrema for Curve
Source§fn extrema(&self, point: Point, tol: Tolerance) -> Vec<CurveProjection>
fn extrema(&self, point: Point, tol: Tolerance) -> Vec<CurveProjection>
point (other stationary points may
be listed too; a valley of equal minima is represented by one of
its points), ordered by ascending distance, the global closest
point first. Distances within tol.confusion snap to 0.0. Read more