aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pathops/SkPathOpsCubic.cpp
diff options
context:
space:
mode:
authorGravatar caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-04 17:59:42 +0000
committerGravatar caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-04 17:59:42 +0000
commitcffbcc3b9665f2c928544b6fc6b8a0e22a4210fb (patch)
treeed16b540c395c4e1c91733d9198575c2352efc06 /src/pathops/SkPathOpsCubic.cpp
parent4075fd485101eea80cc67c396e6839e555ab948a (diff)
path ops -- rewrite angle sort
This is a major change resulting from a minor tweak. In the old code, the intersection point of two curves was shared between them, but the intersection points and end points of sorted edges was computed directly from the intersection T value. In this CL, both intersection points and sorted points are the same, and intermediate control points are computed to preserve their slope. The sort itself has been completely rewritten to be more robust and remove 'magic' checks, conditions that empirically worked but couldn't be rationalized. This CL was triggered by errors generated computing the clips of SKP files. At this point, all 73M standard tests work and at least the first troublesome SKPs work. Review URL: https://codereview.chromium.org/15338003 git-svn-id: http://skia.googlecode.com/svn/trunk@9432 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/pathops/SkPathOpsCubic.cpp')
-rw-r--r--src/pathops/SkPathOpsCubic.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/pathops/SkPathOpsCubic.cpp b/src/pathops/SkPathOpsCubic.cpp
index 674213c383..c644a67117 100644
--- a/src/pathops/SkPathOpsCubic.cpp
+++ b/src/pathops/SkPathOpsCubic.cpp
@@ -403,11 +403,23 @@ SkDCubic SkDCubic::subDivide(double t1, double t2) const {
/* by = */ dst[1].fY = (my * 2 - ny) / 18;
/* cx = */ dst[2].fX = (nx * 2 - mx) / 18;
/* cy = */ dst[2].fY = (ny * 2 - my) / 18;
+ // FIXME: call align() ?
return dst;
}
+void SkDCubic::align(int endIndex, int ctrlIndex, SkDPoint* dstPt) const {
+ if (fPts[endIndex].fX == fPts[ctrlIndex].fX) {
+ dstPt->fX = fPts[endIndex].fX;
+ }
+ if (fPts[endIndex].fY == fPts[ctrlIndex].fY) {
+ dstPt->fY = fPts[endIndex].fY;
+ }
+}
+
void SkDCubic::subDivide(const SkDPoint& a, const SkDPoint& d,
double t1, double t2, SkDPoint dst[2]) const {
+ SkASSERT(t1 != t2);
+#if 0
double ex = interp_cubic_coords(&fPts[0].fX, (t1 * 2 + t2) / 3);
double ey = interp_cubic_coords(&fPts[0].fY, (t1 * 2 + t2) / 3);
double fx = interp_cubic_coords(&fPts[0].fX, (t1 + t2 * 2) / 3);
@@ -420,6 +432,30 @@ void SkDCubic::subDivide(const SkDPoint& a, const SkDPoint& d,
/* by = */ dst[0].fY = (my * 2 - ny) / 18;
/* cx = */ dst[1].fX = (nx * 2 - mx) / 18;
/* cy = */ dst[1].fY = (ny * 2 - my) / 18;
+#else
+ // this approach assumes that the control points computed directly are accurate enough
+ SkDCubic sub = subDivide(t1, t2);
+ dst[0] = sub[1] + (a - sub[0]);
+ dst[1] = sub[2] + (d - sub[3]);
+#endif
+ if (t1 == 0 || t2 == 0) {
+ align(0, 1, t1 == 0 ? &dst[0] : &dst[1]);
+ }
+ if (t1 == 1 || t2 == 1) {
+ align(3, 2, t1 == 1 ? &dst[0] : &dst[1]);
+ }
+ if (precisely_subdivide_equal(dst[0].fX, a.fX)) {
+ dst[0].fX = a.fX;
+ }
+ if (precisely_subdivide_equal(dst[0].fY, a.fY)) {
+ dst[0].fY = a.fY;
+ }
+ if (precisely_subdivide_equal(dst[1].fX, d.fX)) {
+ dst[1].fX = d.fX;
+ }
+ if (precisely_subdivide_equal(dst[1].fY, d.fY)) {
+ dst[1].fY = d.fY;
+ }
}
/* classic one t subdivision */