pub struct CubicBezier {
pub x1: f32,
pub y1: f32,
pub x2: f32,
pub y2: f32,
}Expand description
A CSS cubic-bezier(x1, y1, x2, y2) timing curve.
x1 and x2 may be any pair for which the curve never runs backwards in time, which holds
the CSS range 0..=1 and reaches 4/3 and -1/3; a host exporting to CSS keeps both in
0..=1. y1 and y2 are unbounded, so a curve may overshoot.
Fields§
§x1: f32Horizontal coordinate of the first control point.
y1: f32Vertical coordinate of the first control point.
x2: f32Horizontal coordinate of the second control point.
y2: f32Vertical coordinate of the second control point.
Implementations§
Source§impl CubicBezier
impl CubicBezier
Sourcepub const fn new(x1: f32, y1: f32, x2: f32, y2: f32) -> Self
pub const fn new(x1: f32, y1: f32, x2: f32, y2: f32) -> Self
Creates a curve from its two inner control points.
Sourcepub fn is_valid(self) -> bool
pub fn is_valid(self) -> bool
Whether every coordinate is finite and the curve never runs backwards in time
(time_handles_valid).
Sourcepub fn apply(self, progress: f64) -> f64
pub fn apply(self, progress: f64) -> f64
The curve’s output at linear progress, which is clamped to 0..=1.
0 maps exactly to 0 and 1 to 1. Between them the output may leave 0..=1 when y1 or
y2 does.
Sourcepub fn between(self, from: f64, to: f64) -> Option<Self>
pub fn between(self, from: f64, to: f64) -> Option<Self>
The part of the curve between linear progress from and to, rescaled to the unit
square, so that it shows the same output over that part of a segment. None when the
output is equal at both ends (or the part is empty), which no rescaled curve can show.
The part’s time coordinates may leave 0..=1, as far as a curve that never runs
backwards allows.
Uses only the operations of Self::apply, so every platform gets the same bits.
Sourcepub fn reversed(self) -> Self
pub fn reversed(self) -> Self
The curve played backwards: its output at progress is one minus this curve’s at
1 - progress.
Sourcepub fn slope(self, progress: f64) -> f64
pub fn slope(self, progress: f64) -> f64
The slope of the output at linear progress (clamped to 0..=1), in output per
progress. Always finite: a vertical tangent gives the largest finite f64 with the
slope’s sign.