pub struct Curve<T>{ /* private fields */ }
Expand description
Interpolated Bezier Curve.
It’s made out of points:
- P0 - starting point (
from
). - P1 - starting tangent point (
from param
). - P2 - ending tangent point (
to param
). - P3 - ending point (
to
).
It’s solved by interpolating each layer of it’s points instead of using Bezier equation:
- A := lerp(from, from param, factor)
- B := lerp(from param, to param, factor)
- C := lerp(to param, to, factor)
- D := lerp(A, B, factor)
- E := lerp(B, C, factor)
- Result: lerp(D, E, factor)
Implementations§
Source§impl<T> Curve<T>
impl<T> Curve<T>
Sourcepub fn linear(from: T, to: T) -> Result<Self, CurveError>
pub fn linear(from: T, to: T) -> Result<Self, CurveError>
Builds linear curve with from
same as from_param
and to
same as to_param
.
Sourcepub fn bezier(
from: T,
from_param: T,
to_param: T,
to: T,
) -> Result<Self, CurveError>
pub fn bezier( from: T, from_param: T, to_param: T, to: T, ) -> Result<Self, CurveError>
Builds curve from all Bezier params.
Sourcepub fn from_param(&self) -> &T
pub fn from_param(&self) -> &T
Gets starting tangent point.
Sourcepub fn set_from_param(&mut self, value: T)
pub fn set_from_param(&mut self, value: T)
Sets starting tangent point.
Sourcepub fn set_to_param(&mut self, value: T)
pub fn set_to_param(&mut self, value: T)
Sets ending tangent point.
Sourcepub fn set(&mut self, from: T, from_param: T, to_param: T, to: T)
pub fn set(&mut self, from: T, from_param: T, to_param: T, to: T)
Sets all Bezier curve parameters.
Sourcepub fn category(&self) -> CurveCategory
pub fn category(&self) -> CurveCategory
Returns category of this curve.
Sourcepub fn reverse(&self) -> Result<Self, CurveError>
pub fn reverse(&self) -> Result<Self, CurveError>
Reverses curve, so: F, FP, TP, T -> T, TP, FP, F
Sourcepub fn to_planar(
&self,
plane_origin: &T,
plane_normal: &T,
) -> Result<Self, CurveError>
pub fn to_planar( &self, plane_origin: &T, plane_normal: &T, ) -> Result<Self, CurveError>
Projects this curve onto plane defined by origin and normal.
Sourcepub fn shift(
&self,
distance: Scalar,
guide: Option<&T>,
) -> Result<Self, CurveError>
pub fn shift( &self, distance: Scalar, guide: Option<&T>, ) -> Result<Self, CurveError>
Shifts this curve by distance perpendicular to guide. Produces low precision shift, so use it carefully! If you need high precision, use offset function.
Sourcepub fn offset(
&self,
distance: Scalar,
guide: Option<&T>,
) -> Result<Vec<Self>, CurveError>
pub fn offset( &self, distance: Scalar, guide: Option<&T>, ) -> Result<Vec<Self>, CurveError>
Offsets this curve by distance. This produces high precision offsetted series of safe curves to ensure curves follow original shape as closely as possible.
Sourcepub fn build_safe_curves(&self, out_result: &mut Vec<Self>)
pub fn build_safe_curves(&self, out_result: &mut Vec<Self>)
Builds safe curves out of this curve. Safe curve means curve has at most one extremity and extremity is within circle between curve start and end points. Original curve is split at points of extremities until all sub-curves are considered safe.
Sourcepub fn value_along_axis_iter(
&self,
steps: usize,
axis_index: usize,
) -> Option<impl Iterator<Item = Scalar>>
pub fn value_along_axis_iter( &self, steps: usize, axis_index: usize, ) -> Option<impl Iterator<Item = Scalar>>
Samples values along given axis in given number of steps.
Sourcepub fn sample_along_axis(
&self,
axis_value: Scalar,
axis_index: usize,
) -> Option<T>
pub fn sample_along_axis( &self, axis_value: Scalar, axis_index: usize, ) -> Option<T>
Samples curve at value of given axis.
Sourcepub fn sample_first_derivative(&self, factor: Scalar) -> T
pub fn sample_first_derivative(&self, factor: Scalar) -> T
Samples velocity of change along the curve.
Sourcepub fn sample_first_derivative_along_axis(
&self,
axis_value: Scalar,
axis_index: usize,
) -> Option<T>
pub fn sample_first_derivative_along_axis( &self, axis_value: Scalar, axis_index: usize, ) -> Option<T>
Samples velocity of change along the curve axis.
Sourcepub fn sample_second_derivative(&self, factor: Scalar) -> T
pub fn sample_second_derivative(&self, factor: Scalar) -> T
Samples acceleration of change along the curve.
Sourcepub fn sample_second_derivative_along_axis(
&self,
axis_value: Scalar,
axis_index: usize,
) -> Option<T>
pub fn sample_second_derivative_along_axis( &self, axis_value: Scalar, axis_index: usize, ) -> Option<T>
Samples acceleration of change along the curve axis.
Sourcepub fn sample_curvature_radius(&self, factor: Scalar) -> Scalar
pub fn sample_curvature_radius(&self, factor: Scalar) -> Scalar
Sample curvature radius at given factor.
Sourcepub fn sample_tangent(&self, factor: Scalar) -> T
pub fn sample_tangent(&self, factor: Scalar) -> T
Sample curve tangent at given factor.
Sourcepub fn sample_tangent_along_axis(
&self,
axis_value: Scalar,
axis_index: usize,
) -> Option<T>
pub fn sample_tangent_along_axis( &self, axis_value: Scalar, axis_index: usize, ) -> Option<T>
Sample curve tangent at given axis value.
Sourcepub fn split(&self, factor: Scalar) -> Result<(Self, Self), CurveError>
pub fn split(&self, factor: Scalar) -> Result<(Self, Self), CurveError>
Splits curve into two parts at given factor.
Sourcepub fn find_extremities(&self) -> Vec<Scalar> ⓘ
pub fn find_extremities(&self) -> Vec<Scalar> ⓘ
Finds list of all time (factors) at which extremities exist.
Sourcepub fn find_extremities_for_axis(&self, axis_index: usize) -> Vec<Scalar> ⓘ
pub fn find_extremities_for_axis(&self, axis_index: usize) -> Vec<Scalar> ⓘ
Finds list of all time (factors) at which extremities for given axis exist.
Sourcepub fn find_intersections(
&self,
other: &Self,
max_iterations: usize,
min_length: Scalar,
) -> Result<Vec<(Scalar, Scalar)>, CurveError>
pub fn find_intersections( &self, other: &Self, max_iterations: usize, min_length: Scalar, ) -> Result<Vec<(Scalar, Scalar)>, CurveError>
Finds list of all time (factors) pair tuples between this and other curve, at which two curves intersect.
Sourcepub fn find_self_intersections(
&self,
max_iterations: usize,
min_length: Scalar,
) -> Result<Vec<(Scalar, Scalar)>, CurveError>
pub fn find_self_intersections( &self, max_iterations: usize, min_length: Scalar, ) -> Result<Vec<(Scalar, Scalar)>, CurveError>
Finds list of all time (factors) pair tuples at which this curve intersects with itself.
Sourcepub fn find_distance_for_time(&self, factor: Scalar) -> Scalar
pub fn find_distance_for_time(&self, factor: Scalar) -> Scalar
Finds distance along the curve for given time (factor).
Sourcepub fn find_time_for_distance(&self, distance: Scalar) -> Scalar
pub fn find_time_for_distance(&self, distance: Scalar) -> Scalar
Finds time (factor) for given distance along the curve.
Sourcepub fn find_time_for_axis(
&self,
axis_value: Scalar,
axis_index: usize,
) -> Option<Scalar>
pub fn find_time_for_axis( &self, axis_value: Scalar, axis_index: usize, ) -> Option<Scalar>
Finds time (factor) for given axis value.
Sourcepub fn find_time_closest_to_point(&self, point: &T) -> (Scalar, Scalar)
pub fn find_time_closest_to_point(&self, point: &T) -> (Scalar, Scalar)
Finds time (factor) closest to given point. Returns tuple of: (time, distance)
Sourcepub fn find_time_for(
&self,
guess: Option<Scalar>,
iterations: Option<usize>,
difference: impl FnMut(Scalar) -> Option<T>,
validation: impl FnMut(Scalar) -> bool,
) -> Scalar
pub fn find_time_for( &self, guess: Option<Scalar>, iterations: Option<usize>, difference: impl FnMut(Scalar) -> Option<T>, validation: impl FnMut(Scalar) -> bool, ) -> Scalar
Finds best time (factor) for given estimate (guess) using provided function to calculate change in hidden value, until reaches number of iterations or derivative gets close to no change. Usually used for Newton-Raphson method of approximation.