pub struct QuadraticBezier3<T> {
    pub start: Vec3<T>,
    pub ctrl: Vec3<T>,
    pub end: Vec3<T>,
}
Expand description

A 3D Bézier curve with one control point.

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

Also note that quadratic Bézier curves are quite bad at approximating circles. See the relevant section of “A Primer on Bézier Curves” for an explanation.

Fields§

§start: Vec3<T>

Starting point of the curve.

§ctrl: Vec3<T>

Control point of the curve.

§end: Vec3<T>

End point of the curve.

Implementations§

source§

impl<T: Real> QuadraticBezier3<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() -> Mat3<T>

Returns the constant matrix M such that, given T = [1, 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 quadratic Bézier curve into two curves, at interpolation factor t.

source

pub fn into_cubic(self) -> CubicBezier3<T>

Elevates this curve into a cubic Bézier curve.

source§

impl<T> QuadraticBezier3<T>

source

pub fn reversed(self) -> Self

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

source

pub fn reverse(&mut self)

Reverses this curve, i.e swaps start with end.

source

pub fn into_vec3(self) -> Vec3<Vec3<T>>

Converts this curve into a Vec3 of points.

source

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

Converts this curve into a tuple of points.

source

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

Converts this curve into an array of points.

source§

impl<T: Real> QuadraticBezier3<T>

source

pub fn x_inflection(self) -> 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> QuadraticBezier3<T>

source

pub fn y_inflection(self) -> 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> QuadraticBezier3<T>

source

pub fn z_inflection(self) -> 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> QuadraticBezier3<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) -> Twhere 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> QuadraticBezier3<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> QuadraticBezier3<T>

source

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

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

Trait Implementations§

source§

impl<T: Clone> Clone for QuadraticBezier3<T>

source§

fn clone(&self) -> QuadraticBezier3<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 QuadraticBezier3<T>

source§

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

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

impl<T: Default> Default for QuadraticBezier3<T>

source§

fn default() -> QuadraticBezier3<T>

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

impl<'de, T> Deserialize<'de> for QuadraticBezier3<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: Real> From<LineSegment3<T>> for QuadraticBezier3<T>

source§

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

Converts to this type from the input type.
source§

impl<T: Zero> From<QuadraticBezier2<T>> for QuadraticBezier3<T>

source§

fn from(c: QuadraticBezier2<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> From<QuadraticBezier3<T>> for QuadraticBezier2<T>

source§

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

Converts to this type from the input type.
source§

impl<T> From<QuadraticBezier3<T>> for Vec3<Vec3<T>>

source§

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

Converts to this type from the input type.
source§

impl<T: Real> From<Range<Vec3<T>>> for QuadraticBezier3<T>

source§

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

Converts to this type from the input type.
source§

impl<T> From<Vec3<Vec3<T>>> for QuadraticBezier3<T>

source§

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

Converts to this type from the input type.
source§

impl<T: Hash> Hash for QuadraticBezier3<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<QuadraticBezier3<T>> for Cols3<T>where T: Real + MulAdd<T, T, Output = T>,

§

type Output = QuadraticBezier3<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

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

§

type Output = QuadraticBezier3<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

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

§

type Output = QuadraticBezier3<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

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

§

type Output = QuadraticBezier3<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T: PartialEq> PartialEq<QuadraticBezier3<T>> for QuadraticBezier3<T>

source§

fn eq(&self, other: &QuadraticBezier3<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 QuadraticBezier3<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 QuadraticBezier3<T>

source§

impl<T: Eq> Eq for QuadraticBezier3<T>

source§

impl<T> StructuralEq for QuadraticBezier3<T>

source§

impl<T> StructuralPartialEq for QuadraticBezier3<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere T: for<'de> Deserialize<'de>,