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

Unified Diff: src/core/SkGeometry.cpp

Issue 1026633002: use Sk2s for EvalQuadTangent and ChopQuadAt (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 6d14e4bb54f595996213a85ecd08d4242f8c450c..2643c87c90dd6392b232897d2fdc87fde3df7ece 100644
--- a/src/core/SkGeometry.cpp
+++ b/src/core/SkGeometry.cpp
@@ -147,6 +147,23 @@ SkPoint SkEvalQuadAt(const SkPoint src[3], SkScalar t) {
return result;
}
+SkVector SkEvalQuadTangentAt(const SkPoint src[3], SkScalar t) {
+ SkASSERT(src);
+ SkASSERT(t >= 0 && t <= SK_Scalar1);
+
+ Sk2f P0 = Sk2f::Load(&src[0].fX);
+ Sk2f P1 = Sk2f::Load(&src[1].fX);
+ Sk2f P2 = Sk2f::Load(&src[2].fX);
+
+ Sk2f B = P1 - P0;
+ Sk2f A = P2 - P1 - B;
+ Sk2f T = A * Sk2f(t) + B;
+
+ SkVector result;
+ (T + T).store(&result.fX);
+ return result;
+}
+
static void interp_quad_coords(const SkScalar* src, SkScalar* dst, SkScalar t) {
SkScalar ab = SkScalarInterp(src[0], src[2], t);
SkScalar bc = SkScalarInterp(src[2], src[4], t);
@@ -165,6 +182,28 @@ void SkChopQuadAt(const SkPoint src[3], SkPoint dst[5], SkScalar t) {
interp_quad_coords(&src[0].fY, &dst[0].fY, t);
}
+static Sk2s interp(Sk2s A, Sk2s B, Sk2s T) {
mtklein 2015/03/20 11:39:48 Interesting. The x86 Windows warnings are telling
+ return A + (B - A) * T;
+}
+
+void SkChopQuadAt2(const SkPoint src[3], SkPoint dst[5], SkScalar t) {
+ SkASSERT(t > 0 && t < SK_Scalar1);
+
+ Sk2s P0 = Sk2f::Load(&src[0].fX);
mtklein 2015/03/20 11:39:48 You might call these A,B,C to match AB and BC.
+ Sk2s P1 = Sk2f::Load(&src[1].fX);
+ Sk2s P2 = Sk2f::Load(&src[2].fX);
+ Sk2s tt = Sk2s(t);
+
+ Sk2s AB = interp(P0, P1, tt);
+ Sk2s BC = interp(P1, P2, tt);
+
+ P0.store(&dst[0].fX);
+ AB.store(&dst[1].fX);
+ interp(AB, BC, tt).store(&dst[2].fX);
+ BC.store(&dst[3].fX);
+ P2.store(&dst[4].fX);
+}
+
void SkChopQuadAtHalf(const SkPoint src[3], SkPoint dst[5]) {
SkScalar x01 = SkScalarAve(src[0].fX, src[1].fX);
SkScalar y01 = SkScalarAve(src[0].fY, src[1].fY);
« 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