Struct vek::bezier::repr_simd::CubicBezier3

source ·
pub struct CubicBezier3<T> {
    pub start: Vec3<T>,
    pub ctrl0: Vec3<T>,
    pub ctrl1: Vec3<T>,
    pub end: Vec3<T>,
}
Expand description

A 3D Bézier curve with two control points.

3x3 and 4x4 matrices can be multiplied by a Bézier curve to transform all of its points.

Fields§

§start: Vec3<T>

Starting point of the curve.

§ctrl0: Vec3<T>

First control point of the curve, associated with start.

§ctrl1: Vec3<T>

Second control point of the curve, associated with end.

§end: Vec3<T>

End point of the curve.

Implementations§

source§

impl<T: Real> CubicBezier3<T>

source

pub fn evaluate(self, t: T) -> Vec3<T>

Evaluates the position of the point lying on the curve at interpolation factor t.

This is one of the most important Bézier curve operations, because, in one way or another, it is used to render a curve to the screen. The common use case is to successively evaluate a curve at a set of values that range from 0 to 1, to approximate the curve as an array of line segments which are then rendered.

source

pub fn evaluate_derivative(self, t: T) -> Vec3<T>

Evaluates the derivative tangent at interpolation factor t, which happens to give a non-normalized tangent vector.

See also normalized_tangent().

source

pub fn matrix() -> Mat4<T>

Returns the constant matrix M such that, given T = [1, t*t, t*t*t, t*t*t*t] and P the vector of control points, dot(T * M, P) evalutes the Bezier curve at ‘t’.

This function name is arguably dubious.

source

pub fn split(self, t: T) -> [Self; 2]

Splits this cubic Bézier curve into two curves, at interpolation factor t.

source

pub fn unit_quarter_circle() -> Self

Gets the cubic Bézier curve that approximates a unit quarter circle.

You can build a good-looking circle out of 4 curves by applying symmetries to this curve.

source

pub fn unit_circle() -> [Self; 4]

Gets the 4 cubic Bézier curves that, used together, approximate a unit quarter circle.

The returned tuple is (north-east, north-west, south-west, south-east).

source§

impl<T> CubicBezier3<T>

source

pub fn reversed(self) -> Self

Gets this curve reversed, i.e swaps start with end and ctrl0 with ctrl1.

source

pub fn reverse(&mut self)

Reverses this curve, i.e swaps start with end and ctrl0 with ctrl1.

source

pub fn into_vec4(self) -> Vec4<Vec3<T>>

Converts this curve into a Vec4 of points.

source

pub fn into_tuple(self) -> (Vec3<T>, Vec3<T>, Vec3<T>, Vec3<T>)

Converts this curve into a tuple of points.

source

pub fn into_array(self) -> [Vec3<T>; 4]

Converts this curve into an array of points.

source§

impl<T: Real> CubicBezier3<T>

source

pub fn x_inflections(self) -> Option<(T, Option<T>)>

Returns the evaluation factor that gives an inflection point along the X axis, if any.

source

pub fn min_x(self) -> T

Returns the evaluation factor that gives the point on the curve which X coordinate is the minimum.

source

pub fn max_x(self) -> T

Returns the evaluation factor that gives the point on the curve which X coordinate is the maximum.

source

pub fn x_bounds(self) -> (T, T)

Returns the evaluation factors that give the points on the curve which X coordinates are the respective minimum and maximum.

source§

impl<T: Real> CubicBezier3<T>

source

pub fn y_inflections(self) -> Option<(T, Option<T>)>

Returns the evaluation factor that gives an inflection point along the Y axis, if any.

source

pub fn min_y(self) -> T

Returns the evaluation factor that gives the point on the curve which Y coordinate is the minimum.

source

pub fn max_y(self) -> T

Returns the evaluation factor that gives the point on the curve which Y coordinate is the maximum.

source

pub fn y_bounds(self) -> (T, T)

Returns the evaluation factors that give the points on the curve which Y coordinates are the respective minimum and maximum.

source§

impl<T: Real> CubicBezier3<T>

source

pub fn z_inflections(self) -> Option<(T, Option<T>)>

Returns the evaluation factor that gives an inflection point along the Z axis, if any.

source

pub fn min_z(self) -> T

Returns the evaluation factor that gives the point on the curve which Z coordinate is the minimum.

source

pub fn max_z(self) -> T

Returns the evaluation factor that gives the point on the curve which Z coordinate is the maximum.

source

pub fn z_bounds(self) -> (T, T)

Returns the evaluation factors that give the points on the curve which Z coordinates are the respective minimum and maximum.

source§

impl<T: Real> CubicBezier3<T>

source

pub fn normalized_tangent(self, t: T) -> Vec3<T>
where T: Add<T, Output = T>,

Evaluates the normalized tangent at interpolation factor t.

source

pub fn length_by_discretization(self, step_count: u16) -> T
where T: Add<T, Output = T> + From<u16>,

Approximates the curve’s length by subdividing it into step_count+1 segments.

source

pub fn aabr(self) -> Aabr<T>

Gets the Axis-Aligned Bounding Rectangle for this curve.

On 3D curves, this discards the z values.

source

pub fn flipped_x(self) -> Self

Returns this curve, flipping the x coordinate of each of its points.

source

pub fn flipped_y(self) -> Self

Returns this curve, flipping the y coordinate of each of its points.

source

pub fn flip_x(&mut self)

Flips the x coordinate of all points of this curve.

source

pub fn flip_y(&mut self)

Flips the y coordinate of all points of this curve.

source

