Skip to main content

Curve

Enum Curve 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

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

Source

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);
Source

pub fn project_points( &self, points: &[Point], tol: Tolerance, ) -> Vec<CurveProjection>

Projects each point in points onto the curve.

Source

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);
Source

pub fn as_elementary(&self) -> Option<ElementaryCurve>

The curve as an ElementaryCurve, or None for a B-spline.

Trait Implementations§

Source§

impl Clone for Curve

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Curve

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<BSplineCurve> for Curve

Source§

impl From<Circle> for Curve

Source§

fn from(curve: Circle) -> Curve

Wraps a Circle as a Curve::Circle.

Source§

impl From<ElementaryCurve> for Curve

Source§

fn from(curve: ElementaryCurve) -> Curve

Wraps an ElementaryCurve as the matching Curve variant.

Source§

impl From<Ellipse> for Curve

Source§

fn from(curve: Ellipse) -> Curve

Wraps an Ellipse as a Curve::Ellipse.

Source§

impl From<Hyperbola> for Curve

Source§

impl From<Line> for Curve

Source§

fn from(curve: Line) -> Curve

Wraps a Line as a Curve::Line.

Source§

impl From<Parabola> for Curve

Source§

fn from(curve: Parabola) -> Curve

Wraps a Parabola as a Curve::Parabola.

Source§

impl HasBoundingBox for Curve

Source§

fn bounding_box(&self) -> Option<BoundingBox>

The axis-aligned box bounding the shape, or None if the shape is unbounded.
Source§

impl Intersect for Curve

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<BSplineCurve> for Curve

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect( &self, other: &BSplineCurve, tol: Tolerance, ) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<BSplineSurface> for Curve

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect( &self, other: &BSplineSurface, tol: Tolerance, ) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Circle> for Curve

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Circle, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Cone> for Curve

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Cone, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for Plane

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for Cylinder

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for Cone

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for Sphere

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for Torus

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for BSplineSurface

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for Surface

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for ElementarySurface

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for Line

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for Circle

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for Ellipse

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for Parabola

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for Hyperbola

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for BSplineCurve

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Curve> for ElementaryCurve

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl<X: CurveOperand> Intersect<Curve> for TrimmedCurve<X>

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Curve, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Cylinder> for Curve

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect( &self, other: &Cylinder, tol: Tolerance, ) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<ElementaryCurve> for Curve

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect( &self, other: &ElementaryCurve, tol: Tolerance, ) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<ElementarySurface> for Curve

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect( &self, other: &ElementarySurface, tol: Tolerance, ) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Ellipse> for Curve

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Ellipse, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Hyperbola> for Curve

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Hyperbola, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Line> for Curve

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Line, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Parabola> for Curve

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Parabola, tol: Tolerance) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Plane> for Curve

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Plane, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Sphere> for Curve

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Sphere, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Surface> for Curve

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Surface, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl Intersect<Torus> for Curve

Source§

type Output = CurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect(&self, other: &Torus, tol: Tolerance) -> CurveSurfaceIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl<X: CurveOperand> Intersect<TrimmedCurve<X>> for Curve
where <Curve as CurveOperand>::Basis: ExactCurveCurve<X::Basis>,

Source§

type Output = CurveCurveIntersection

The result of intersecting Self with Rhs.
Source§

fn intersect( &self, other: &TrimmedCurve<X>, tol: Tolerance, ) -> CurveCurveIntersection

Intersects self with other, deciding tangency and coincidence with tol.
Source§

impl IntersectExact for Curve

Source§

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

The result of intersecting Self with Rhs.
Source§

impl IntersectExact<Curve> for Surface

Source§

fn intersect_exact( &self, other: &Curve, tol: Tolerance, ) -> ExactCurveSurfaceIntersection

The same result as in the other argument order.

Source§

type Output = ExactCurveSurfaceIntersection

The result of intersecting Self with Rhs.
Source§

impl IntersectExact<Surface> for Curve

Source§

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

The result of intersecting Self with Rhs.
Source§

impl ParametricCurve for Curve

Source§

fn eval_point(&self, u: f64) -> Point

Evaluates the point on the curve at parameter u.
Source§

fn eval_derivative(&self, u: f64, order: u32) -> Vector

Evaluates the derivative of the given order at parameter u.
Source§

fn eval_d1(&self, u: f64) -> (Point, Vector)

Evaluates the point and the first derivative at parameter u. Read more
Source§

fn eval_d2(&self, u: f64) -> (Point, Vector, Vector)

Evaluates the point and the first and second derivatives at parameter u. Read more
Source§

fn bounds(&self) -> (f64, f64)

Returns the curve’s parameter bounds as (first, last). Unbounded curves use (f64::NEG_INFINITY, f64::INFINITY).
Source§

fn period(&self) -> Option<f64>

Returns the curve’s period, or None if the curve is not periodic.
Source§

fn eval_points(&self, us: &[f64]) -> Vec<Point>

Evaluates the points on the curve at each parameter in us. Read more
Source§

fn is_closed(&self, tol: Tolerance) -> bool

Returns whether the curve’s ends meet, i.e. whether travelling along it returns to its start. Read more
Source§

fn continuity(&self, u: f64, tol: Tolerance) -> Continuity

Continuity at parameter u. Read more
Source§

fn min_continuity(&self) -> Continuity

Minimum 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>

The B-spline this curve evaluates: the curve itself, or the basis of a trimmed B-spline, of which the curve is the piece over bounds. None for any other curve. Read more
Source§

fn as_elementary(&self) -> Option<ElementaryCurve>

The elementary curve this curve evaluates: the curve itself, or the basis of a trimmed elementary curve, of which the curve is the piece over bounds. None for any other curve. Read more
Source§

fn tangent(&self, u: f64, tol: Tolerance) -> Option<Vector>

Unit tangent 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 more
Source§

fn curvature(&self, u: f64, tol: Tolerance) -> Option<f64>

Scalar curvature |C' × C''| / |C'|³ (the turn rate |dT/ds| of the unit tangent per unit arc length) at parameter u, or None where the speed vanishes, by the same test as tangent. Zero on a straight line. Read more
Source§

fn curvature_center(&self, u: f64, tol: Tolerance) -> Option<Point>

Centre of curvature 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 more
Source§

fn is_periodic(&self) -> bool

Returns whether the curve is periodic, i.e. whether period is Some.
Source§

impl PartialEq for Curve

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PointExtrema for Curve

Source§

fn extrema(&self, point: Point, tol: Tolerance) -> Vec<CurveProjection>

Parameters on the curve’s own domain that include every local minimum of the distance from 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
Source§

impl StructuralPartialEq for Curve

Auto Trait Implementations§

§

impl !Freeze for Curve

§

impl RefUnwindSafe for Curve

§

impl Send for Curve

§

impl Sync for Curve

§

impl Unpin for Curve

§

impl UnsafeUnpin for Curve

§

impl UnwindSafe for Curve

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.