Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: src/core/SkGeometry.cpp

Issue 1011493003: alt SkEvalQuadAt that returns its answer, using Sk2f (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkGeometry.cpp
diff --git a/src/core/SkGeometry.cpp b/src/core/SkGeometry.cpp
index b4d12dbfa42e902eb18179da19b9c7717d5c28b3..063c7822b25c221c58df7fa98068b816d01a136d 100644
--- a/src/core/SkGeometry.cpp
+++ b/src/core/SkGeometry.cpp
@@ -114,17 +114,10 @@ static SkScalar eval_quad_derivative(const SkScalar src[], SkScalar t) {
return 2 * SkScalarMulAdd(A, t, B);
}
-static SkScalar eval_quad_derivative_at_half(const SkScalar src[]) {
- SkScalar A = src[4] - 2 * src[2] + src[0];
- SkScalar B = src[2] - src[0];
- return A + 2 * B;
-}
-
-void SkEvalQuadAt(const SkPoint src[3], SkScalar t, SkPoint* pt,
- SkVector* tangent) {
+void SkEvalQuadAt(const SkPoint src[3], SkScalar t, SkPoint* pt, SkVector* tangent) {
SkASSERT(src);
SkASSERT(t >= 0 && t <= SK_Scalar1);
-
+
if (pt) {
pt->set(eval_quad(&src[0].fX, t), eval_quad(&src[0].fY, t));
}
@@ -134,20 +127,25 @@ void SkEvalQuadAt(const SkPoint src[3], SkScalar t, SkPoint* pt,
}
}
-void SkEvalQuadAtHalf(const SkPoint src[3], SkPoint* pt, SkVector* tangent) {
+#include "Sk4x.h"
+
+SkPoint SkEvalQuadAt(const SkPoint src[3], SkScalar t) {
SkASSERT(src);
+ SkASSERT(t >= 0 && t <= SK_Scalar1);
- if (pt) {
- SkScalar x01 = SkScalarAve(src[0].fX, src[1].fX);
- SkScalar y01 = SkScalarAve(src[0].fY, src[1].fY);
- SkScalar x12 = SkScalarAve(src[1].fX, src[2].fX);
- SkScalar y12 = SkScalarAve(src[1].fY, src[2].fY);
- pt->set(SkScalarAve(x01, x12), SkScalarAve(y01, y12));
- }
- if (tangent) {
- tangent->set(eval_quad_derivative_at_half(&src[0].fX),
- eval_quad_derivative_at_half(&src[0].fY));
- }
+ const Sk4f t2(t);
+ const Sk4f two(2);
+
+ Sk4f P0 = Sk4f::Load2(&src[0].fX);
+ Sk4f P1 = Sk4f::Load2(&src[1].fX);
+ Sk4f P2 = Sk4f::Load2(&src[2].fX);
+
+ Sk4f A = P2.subtract(P1.multiply(two)).add(P0);
+ Sk4f B = P1.subtract(P0).multiply(two);
+
+ SkPoint result;
+ A.multiply(t2).add(B).multiply(t2).add(P0).store2(&result.fX);
+ return result;
}
static void interp_quad_coords(const SkScalar* src, SkScalar* dst, SkScalar t) {
« bench/GeometryBench.cpp ('K') | « src/core/SkGeometry.h ('k') | tests/GeometryTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698