Struct vek::bezier::repr_c::CubicBezier2
source · pub struct CubicBezier2<T> {
pub start: Vec2<T>,
pub ctrl0: Vec2<T>,
pub ctrl1: Vec2<T>,
pub end: Vec2<T>,
}
Expand description
A 2D Bézier curve with two control points.
2x2 and 3x3 matrices can be multiplied by a Bézier curve to transform all of its points.
Fields§
§start: Vec2<T>
Starting point of the curve.
ctrl0: Vec2<T>
First control point of the curve, associated with start
.
ctrl1: Vec2<T>
Second control point of the curve, associated with end
.
end: Vec2<T>
End point of the curve.
Implementations§
source§impl<T: Real> CubicBezier2<T>
impl<T: Real> CubicBezier2<T>
sourcepub fn evaluate(self, t: T) -> Vec2<T>
pub fn evaluate(self, t: T) -> Vec2<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) -> Vec2<T>
pub fn evaluate_derivative(self, t: T) -> Vec2<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() -> Mat4<T>
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.
sourcepub fn split(self, t: T) -> [Self; 2]
pub fn split(self, t: T) -> [Self; 2]
Splits this cubic Bézier curve into two curves, at interpolation factor t
.
sourcepub fn unit_quarter_circle() -> Self
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.
sourcepub fn unit_circle() -> [Self; 4]
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> CubicBezier2<T>
impl<T> CubicBezier2<T>
sourcepub fn reversed(self) -> Self
pub fn reversed(self) -> Self
Gets this curve reversed, i.e swaps start
with end
and ctrl0
with ctrl1
.
sourcepub fn into_tuple(self) -> (Vec2<T>, Vec2<T>, Vec2<T>, Vec2<T>)
pub fn into_tuple(self) -> (Vec2<T>, Vec2<T>, Vec2<T>, Vec2<T>)
Converts this curve into a tuple of points.
sourcepub fn into_array(self) -> [Vec2<T>; 4]
pub fn into_array(self) -> [Vec2<T>; 4]
Converts this curve into an array of points.
source§impl<T: Real> CubicBezier2<T>
impl<T: Real> CubicBezier2<T>
sourcepub fn x_inflections(self) -> Option<(T, Option<T>)>
pub fn x_inflections(self) -> Option<(T, 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: Real> CubicBezier2<T>
impl<T: Real> CubicBezier2<T>
sourcepub fn y_inflections(self) -> Option<(T, Option<T>)>
pub fn y_inflections(self) -> Option<(T, 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: Real> CubicBezier2<T>
impl<T: Real> CubicBezier2<T>
sourcepub fn normalized_tangent(self, t: T) -> Vec2<T>where
T: Add<T, Output = T>,
pub fn normalized_tangent(self, t: T) -> Vec2<T>where T: Add<T, Output = T>,
Evaluates the normalized tangent at interpolation factor t
.
sourcepub fn length_by_discretization(self, step_count: u16) -> Twhere
T: Add<T, Output = T> + From<u16>,
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.
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) -> Self
pub fn flipped_x(self) -> Self
Returns this curve, flipping the x
coordinate of each of its points.
sourcepub fn flipped_y(self) -> Self
pub fn flipped_y(self) -> Self
Returns this curve, flipping the y
coordinate of each of its points.
sourcepub fn binary_search_point_by_steps(
self,
p: Vec2<T>,
steps: u16,
epsilon: T
) -> (T, Vec2<T>)where
T: Add<T, Output = T> + From<u16>,
pub fn binary_search_point_by_steps( self, p: Vec2<T>, steps: u16, epsilon: T ) -> (T, Vec2<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.
sourcepub fn binary_search_point<I>(
self,
p: Vec2<T>,
coarse: I,
half_interval: T,
epsilon: T
) -> (T, Vec2<T>)where
T: Add<T, Output = T>,
I: IntoIterator<Item = (T, Vec2<T>)>,
pub fn binary_search_point<I>( self, p: Vec2<T>, coarse: I, half_interval: T, epsilon: T ) -> (T, Vec2<T>)where T: Add<T, Output = T>, I: IntoIterator<Item = (T, Vec2<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: Zero> CubicBezier2<T>
impl<T: Zero> CubicBezier2<T>
sourcepub fn into_3d(self) -> CubicBezier3<T>
pub fn into_3d(self) -> CubicBezier3<T>
Converts this 2D curve to a 3D one, setting the z
elements to zero.
Trait Implementations§
source§impl<T: Clone> Clone for CubicBezier2<T>
impl<T: Clone> Clone for CubicBezier2<T>
source§fn clone(&self) -> CubicBezier2<T>
fn clone(&self) -> CubicBezier2<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> Debug for CubicBezier2<T>
impl<T: Debug> Debug for CubicBezier2<T>
source§impl<T: Default> Default for CubicBezier2<T>
impl<T: Default> Default for CubicBezier2<T>
source§fn default() -> CubicBezier2<T>
fn default() -> CubicBezier2<T>
source§impl<'de, T> Deserialize<'de> for CubicBezier2<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for CubicBezier2<T>where T: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<T: Zero> From<CubicBezier2<T>> for CubicBezier3<T>
impl<T: Zero> From<CubicBezier2<T>> for CubicBezier3<T>
source§fn from(c: CubicBezier2<T>) -> Self
fn from(c: CubicBezier2<T>) -> Self
source§impl<T> From<CubicBezier2<T>> for Vec4<Vec2<T>>
impl<T> From<CubicBezier2<T>> for Vec4<Vec2<T>>
source§fn from(v: CubicBezier2<T>) -> Self
fn from(v: CubicBezier2<T>) -> Self
source§impl<T> From<CubicBezier3<T>> for CubicBezier2<T>
impl<T> From<CubicBezier3<T>> for CubicBezier2<T>
source§fn from(c: CubicBezier3<T>) -> Self
fn from(c: CubicBezier3<T>) -> Self
source§impl<T: Real + Lerp<T, Output = T>> From<LineSegment2<T>> for CubicBezier2<T>
impl<T: Real + Lerp<T, Output = T>> From<LineSegment2<T>> for CubicBezier2<T>
source§fn from(line_segment: LineSegment2<T>) -> Self
fn from(line_segment: LineSegment2<T>) -> Self
source§impl<T: Real> From<QuadraticBezier2<T>> for CubicBezier2<T>
impl<T: Real> From<QuadraticBezier2<T>> for CubicBezier2<T>
source§fn from(b: QuadraticBezier2<T>) -> Self
fn from(b: QuadraticBezier2<T>) -> Self
source§impl<T: Hash> Hash for CubicBezier2<T>
impl<T: Hash> Hash for CubicBezier2<T>
source§impl<T> Mul<CubicBezier2<T>> for Cols2<T>where
T: Real + MulAdd<T, T, Output = T>,
impl<T> Mul<CubicBezier2<T>> for Cols2<T>where T: Real + MulAdd<T, T, Output = T>,
§type Output = CubicBezier2<T>
type Output = CubicBezier2<T>
*
operator.source§fn mul(self, rhs: CubicBezier2<T>) -> CubicBezier2<T>
fn mul(self, rhs: CubicBezier2<T>) -> CubicBezier2<T>
*
operation. Read moresource§impl<T> Mul<CubicBezier2<T>> for Cols3<T>where
T: Real + MulAdd<T, T, Output = T>,
impl<T> Mul<CubicBezier2<T>> for Cols3<T>where T: Real + MulAdd<T, T, Output = T>,
§type Output = CubicBezier2<T>
type Output = CubicBezier2<T>
*
operator.source§fn mul(self, rhs: CubicBezier2<T>) -> CubicBezier2<T>
fn mul(self, rhs: CubicBezier2<T>) -> CubicBezier2<T>
*
operation. Read moresource§impl<T> Mul<CubicBezier2<T>> for Rows2<T>where
T: Real + MulAdd<T, T, Output = T>,
impl<T> Mul<CubicBezier2<T>> for Rows2<T>where T: Real + MulAdd<T, T, Output = T>,
§type Output = CubicBezier2<T>
type Output = CubicBezier2<T>
*
operator.source§fn mul(self, rhs: CubicBezier2<T>) -> CubicBezier2<T>
fn mul(self, rhs: CubicBezier2<T>) -> CubicBezier2<T>
*
operation. Read moresource§impl<T> Mul<CubicBezier2<T>> for Rows3<T>where
T: Real + MulAdd<T, T, Output = T>,
impl<T> Mul<CubicBezier2<T>> for Rows3<T>where T: Real + MulAdd<T, T, Output = T>,
§type Output = CubicBezier2<T>
type Output = CubicBezier2<T>
*
operator.source§fn mul(self, rhs: CubicBezier2<T>) -> CubicBezier2<T>
fn mul(self, rhs: CubicBezier2<T>) -> CubicBezier2<T>
*
operation. Read moresource§impl<T: PartialEq> PartialEq<CubicBezier2<T>> for CubicBezier2<T>
impl<T: PartialEq> PartialEq<CubicBezier2<T>> for CubicBezier2<T>
source§fn eq(&self, other: &CubicBezier2<T>) -> bool
fn eq(&self, other: &CubicBezier2<T>) -> bool
self
and other
values to be equal, and is used
by ==
.