pub fn binary_search_point_by_steps( self, p: Vec3<T>, steps: u16, epsilon: T ) -> (T, Vec3<T>)
where T: Add<T, Output = T> + From<u16>,

Searches for the point lying on this curve that is closest to p.

steps is the number of points to sample in the curve for the “broad phase” that takes place before the binary search.

epsilon denotes the desired precision for the result. The higher it is, the sooner the algorithm will finish, but the result would be less satisfactory.

§Panics

Panics if epsilon is less than or equal to T::epsilon().
epsilon must be positive and not approximately equal to zero.

source

pub fn binary_search_point<I>( self, p: Vec3<T>, coarse: I, half_interval: T, epsilon: T ) -> (T, Vec3<T>)
where T: Add<T, Output = T>, I: IntoIterator<Item = (T, Vec3<T>)>,

Searches for the point lying on this curve that is closest to p.

For an example usage, see the source code of binary_search_point_by_steps().

coarse is an iterator over pairs of (interpolation_value, point) that are assumed to, together, represent a discretization of the curve.
This parameter is used for a “broad phase” - the point yielded by coarse that is closest to p is the starting point for the binary search.
coarse may very well yield a single pair; Also, it was designed so that, if you already have the values handy, there is no need to recompute them.
This function doesn’t panic if coarse yields no element, but then it would be very unlikely for the result to be satisfactory.

half_interval is the starting value for the half of the binary search interval.

epsilon denotes the desired precision for the result. The higher it is, the sooner the algorithm will finish, but the result would be less satisfactory.

§Panics

Panics if epsilon is less than or equal to T::epsilon().
epsilon must be positive and not approximately equal to zero.

source§

impl<T: Real> CubicBezier3<T>

source

pub fn aabb(self) -> Aabb<T>

Gets the Axis-Aligned Bounding Box for this curve.

source

pub fn flipped_z(self) -> Self

Returns this curve, flipping the y coordinate of each of its points.

source

pub fn flip_z(&mut self)

Flips the x coordinate of all points of this curve.

source§

impl<T> CubicBezier3<T>

source

pub fn into_2d(self) -> CubicBezier2<T>

Converts this 3D curve to a 2D one, dropping the z elements.

Trait Implementations§

source§

impl<T: Clone> Clone for CubicBezier3<T>

source§

fn clone(&self) -> CubicBezier3<T>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for CubicBezier3<T>

source§

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

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

impl<T: Default> Default for CubicBezier3<T>

source§

fn default() -> CubicBezier3<T>

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

impl<'de, T> Deserialize<'de> for CubicBezier3<T>
where T: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: Zero> From<CubicBezier2<T>> for CubicBezier3<T>

source§

fn from(c: CubicBezier2<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<CubicBezier3<T>> for CubicBezier2<T>

source§

fn from(c: CubicBezier3<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<CubicBezier3<T>> for Vec4<Vec3<T>>

source§

fn from(v: CubicBezier3<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Real + Lerp<T, Output = T>> From<LineSegment3<T>> for CubicBezier3<T>

source§

fn from(line_segment: LineSegment3<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Real> From<QuadraticBezier3<T>> for CubicBezier3<T>

source§

fn from(b: QuadraticBezier3<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Real + Lerp<T, Output = T>> From<Range<Vec3<T>>> for CubicBezier3<T>

source§

fn from(range: Range<Vec3<T>>) -> Self

Converts to this type from the input type.
source§

impl<T> From<Vec4<Vec3<T>>> for CubicBezier3<T>

source§

fn from(v: Vec4<Vec3<T>>) -> Self

Converts to this type from the input type.
source§

impl<T: Hash> Hash for CubicBezier3<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T> Mul<CubicBezier3<T>> for Cols3<T>
where T: Real + MulAdd<T, T, Output = T>,

§

type Output = CubicBezier3<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: CubicBezier3<T>) -> CubicBezier3<T>

Performs the * operation. Read more
source§

impl<T> Mul<CubicBezier3<T>> for Rows3<T>
where T: Real + MulAdd<T, T, Output = T>,

§

type Output = CubicBezier3<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: CubicBezier3<T>) -> CubicBezier3<T>

Performs the * operation. Read more
source§

impl<T> Mul<CubicBezier3<T>> for Cols4<T>
where T: Real + MulAdd<T, T, Output = T>,

§

type Output = CubicBezier3<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: CubicBezier3<T>) -> CubicBezier3<T>

Performs the * operation. Read more
source§

impl<T> Mul<CubicBezier3<T>> for Rows4<T>
where T: Real + MulAdd<T, T, Output = T>,

§

type Output = CubicBezier3<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: CubicBezier3<T>) -> CubicBezier3<T>

Performs the * operation. Read more
source§

impl<T: PartialEq> PartialEq for CubicBezier3<T>

source§

fn eq(&self, other: &CubicBezier3<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Serialize for CubicBezier3<T>
where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Copy> Copy for CubicBezier3<T>

source§

impl<T: Eq> Eq for CubicBezier3<T>

source§

impl<T> StructuralPartialEq for CubicBezier3<T>

Auto Trait Implementations§

§

impl<T> Freeze for CubicBezier3<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for CubicBezier3<T>
where T: RefUnwindSafe,

§

impl<T> Send for CubicBezier3<T>
where T: Send,

§

impl<T> Sync for CubicBezier3<T>
where T: Sync,

§

impl<T> Unpin for CubicBezier3<T>
where T: Unpin,

§

impl<T> UnwindSafe for CubicBezier3<T>
where T: UnwindSafe,

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

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,