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

Unified Diff: src/core/SkGeometry.cpp

Issue 1113963002: use pathops utils to improve precision of cubic chopping in scan converter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « src/core/SkGeometry.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkGeometry.cpp
diff --git a/src/core/SkGeometry.cpp b/src/core/SkGeometry.cpp
index b9366f3dd916195c2ef332c59ca96c4e22b78be2..78318cf65228d1d47699826fb8ce6937853d1ab2 100644
--- a/src/core/SkGeometry.cpp
+++ b/src/core/SkGeometry.cpp
@@ -916,6 +916,58 @@ int SkChopCubicAtMaxCurvature(const SkPoint src[4], SkPoint dst[13],
return count + 1;
}
+#include "../pathops/SkPathOpsCubic.h"
+
+//static int RootsValidT(const double A, const double B, const double C, double D, double s[3]);
+
+static void cubic_to_dcoeff(double p0, double p1, double p2, double p3, double coeff[4]) {
+ const Sk2s three(3);
caryclark 2015/04/30 12:59:41 unused variable?
reed1 2015/04/30 13:34:22 Done.
+ double p1minusp2 = p1 - p2;
+
+ double D = p0;
+ double A = p3 + 3 * p1minusp2 - D;
+ double B = 3 * (D - p1minusp2 - p1);
+ double C = 3 * (p1 - D);
+
+ coeff[0] = A;
+ coeff[1] = B;
+ coeff[2] = C;
+ coeff[3] = D;
+}
+
+static SkPoint dpoint_to_point(const SkDPoint& src) {
caryclark 2015/04/30 12:59:40 this is the same as src.asSkPoint()
reed1 2015/04/30 13:34:22 Done.
+ return SkPoint::Make(SkDoubleToScalar(src.fX), SkDoubleToScalar(src.fY));
+}
+
+static bool cubic_dchop_at_root(const SkPoint src[4], const double coeff[4], SkPoint dst[7]) {
+ double t[3];
+ int roots = SkDCubic::RootsValidT(coeff[0], coeff[1], coeff[2], coeff[3], t);
caryclark 2015/04/30 12:59:41 This doesn't take into account the case where the
caryclark 2015/04/30 13:03:00 On 2015/04/30 12:59:41, caryclark wrote: int root
reed1 2015/04/30 13:34:22 Done.
+ SkASSERT(roots <= 1);
+ if (roots > 0) {
+ SkDCubic cubic;
+ SkDCubicPair pair = cubic.set(src).chopAt(t[0]);
+ for (int i = 0; i < 7; ++i) {
+ dst[i] = dpoint_to_point(pair.pts[i]);
+ }
+ return true;
+ }
+ return false;
+}
+
+bool SkChopMonoCubicAtY(SkPoint src[4], SkScalar y, SkPoint dst[7]) {
+ double coeff[4];
+ cubic_to_dcoeff(src[0].fY, src[1].fY, src[2].fY, src[3].fY, coeff);
+ coeff[3] -= y;
+ return cubic_dchop_at_root(src, coeff, dst);
+}
+
+bool SkChopMonoCubicAtX(SkPoint src[4], SkScalar x, SkPoint dst[7]) {
+ double coeff[4];
+ cubic_to_dcoeff(src[0].fX, src[1].fX, src[2].fX, src[3].fX, coeff);
+ coeff[3] -= x;
+ return cubic_dchop_at_root(src, coeff, dst);
+}
+
///////////////////////////////////////////////////////////////////////////////
/* Find t value for quadratic [a, b, c] = d.
« no previous file with comments | « src/core/SkGeometry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698