skia2/tests/PathOpsTSectDebug.h
caryclark 26ad22ab61 Enabling clip stack flattening exercises path ops.
Iterating through the 903K skps that represent the
imagable 1M top web pages triggers a number of
bugs, some of which are addressed here.

Some web pages trigger intersecting cubic
representations of arc with their conic
counterparts. This exposed a flaw in coincident
detection that caused an infinite loop. The loop
alternatively extended the coincident section and,
determining the that the bounds of the curve pairs
did not overlap, deleted the extension.

Track the number of times the coincident detection
is called, and if it exceeds an empirically found
limit, assume that the curves are coincident and
force it to be so.

The loop count limit can be determined by enabling
DEBUG_T_SECT_LOOP_COUNT and running all tests. The
largest count is reported on completion.

Another class of bugs was caused by concident
detection duplicating nearly identical points that
had been merged earlier. To track these bugs, the
'handle coincidence' code was duplicated as a
const debug variety that reported if one of a
dozen or so irregularities are present; then it is
easier to see when a block of code that fixes one
irregularity regresses another.

Creating the debug const code version exposed some
non-debug code that could be const, and some that
was experimental and could be removed. Set
DEBUG_COINCIDENCE to track coincidence health and
handling.

For running on Chrome, DEBUG_VERIFY checks the
result of pathops against the same operation
using SkRegion to verify that the results are
nearly the same.

When visualizing the pathops work using
tools/pathops_visualizer.htm, set
DEBUG_DUMP_ALIGNMENT to see the curves after
they've been aligned for coincidence.

Other bugs fixed include detecting when a
section of a pair of curves have devolved into
lines and are coincident.

TBR=reed@google.com

Review URL: https://codereview.chromium.org/1394503003
2015-10-16 09:03:38 -07:00

212 lines
6.0 KiB
C++

/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkPathOpsTSect.h"
template<typename TCurve, typename OppCurve>
void SkTCoincident<TCurve, OppCurve>::dump() const {
SkDebugf("t=%1.9g pt=(%1.9g,%1.9g)%s\n", fPerpT, fPerpPt.fX, fPerpPt.fY,
fCoincident ? " coincident" : "");
}
template<typename TCurve, typename OppCurve>
const SkTSpan<TCurve, OppCurve>* SkTSect<TCurve, OppCurve>::debugSpan(int id) const {
const SkTSpan<TCurve, OppCurve>* test = fHead;
do {
if (test->debugID() == id) {
return test;
}
} while ((test = test->next()));
return nullptr;
}
template<typename TCurve, typename OppCurve>
const SkTSpan<TCurve, OppCurve>* SkTSect<TCurve, OppCurve>::debugT(double t) const {
const SkTSpan<TCurve, OppCurve>* test = fHead;
const SkTSpan<TCurve, OppCurve>* closest = nullptr;
double bestDist = DBL_MAX;
do {
if (between(test->fStartT, t, test->fEndT)) {
return test;
}
double testDist = SkTMin(fabs(test->fStartT - t), fabs(test->fEndT - t));
if (bestDist > testDist) {
bestDist = testDist;
closest = test;
}
} while ((test = test->next()));
SkASSERT(closest);
return closest;
}
template<typename TCurve, typename OppCurve>
void SkTSect<TCurve, OppCurve>::dump() const {
dumpCommon(fHead);
}
extern int gDumpTSectNum;
template<typename TCurve, typename OppCurve>
void SkTSect<TCurve, OppCurve>::dumpBoth(SkTSect<OppCurve, TCurve>* opp) const {
#if DEBUG_T_SECT_DUMP <= 2
#if DEBUG_T_SECT_DUMP == 2
SkDebugf("%d ", ++gDumpTSectNum);
#endif
this->dump();
SkDebugf(" ");
opp->dump();
SkDebugf("\n");
#elif DEBUG_T_SECT_DUMP == 3
SkDebugf("<div id=\"sect%d\">\n", ++gDumpTSectNum);
if (this->fHead) {
this->dumpCurves();
}
if (opp->fHead) {
opp->dumpCurves();
}
SkDebugf("</div>\n\n");
#endif
}
template<typename TCurve, typename OppCurve>
void SkTSect<TCurve, OppCurve>::dumpBounded(int id) const {
const SkTSpan<TCurve, OppCurve>* bounded = debugSpan(id);
if (!bounded) {
SkDebugf("no span matches %d\n", id);
return;
}
const SkTSpan<OppCurve, TCurve>* test = bounded->debugOpp()->fHead;
do {
if (test->findOppSpan(bounded)) {
test->dump();
SkDebugf(" ");
}
} while ((test = test->next()));
SkDebugf("\n");
}
template<typename TCurve, typename OppCurve>
void SkTSect<TCurve, OppCurve>::dumpBounds() const {
const SkTSpan<TCurve, OppCurve>* test = fHead;
do {
test->dumpBounds();
} while ((test = test->next()));
}
template<typename TCurve, typename OppCurve>
void SkTSect<TCurve, OppCurve>::dumpCoin() const {
dumpCommon(fCoincident);
}
template<typename TCurve, typename OppCurve>
void SkTSect<TCurve, OppCurve>::dumpCoinCurves() const {
dumpCommonCurves(fCoincident);
}
template<typename TCurve, typename OppCurve>
void SkTSect<TCurve, OppCurve>::dumpCommon(const SkTSpan<TCurve, OppCurve>* test) const {
SkDebugf("id=%d", debugID());
if (!test) {
SkDebugf(" (empty)");
return;
}
do {
SkDebugf(" ");
test->dump();
} while ((test = test->next()));
}
template<typename TCurve, typename OppCurve>
void SkTSect<TCurve, OppCurve>::dumpCommonCurves(const SkTSpan<TCurve, OppCurve>* test) const {
do {
test->fPart.dumpID(test->debugID());
} while ((test = test->next()));
}
template<typename TCurve, typename OppCurve>
void SkTSect<TCurve, OppCurve>::dumpCurves() const {
dumpCommonCurves(fHead);
}
template<typename TCurve, typename OppCurve>
const SkTSpan<TCurve, OppCurve>* SkTSpan<TCurve, OppCurve>::debugSpan(int id) const {
return SkDEBUGRELEASE(fDebugSect->debugSpan(id), nullptr);
}
template<typename TCurve, typename OppCurve>
const SkTSpan<TCurve, OppCurve>* SkTSpan<TCurve, OppCurve>::debugT(double t) const {
return SkDEBUGRELEASE(fDebugSect->debugT(t), nullptr);
}
template<typename TCurve, typename OppCurve>
void SkTSpan<TCurve, OppCurve>::dumpAll() const {
dumpID();
SkDebugf("=(%g,%g) [", fStartT, fEndT);
const SkTSpanBounded<OppCurve, TCurve>* testBounded = fBounded;
while (testBounded) {
const SkTSpan<OppCurve, TCurve>* span = testBounded->fBounded;
const SkTSpanBounded<OppCurve, TCurve>* next = testBounded->fNext;
span->dumpID();
SkDebugf("=(%g,%g)", span->fStartT, span->fEndT);
if (next) {
SkDebugf(" ");
}
testBounded = next;
}
SkDebugf("]\n");
}
template<typename TCurve, typename OppCurve>
void SkTSpan<TCurve, OppCurve>::dump() const {
dumpID();
SkDebugf("=(%g,%g) [", fStartT, fEndT);
const SkTSpanBounded<OppCurve, TCurve>* testBounded = fBounded;
while (testBounded) {
const SkTSpan<OppCurve, TCurve>* span = testBounded->fBounded;
const SkTSpanBounded<OppCurve, TCurve>* next = testBounded->fNext;
span->dumpID();
if (next) {
SkDebugf(",");
}
testBounded = next;
}
SkDebugf("]");
}
template<typename TCurve, typename OppCurve>
void SkTSpan<TCurve, OppCurve>::dumpBounded(int id) const {
SkDEBUGCODE(fDebugSect->dumpBounded(id));
}
template<typename TCurve, typename OppCurve>
void SkTSpan<TCurve, OppCurve>::dumpBounds() const {
dumpID();
SkDebugf(" bounds=(%1.9g,%1.9g, %1.9g,%1.9g) boundsMax=%1.9g%s\n",
fBounds.fLeft, fBounds.fTop, fBounds.fRight, fBounds.fBottom, fBoundsMax,
fCollapsed ? " collapsed" : "");
}
template<typename TCurve, typename OppCurve>
void SkTSpan<TCurve, OppCurve>::dumpCoin() const {
dumpID();
SkDebugf(" coinStart ");
fCoinStart.dump();
SkDebugf(" coinEnd ");
fCoinEnd.dump();
}
template<typename TCurve, typename OppCurve>
void SkTSpan<TCurve, OppCurve>::dumpID() const {
if (fCoinStart.isCoincident()) {
SkDebugf("%c", '*');
}
SkDebugf("%d", debugID());
if (fCoinEnd.isCoincident()) {
SkDebugf("%c", '*');
}
}