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> QuadraticBezier3<T>where
T: Real,
impl<T> QuadraticBezier3<T>where
T: Real,
Sourcepub fn evaluate(self, t: T) -> Vec3<T>
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.
Sourcepub fn evaluate_derivative(self, t: T) -> Vec3<T>
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()
.
Sourcepub fn matrix() -> Mat3<T>
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.
Sourcepub fn split(self, t: T) -> [QuadraticBezier3<T>; 2]
pub fn split(self, t: T) -> [QuadraticBezier3<T>; 2]
Splits this quadratic Bézier curve into two curves, at interpolation factor t
.
Sourcepub fn into_cubic(self) -> CubicBezier3<T>
pub fn into_cubic(self) -> CubicBezier3<T>
Elevates this curve into a cubic Bézier curve.
Source§impl<T> QuadraticBezier3<T>
impl<T> QuadraticBezier3<T>
Sourcepub fn reversed(self) -> QuadraticBezier3<T>
pub fn reversed(self) -> QuadraticBezier3<T>
Gets this curve reversed, i.e swaps start
with end
.
Sourcepub fn into_tuple(self) -> (Vec3<T>, Vec3<T>, Vec3<T>)
pub fn into_tuple(self) -> (Vec3<T>, Vec3<T>, Vec3<T>)
Converts this curve into a tuple of points.
Sourcepub fn into_array(self) -> [Vec3<T>; 3]
pub fn into_array(self) -> [Vec3<T>; 3]
Converts this curve into an array of points.
Source§impl<T> QuadraticBezier3<T>where
T: Real,
impl<T> QuadraticBezier3<T>where
T: Real,
Sourcepub fn x_inflection(self) -> Option<T>
pub fn x_inflection(self) -> Option<T>
Returns the evaluation factor that gives an inflection point along the X axis, if any.
Sourcepub fn min_x(self) -> T
pub fn min_x(self) -> T
Returns the evaluation factor that gives the point on the curve which X coordinate is the minimum.
Source§impl<T> QuadraticBezier3<T>where
T: Real,
impl<T> QuadraticBezier3<T>where
T: Real,
Sourcepub fn y_inflection(self) -> Option<T>
pub fn y_inflection(self) -> Option<T>
Returns the evaluation factor that gives an inflection point along the Y axis, if any.
Sourcepub fn min_y(self) -> T
pub fn min_y(self) -> T
Returns the evaluation factor that gives the point on the curve which Y coordinate is the minimum.
Source§impl<T> QuadraticBezier3<T>where
T: Real,
impl<T> QuadraticBezier3<T>where
T: Real,
Sourcepub fn z_inflection(self) -> Option<T>
pub fn z_inflection(self) -> Option<T>
Returns the evaluation factor that gives an inflection point along the Z axis, if any.
Sourcepub fn min_z(self) -> T
pub fn min_z(self) -> T
Returns the evaluation factor that gives the point on the curve which Z coordinate is the minimum.
Source§impl<T> QuadraticBezier3<T>where
T: Real,
impl<T> QuadraticBezier3<T>where
T: Real,
Sourcepub fn normalized_tangent(self, t: T) -> Vec3<T>where
T: Add<Output = T>,
pub fn normalized_tangent(self, t: T) -> Vec3<T>where
T: Add<Output = T>,
Evaluates the normalized tangent at interpolation factor t
.
Sourcepub fn length_by_discretization(self, step_count: u16) -> T
pub fn length_by_discretization(self, step_count: u16) -> T
Approximates the curve’s length by subdividing it into step_count+1 segments.
Sourcepub fn aabr(self) -> Aabr<T>
pub fn aabr(self) -> Aabr<T>
Gets the Axis-Aligned Bounding Rectangle for this curve.
On 3D curves, this discards the z
values.
Sourcepub fn flipped_x(self) -> QuadraticBezier3<T>
pub fn flipped_x(self) -> QuadraticBezier3<T>
Returns this curve, flipping the x
coordinate of each of its points.
Sourcepub fn flipped_y(self) -> QuadraticBezier3<T>
pub fn flipped_y(self) -> QuadraticBezier3<T>
Returns this curve, flipping the y
coordinate of each of its points.
Sourcepub fn binary_search_point_by_steps(
self,
p: Vec3<T>,
steps: u16,
epsilon: T,
) -> (T, Vec3<T>)
pub fn binary_search_point_by_steps( self, p: Vec3<T>, steps: u16, epsilon: T, ) -> (T, Vec3<T>)
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.
Sourcepub fn binary_search_point<I>(
self,
p: Vec3<T>,
coarse: I,
half_interval: T,
epsilon: T,
) -> (T, Vec3<T>)
pub fn binary_search_point<I>( self, p: Vec3<T>, coarse: I, half_interval: T, epsilon: T, ) -> (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> QuadraticBezier3<T>where
T: Real,
impl<T> QuadraticBezier3<T>where
T: Real,
Source§impl<T> QuadraticBezier3<T>
impl<T> QuadraticBezier3<T>
Sourcepub fn into_2d(self) -> QuadraticBezier2<T>
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 for QuadraticBezier3<T>where
T: Clone,
impl<T> Clone for QuadraticBezier3<T>where
T: Clone,
Source§fn clone(&self) -> QuadraticBezier3<T>
fn clone(&self) -> QuadraticBezier3<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T> Debug for QuadraticBezier3<T>where
T: Debug,
impl<T> Debug for QuadraticBezier3<T>where
T: Debug,
Source§impl<T> Default for QuadraticBezier3<T>where
T: Default,
impl<T> Default for QuadraticBezier3<T>where
T: Default,
Source§fn default() -> QuadraticBezier3<T>
fn default() -> QuadraticBezier3<T>
Source§impl<'de, T> Deserialize<'de> for QuadraticBezier3<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for QuadraticBezier3<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<QuadraticBezier3<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<QuadraticBezier3<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<T> From<LineSegment3<T>> for QuadraticBezier3<T>where
T: Real,
impl<T> From<LineSegment3<T>> for QuadraticBezier3<T>where
T: Real,
Source§fn from(line_segment: LineSegment3<T>) -> QuadraticBezier3<T>
fn from(line_segment: LineSegment3<T>) -> QuadraticBezier3<T>
Source§impl<T> From<QuadraticBezier2<T>> for QuadraticBezier3<T>where
T: Zero,
impl<T> From<QuadraticBezier2<T>> for QuadraticBezier3<T>where
T: Zero,
Source§fn from(c: QuadraticBezier2<T>) -> QuadraticBezier3<T>
fn from(c: QuadraticBezier2<T>) -> QuadraticBezier3<T>
Source§impl<T> From<QuadraticBezier3<T>> for CubicBezier3<T>where
T: Real,
impl<T> From<QuadraticBezier3<T>> for CubicBezier3<T>where
T: Real,
Source§fn from(b: QuadraticBezier3<T>) -> CubicBezier3<T>
fn from(b: QuadraticBezier3<T>) -> CubicBezier3<T>
Source§impl<T> From<QuadraticBezier3<T>> for QuadraticBezier2<T>
impl<T> From<QuadraticBezier3<T>> for QuadraticBezier2<T>
Source§fn from(c: QuadraticBezier3<T>) -> QuadraticBezier2<T>
fn from(c: QuadraticBezier3<T>) -> QuadraticBezier2<T>
Source§impl<T> Hash for QuadraticBezier3<T>where
T: Hash,
impl<T> Hash for QuadraticBezier3<T>where
T: Hash,
Source§impl<T> Mul<QuadraticBezier3<T>> for Mat4<T>
impl<T> Mul<QuadraticBezier3<T>> for Mat4<T>
Source§type Output = QuadraticBezier3<T>
type Output = QuadraticBezier3<T>
*
operator.Source§fn mul(self, rhs: QuadraticBezier3<T>) -> QuadraticBezier3<T>
fn mul(self, rhs: QuadraticBezier3<T>) -> QuadraticBezier3<T>
*
operation. Read moreSource§impl<T> PartialEq for QuadraticBezier3<T>where
T: PartialEq,
impl<T> PartialEq for QuadraticBezier3<T>where
T: PartialEq,
Source§impl<T> Serialize for QuadraticBezier3<T>where
T: Serialize,
impl<T> Serialize for QuadraticBezier3<T>where
T: Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl<T> Copy for QuadraticBezier3<T>where
T: Copy,
impl<T> Eq for QuadraticBezier3<T>where
T: Eq,
impl<T> StructuralPartialEq for QuadraticBezier3<T>
Auto Trait Implementations§
impl<T> Freeze for QuadraticBezier3<T>where
T: Freeze,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C, M> ConvertSaveload<M> for C
impl<C, M> ConvertSaveload<M> for C
§type Error = Infallible
type Error = Infallible
§fn convert_into<F>(
&self,
_: F,
) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
fn convert_into<F>( &self, _: F, ) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
Data
) using
entity to marker mapping function§fn convert_from<F>(
data: <C as ConvertSaveload<M>>::Data,
_: F,
) -> Result<C, <C as ConvertSaveload<M>>::Error>
fn convert_from<F>( data: <C as ConvertSaveload<M>>::Data, _: F, ) -> Result<C, <C as ConvertSaveload<M>>::Error>
Data
) using
entity to marker mapping function§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self
file descriptor.§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Pointee for T
impl<T> Pointee for T
§impl<Context> SubContext<Context> for Context
impl<Context> SubContext<Context> for Context
fn sub_context(self) -> Context
§impl<T> TryDefault for Twhere
T: Default,
impl<T> TryDefault for Twhere
T: Default,
§fn try_default() -> Result<T, String>
fn try_default() -> Result<T, String>
§fn unwrap_default() -> Self
fn unwrap_default() -> Self
try_default
and panics on an error case.