lottie/vector: added angleAt() api to bezier class.

Change-Id: Ie5a3f68ad849d1a283363e1eae50ce9520bddb7a
This commit is contained in:
subhransu mohanty
2018-11-15 11:42:10 +09:00
parent ea7f55d44a
commit 18bb0afcfe
2 changed files with 26 additions and 0 deletions

View File

@@ -93,4 +93,29 @@ void VBezier::splitAtLength(float len, VBezier *left, VBezier *right)
right->parameterSplitLeft(t, left);
}
VPointF VBezier::derivative(float t) const
{
// p'(t) = 3 * (-(1-2t+t^2) * p0 + (1 - 4 * t + 3 * t^2) * p1 + (2 * t - 3 * t^2) * p2 + t^2 * p3)
float m_t = 1. - t;
float d = t * t;
float a = -m_t * m_t;
float b = 1 - 4 * t + 3 * d;
float c = 2 * t - 3 * d;
return 3 * VPointF(a * x1 + b * x2 + c * x3 + d * x4,
a * y1 + b * y2 + c * y3 + d * y4);
}
float VBezier::angleAt(float t) const
{
if (t < 0 || t > 1) {
return 0;
}
return VLine({}, derivative(t)).angle();
}
V_END_NAMESPACE

View File

@@ -9,6 +9,7 @@ class VBezier {
public:
VBezier() = default;
VPointF pointAt(float t) const;
float angleAt(float t) const;
VBezier onInterval(float t0, float t1) const;
float length() const;
static void coefficients(float t, float &a, float &b, float &c, float &d);