style: Document the bezier module.

This commit is contained in:
Emilio Cobos Álvarez 2016-12-31 14:03:49 +01:00
parent 5241fa35ab
commit c82fcac77f
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -6,10 +6,13 @@
//! //!
//! This is based on `WebCore/platform/graphics/UnitBezier.h` in WebKit. //! This is based on `WebCore/platform/graphics/UnitBezier.h` in WebKit.
#![deny(missing_docs)]
use euclid::point::Point2D; use euclid::point::Point2D;
const NEWTON_METHOD_ITERATIONS: u8 = 8; const NEWTON_METHOD_ITERATIONS: u8 = 8;
/// A Bézier curve.
pub struct Bezier { pub struct Bezier {
ax: f64, ax: f64,
bx: f64, bx: f64,
@ -20,6 +23,7 @@ pub struct Bezier {
} }
impl Bezier { impl Bezier {
/// Create a Bézier curve from two control points.
#[inline] #[inline]
pub fn new(p1: Point2D<f64>, p2: Point2D<f64>) -> Bezier { pub fn new(p1: Point2D<f64>, p2: Point2D<f64>) -> Bezier {
let cx = 3.0 * p1.x; let cx = 3.0 * p1.x;
@ -96,6 +100,8 @@ impl Bezier {
t t
} }
/// Solve the bezier curve for a given `x` and an `epsilon`, that should be
/// between zero and one.
#[inline] #[inline]
pub fn solve(&self, x: f64, epsilon: f64) -> f64 { pub fn solve(&self, x: f64, epsilon: f64) -> f64 {
self.sample_curve_y(self.solve_curve_x(x, epsilon)) self.sample_curve_y(self.solve_curve_x(x, epsilon))