Skip to main content

CurvePath

Struct CurvePath 

Source
pub struct CurvePath<P: CurveVector> {
    pub curves: Vec<CurveRef<P>>,
    pub auto_close: bool,
    pub arc_length_divisions: usize,
    pub needs_update: Cell<bool>,
    /* private fields */
}
Expand description

CurvePath: a sequence of connected curves, itself a Curve.

§The two caches

CurvePath.getPoint( t ) is built on getLength(), which sums every sub-curve’s length, and the inherited getPointAt( u ) maps u through getLengths(), which calls getPoint 201 times. Uncached that is quadratic, so unlike the leaf curves (see super::curve) this keeps both of three.js’ caches, with three.js’ own invalidation rules:

  • cacheLengths (the per-curve running sums, getCurveLengths()) is reused while it has one entry per curve, so adding a curve refreshes it;
  • cacheArcLengths (Curve.getLengths()) is reused while it has divisions + 1 entries and needsUpdate is unset. Adding a curve does not refresh it — in three.js either — so get_point_at after a later line_to maps through the old path’s arc lengths until update_arc_lengths is called. That is reproduced on purpose: it is what three.js computes.

Fields§

§curves: Vec<CurveRef<P>>

The curves, in order.

§auto_close: bool

Whether the path should automatically be closed by a line curve.

§arc_length_divisions: usize

Curve.arcLengthDivisions, default 200.

§needs_update: Cell<bool>

this.needsUpdate.

Implementations§

Source§

impl<P: CurveVector> CurvePath<P>

Source

pub fn new() -> Self

new CurvePath().

Source

pub fn add(&mut self, curve: impl Curve<Point = P> + 'static)

CurvePath.add( curve ).

Source

pub fn update_arc_lengths(&self)

CurvePath.updateArcLengths().

Source

pub fn get_curve_lengths(&self) -> Vec<f64>

CurvePath.getCurveLengths(): the running sum of the sub-curves’ lengths, cached while the curve count is unchanged.

Source§

impl<P: LineVector> CurvePath<P>

Source

pub fn close_path(&mut self) -> &mut Self

CurvePath.closePath(): adds a line curve back to the start if the path does not already end there.

Trait Implementations§

Source§

impl<P: CurveVector> Clone for CurvePath<P>

Source§

fn clone(&self) -> Self

CurvePath.clone(): the curves, autoClose and arcLengthDivisions; the caches start empty, as a fresh three.js instance’s do.

1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<P: CurveVector> Curve for CurvePath<P>

Source§

fn get_point(&self, t: f64) -> P

CurvePath.getPoint( t ).

§Panics

Where three.js returns null: when t * getLength() lies past the last curve (t > 1, or an empty path).

Source§

fn get_length(&self) -> f64

CurvePath.getLength().

We cannot use the default THREE.Curve getPoint() with getLength() because in THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath getPoint() depends on getLength

Source§

fn get_lengths(&self, divisions: usize) -> Vec<f64>

Curve.getLengths( divisions ) with its cacheArcLengths cache; see the type’s doc.

Source§

fn get_spaced_points(&self, divisions: usize) -> Vec<P>

CurvePath.getSpacedPoints( divisions ): getPoint, not getPointAt, at even t, plus the first point again when autoClose is set.

Source§

fn get_points(&self, divisions: usize) -> Vec<P>

CurvePath.getPoints( divisions ): each curve sampled at its own resolution (Curve::curve_path_resolution), consecutive duplicates dropped.

Source§

type Point = P

Vector2 or Vector3.
Source§

fn type_name(&self) -> &'static str

Curve.type: 'LineCurve', 'EllipseCurve', 'Path', …
Source§

fn arc_length_divisions(&self) -> usize

Curve.arcLengthDivisions, default 200.
Source§

fn curve_path_resolution(&self, divisions: usize) -> usize

How many divisions CurvePath.getPoints( divisions ) asks this curve for. three.js writes it as a chain of brand checks in CurvePath: isEllipseCurve doubles it, isLineCurve / isLineCurve3 use 1 and isSplineCurve multiplies by its point count; every other curve uses divisions as given. Here each of those subclasses overrides this.
Source§

fn is_closed_catmull_rom(&self) -> bool

extrudePath.isCatmullRomCurve3 ? extrudePath.closed : false — the one place three.js reads a subclass’ closed generically (ExtrudeGeometry). Only CatmullRomCurve3 overrides it.
Source§

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

Curve.getPointAt( u, optionalTarget ).
Source§

fn get_u_to_t_mapping(&self, u: f64, distance: Option<f64>) -> f64

Curve.getUtoTmapping( u, distance ), statement for statement.
Source§

fn get_tangent(&self, t: f64) -> Self::Point

Curve.getTangent( t, optionalTarget ).
Source§

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

Curve.getTangentAt( u, optionalTarget ).
Source§

fn compute_frenet_frames(&self, segments: usize, closed: bool) -> FrenetFrames

Curve.computeFrenetFrames( segments, closed ). Read more
Source§

impl<P: CurveVector> Debug for CurvePath<P>

Source§

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

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

impl<P: CurveVector> Default for CurvePath<P>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<P> !Freeze for CurvePath<P>

§

impl<P> !RefUnwindSafe for CurvePath<P>

§

impl<P> !Send for CurvePath<P>

§

impl<P> !Sync for CurvePath<P>

§

impl<P> !UnwindSafe for CurvePath<P>

§

impl<P> Unpin for CurvePath<P>
where Vec<Rc<dyn Curve<Point = P>>>: Unpin,

§

impl<P> UnsafeUnpin for CurvePath<P>
where Vec<Rc<dyn Curve<Point = P>>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.