aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2016-10-18 07:59:44 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-10-18 07:59:44 -0700
commitb36a3cd137e2b6c328854015018594bb9967e493 (patch)
tree78e6c88a0915d3004381a359f9a517341fe4aa97 /src
parentc5eceb00adaa05e50ed732985a2df7db17c80053 (diff)
break ambiguous angle sorting loop
A pair of cubics may be difficult to sort if the tangents suggest one sort but the midpoints suggest a different one. When in this gray area, and when the cumulative sort of all the angles fails to resolve, reverse the sort to break the tie. Before, when tiger8 was run through the signed distance field generated directly from the path data, the simplify call might hang since the angle could not be resolved. If the endless loop is detected, and if there is no tie to break, just fail instead. TBR=reed@google.com BUG=skia:5131 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2426753002 Review-Url: https://codereview.chromium.org/2426753002
Diffstat (limited to 'src')
-rw-r--r--src/pathops/SkOpAngle.cpp28
-rw-r--r--src/pathops/SkOpAngle.h11
-rw-r--r--src/pathops/SkOpContour.h5
-rw-r--r--src/pathops/SkOpSegment.cpp7
-rw-r--r--src/pathops/SkOpSegment.h2
-rw-r--r--src/pathops/SkPathOpsCommon.cpp11
-rw-r--r--src/pathops/SkPathOpsDebug.h2
7 files changed, 43 insertions, 23 deletions
diff --git a/src/pathops/SkOpAngle.cpp b/src/pathops/SkOpAngle.cpp
index 820b5dceee..99f93dd544 100644
--- a/src/pathops/SkOpAngle.cpp
+++ b/src/pathops/SkOpAngle.cpp
@@ -320,7 +320,7 @@ recomputeSector:
return !fUnorderable;
}
-int SkOpAngle::convexHullOverlaps(const SkOpAngle* rh) const {
+int SkOpAngle::convexHullOverlaps(const SkOpAngle* rh) {
const SkDVector* sweep = this->fPart.fSweep;
const SkDVector* tweep = rh->fPart.fSweep;
double s0xs1 = sweep[0].crossCheck(sweep[1]);
@@ -593,20 +593,20 @@ SkOpGlobalState* SkOpAngle::globalState() const {
// OPTIMIZE: if this loops to only one other angle, after first compare fails, insert on other side
// OPTIMIZE: return where insertion succeeded. Then, start next insertion on opposite side
-void SkOpAngle::insert(SkOpAngle* angle) {
+bool SkOpAngle::insert(SkOpAngle* angle) {
if (angle->fNext) {
if (loopCount() >= angle->loopCount()) {
if (!merge(angle)) {
- return;
+ return true;
}
} else if (fNext) {
if (!angle->merge(this)) {
- return;
+ return true;
}
} else {
angle->insert(this);
}
- return;
+ return true;
}
bool singleton = nullptr == fNext;
if (singleton) {
@@ -622,20 +622,27 @@ void SkOpAngle::insert(SkOpAngle* angle) {
angle->fNext = this;
}
debugValidateNext();
- return;
+ return true;
}
SkOpAngle* last = this;
+ bool flipAmbiguity = false;
do {
SkASSERT(last->fNext == next);
- if (angle->after(last)) {
+ if (angle->after(last) ^ (angle->tangentsAmbiguous() & flipAmbiguity)) {
last->fNext = angle;
angle->fNext = next;
debugValidateNext();
- return;
+ return true;
}
last = next;
+ if (last == this) {
+ FAIL_IF(flipAmbiguity);
+ // We're in a loop. If a sort was ambiguous, flip it to end the loop.
+ flipAmbiguity = true;
+ }
next = next->fNext;
} while (true);
+ return true;
}
SkOpSpanBase* SkOpAngle::lastMarked() const {
@@ -815,7 +822,7 @@ void SkOpAngle::set(SkOpSpanBase* start, SkOpSpanBase* end) {
fComputedEnd = fEnd = end;
SkASSERT(start != end);
fNext = nullptr;
- fComputeSector = fComputedSector = fCheckCoincidence = false;
+ fComputeSector = fComputedSector = fCheckCoincidence = fTangentsAmbiguous = false;
setSpans();
setSector();
SkDEBUGCODE(fID = start ? start->globalState()->nextAngleID() : -1);
@@ -966,7 +973,7 @@ SkOpSpan* SkOpAngle::starter() {
return fStart->starter(fEnd);
}
-bool SkOpAngle::tangentsDiverge(const SkOpAngle* rh, double s0xt0) const {
+bool SkOpAngle::tangentsDiverge(const SkOpAngle* rh, double s0xt0) {
if (s0xt0 == 0) {
return false;
}
@@ -991,5 +998,6 @@ bool SkOpAngle::tangentsDiverge(const SkOpAngle* rh, double s0xt0) const {
double tDist = tweep[0].length() * m;
bool useS = fabs(sDist) < fabs(tDist);
double mFactor = fabs(useS ? this->distEndRatio(sDist) : rh->distEndRatio(tDist));
+ fTangentsAmbiguous = mFactor >= 50 && mFactor < 200;
return mFactor < 50; // empirically found limit
}
diff --git a/src/pathops/SkOpAngle.h b/src/pathops/SkOpAngle.h
index cbdadf1039..3cebfff717 100644
--- a/src/pathops/SkOpAngle.h
+++ b/src/pathops/SkOpAngle.h
@@ -64,7 +64,7 @@ public:
return fEnd;
}
- void insert(SkOpAngle* );
+ bool insert(SkOpAngle* );
SkOpSpanBase* lastMarked() const;
bool loopContains(const SkOpAngle* ) const;
int loopCount() const;
@@ -87,6 +87,10 @@ public:
SkOpSpan* starter();
+ bool tangentsAmbiguous() const {
+ return fTangentsAmbiguous;
+ }
+
bool unorderable() const {
return fUnorderable;
}
@@ -97,7 +101,7 @@ private:
bool checkCrossesZero() const;
bool checkParallel(SkOpAngle* );
bool computeSector();
- int convexHullOverlaps(const SkOpAngle* ) const;
+ int convexHullOverlaps(const SkOpAngle* );
bool endToSide(const SkOpAngle* rh, bool* inside) const;
bool endsIntersect(SkOpAngle* );
int findSector(SkPath::Verb verb, double x, double y) const;
@@ -109,7 +113,7 @@ private:
bool orderable(SkOpAngle* rh); // false == this < rh ; true == this > rh
void setSector();
void setSpans();
- bool tangentsDiverge(const SkOpAngle* rh, double s0xt0) const;
+ bool tangentsDiverge(const SkOpAngle* rh, double s0xt0);
SkDCurve fOriginalCurvePart; // the curve from start to end
SkDCurveSweep fPart; // the curve from start to end offset as needed
@@ -127,6 +131,7 @@ private:
bool fComputeSector;
bool fComputedSector;
bool fCheckCoincidence;
+ bool fTangentsAmbiguous;
SkDEBUGCODE(int fID);
friend class PathOpsAngleTester;
diff --git a/src/pathops/SkOpContour.h b/src/pathops/SkOpContour.h
index dc07c53045..f6c879f16f 100644
--- a/src/pathops/SkOpContour.h
+++ b/src/pathops/SkOpContour.h
@@ -341,12 +341,13 @@ public:
fXor = isXor;
}
- void sortAngles() {
+ bool sortAngles() {
SkASSERT(fCount > 0);
SkOpSegment* segment = &fHead;
do {
- segment->sortAngles();
+ FAIL_IF(!segment->sortAngles());
} while ((segment = segment->next()));
+ return true;
}
const SkPoint& start() const {
diff --git a/src/pathops/SkOpSegment.cpp b/src/pathops/SkOpSegment.cpp
index 2246f36ff2..6012d832bf 100644
--- a/src/pathops/SkOpSegment.cpp
+++ b/src/pathops/SkOpSegment.cpp
@@ -855,7 +855,7 @@ bool SkOpSegment::markAndChaseWinding(SkOpSpanBase* start, SkOpSpanBase* end, in
SkOpSegment* other = this;
while ((other = other->nextChase(&start, &step, &spanStart, &last))) {
if (spanStart->windSum() != SK_MinS32) {
- SkASSERT(spanStart->windSum() == winding);
+// SkASSERT(spanStart->windSum() == winding); // FIXME: is this assert too aggressive?
SkASSERT(!last);
break;
}
@@ -1459,7 +1459,7 @@ void SkOpSegment::setUpWindings(SkOpSpanBase* start, SkOpSpanBase* end, int* sum
SkASSERT(!DEBUG_LIMIT_WIND_SUM || SkTAbs(*oppSumWinding) <= DEBUG_LIMIT_WIND_SUM);
}
-void SkOpSegment::sortAngles() {
+bool SkOpSegment::sortAngles() {
SkOpSpanBase* span = &this->fHead;
do {
SkOpAngle* fromAngle = span->fromAngle();
@@ -1477,7 +1477,7 @@ void SkOpSegment::sortAngles() {
span->debugID());
wroteAfterHeader = true;
#endif
- fromAngle->insert(toAngle);
+ FAIL_IF(!fromAngle->insert(toAngle));
} else if (!fromAngle) {
baseAngle = toAngle;
}
@@ -1527,6 +1527,7 @@ void SkOpSegment::sortAngles() {
SkASSERT(!baseAngle || baseAngle->loopCount() > 1);
#endif
} while (!span->final() && (span = span->upCast()->next()));
+ return true;
}
bool SkOpSegment::subDivide(const SkOpSpanBase* start, const SkOpSpanBase* end,
diff --git a/src/pathops/SkOpSegment.h b/src/pathops/SkOpSegment.h
index b6e7714018..e9618ceeb2 100644
--- a/src/pathops/SkOpSegment.h
+++ b/src/pathops/SkOpSegment.h
@@ -371,7 +371,7 @@ public:
int* maxWinding, int* sumWinding);
void setUpWindings(SkOpSpanBase* start, SkOpSpanBase* end, int* sumMiWinding, int* sumSuWinding,
int* maxWinding, int* sumWinding, int* oppMaxWinding, int* oppSumWinding);
- void sortAngles();
+ bool sortAngles();
bool spansNearby(const SkOpSpanBase* ref, const SkOpSpanBase* check) const;
static int SpanSign(const SkOpSpanBase* start, const SkOpSpanBase* end) {
diff --git a/src/pathops/SkPathOpsCommon.cpp b/src/pathops/SkPathOpsCommon.cpp
index b4049bc5d9..a1cd7bbd63 100644
--- a/src/pathops/SkPathOpsCommon.cpp
+++ b/src/pathops/SkPathOpsCommon.cpp
@@ -235,11 +235,14 @@ static void move_nearby(SkOpContourHead* contourList DEBUG_COIN_DECLARE_PARAMS(
} while ((contour = contour->next()));
}
-static void sort_angles(SkOpContourHead* contourList) {
+static bool sort_angles(SkOpContourHead* contourList) {
SkOpContour* contour = contourList;
do {
- contour->sortAngles();
+ if (!contour->sortAngles()) {
+ return false;
+ }
} while ((contour = contour->next()));
+ return true;
}
bool HandleCoincidence(SkOpContourHead* contourList, SkOpCoincidence* coincidence) {
@@ -327,7 +330,9 @@ bool HandleCoincidence(SkOpContourHead* contourList, SkOpCoincidence* coincidenc
}
} while (!overlaps.isEmpty());
calc_angles(contourList DEBUG_COIN_PARAMS());
- sort_angles(contourList);
+ if (!sort_angles(contourList)) {
+ return false;
+ }
#if DEBUG_COINCIDENCE_VERBOSE
coincidence->debugShowCoincidence();
#endif
diff --git a/src/pathops/SkPathOpsDebug.h b/src/pathops/SkPathOpsDebug.h
index f07d7d0524..4dc52721e6 100644
--- a/src/pathops/SkPathOpsDebug.h
+++ b/src/pathops/SkPathOpsDebug.h
@@ -22,7 +22,7 @@ class SkOpContourHead;
#define FORCE_RELEASE 1 // set force release to 1 for multiple thread -- no debugging
#endif
-#define DEBUG_UNDER_DEVELOPMENT 1
+#define DEBUG_UNDER_DEVELOPMENT 0
#define ONE_OFF_DEBUG 0
#define ONE_OFF_DEBUG_MATHEMATICA 0