36 constexpr
UnitBezier(
double p1x,
double p1y,
double p2x,
double p2y)
38 , bx(3.0 * (p2x - p1x) - (3.0 * p1x))
39 , ax(1.0 - (3.0 * p1x) - (3.0 * (p2x - p1x) - (3.0 * p1x)))
41 , by(3.0 * (p2y - p1y) - (3.0 * p1y))
42 , ay(1.0 - (3.0 * p1y) - (3.0 * (p2y - p1y) - (3.0 * p1y))) {
45 std::pair<double, double>
getP1()
const {
46 return { cx / 3.0, cy / 3.0 };
49 std::pair<double, double>
getP2()
const {
51 (bx + (3.0 * cx / 3.0) + cx) / 3.0,
52 (by + (3.0 * cy / 3.0) + cy) / 3.0,
58 return ((ax * t + bx) * t + cx) * t;
62 return ((ay * t + by) * t + cy) * t;
66 return (3.0 * ax * t + 2.0 * bx) * t + cx;
79 for (t2 = x, i = 0; i < 8; ++i) {
81 if (fabs (x2) < epsilon)
101 if (fabs(x2 - x) < epsilon)
107 t2 = (t1 - t0) * .5 + t0;
114 double solve(
double x,
double epsilon)
const {
119 return std::tie(cx, bx, ax, cy, by, ay) ==
120 std::tie(rhs.cx, rhs.bx, rhs.ax, rhs.cy, rhs.by, rhs.ay);
double solve(double x, double epsilon) const
bool operator==(const UnitBezier &rhs) const
constexpr UnitBezier(double p1x, double p1y, double p2x, double p2y)
Calculate the polynomial coefficients, implicit first and last control points are (0,...
double solveCurveX(double x, double epsilon) const
Given an x value, find a parametric value it came from.
std::pair< double, double > getP2() const
double sampleCurveY(double t) const
double sampleCurveDerivativeX(double t) const
double sampleCurveX(double t) const
std::pair< double, double > getP1() const