mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Document the bezier module.
This commit is contained in:
parent
5241fa35ab
commit
c82fcac77f
1 changed files with 6 additions and 0 deletions
|
@ -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))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue