More conic-specific tests revealed a few conic-specific bugs. Because javascript / canvas make visualizing conics tricky, new native tools are required.
The utility SubsetPath removes parts of a potentially very large path to isolate a minimal test case. SubsetPath is very useful for debugging path ops, but is not path ops specific.
PathOpsBuilderConicTest compares the output of the Path Ops Builder, sequential calls to Simplify, and SkRegions for some number of rotated ovals.
Some tests caused path ops to hang. It was caught adding a loop of curves because the head was not found by the tail. Even though the root cause has been fixed, SkSegment::addCurveTo callers now abort the path op if the same curve was added twice.
The subdivided conic weight was been computed anew. Fortunately, it's a simpler computation that the one it replaces.
Some Simplify() subroutines returned false to signal that the results needed assembling. Change these to abort the current operation instead.
Coincident curve intersection triggered two small bugs; one where no perpendicular could be found for coincident curves, and one where no coincident curves remain after looping.
The SixtyOvals test can be run through multiple processes instead of multiple threads. This strategy allows a 48 core machine to saturate all cores at 100%.
The DEBUG_VISUALIZE_CONICS code in PathOpsConicIntersectionTest acknowleges that it is easier to visualize conics with Skia than with script and html canvas. This test also verifies that path ops subdivision matches geometry chopping.
TBR=reed@google.com
Review URL: https://codereview.chromium.org/1405383004
diff --git a/src/pathops/SkPathOpsSimplify.cpp b/src/pathops/SkPathOpsSimplify.cpp
index 34b19d1..08bb26d 100644
--- a/src/pathops/SkPathOpsSimplify.cpp
+++ b/src/pathops/SkPathOpsSimplify.cpp
@@ -11,7 +11,7 @@
#include "SkPathWriter.h"
static bool bridgeWinding(SkOpContourHead* contourList, SkPathWriter* simple,
- SkChunkAlloc* allocator) {
+ SkChunkAlloc* allocator, bool* closable) {
bool unsortable = false;
do {
SkOpSpan* span = FindSortableTop(contourList);
@@ -37,7 +37,9 @@
if (!unsortable && simple->hasMove()
&& current->verb() != SkPath::kLine_Verb
&& !simple->isClosed()) {
- current->addCurveTo(start, end, simple, true);
+ if (!current->addCurveTo(start, end, simple)) {
+ return false;
+ }
#if DEBUG_ACTIVE_SPANS
if (!simple->isClosed()) {
DebugShowActiveSpans(contourList);
@@ -51,7 +53,9 @@
current->debugID(), start->pt().fX, start->pt().fY,
end->pt().fX, end->pt().fY);
#endif
- current->addCurveTo(start, end, simple, true);
+ if (!current->addCurveTo(start, end, simple)) {
+ return false;
+ }
current = next;
start = nextStart;
end = nextEnd;
@@ -59,7 +63,9 @@
if (current->activeWinding(start, end) && !simple->isClosed()) {
SkOpSpan* spanStart = start->starter(end);
if (!spanStart->done()) {
- current->addCurveTo(start, end, simple, true);
+ if (!current->addCurveTo(start, end, simple)) {
+ return false;
+ }
current->markDone(spanStart);
}
}
@@ -88,17 +94,18 @@
}
} while (true);
} while (true);
- return simple->someAssemblyRequired();
+ *closable = !simple->someAssemblyRequired();
+ return true;
}
// returns true if all edges were processed
static bool bridgeXor(SkOpContourHead* contourList, SkPathWriter* simple,
- SkChunkAlloc* allocator) {
+ SkChunkAlloc* allocator, bool* closable) {
SkOpSegment* current;
SkOpSpanBase* start;
SkOpSpanBase* end;
bool unsortable = false;
- bool closable = true;
+ *closable = true;
while ((current = FindUndone(contourList, &start, &end))) {
do {
#if DEBUG_ACTIVE_SPANS
@@ -114,7 +121,9 @@
if (!unsortable && simple->hasMove()
&& current->verb() != SkPath::kLine_Verb
&& !simple->isClosed()) {
- current->addCurveTo(start, end, simple, true);
+ if (!current->addCurveTo(start, end, simple)) {
+ return false;
+ }
#if DEBUG_ACTIVE_SPANS
if (!simple->isClosed()) {
DebugShowActiveSpans(contourList);
@@ -128,7 +137,9 @@
current->debugID(), start->pt().fX, start->pt().fY,
end->pt().fX, end->pt().fY);
#endif
- current->addCurveTo(start, end, simple, true);
+ if (!current->addCurveTo(start, end, simple)) {
+ return false;
+ }
current = next;
start = nextStart;
end = nextEnd;
@@ -137,17 +148,19 @@
SkASSERT(unsortable);
SkOpSpan* spanStart = start->starter(end);
if (!spanStart->done()) {
- current->addCurveTo(start, end, simple, true);
+ if (!current->addCurveTo(start, end, simple)) {
+ return false;
+ }
current->markDone(spanStart);
}
- closable = false;
+ *closable = false;
}
simple->close();
#if DEBUG_ACTIVE_SPANS
DebugShowActiveSpans(contourList);
#endif
}
- return closable;
+ return true;
}
// FIXME : add this as a member of SkPath
@@ -203,8 +216,13 @@
result->reset();
result->setFillType(fillType);
SkPathWriter wrapper(*result);
- if (builder.xorMask() == kWinding_PathOpsMask ? bridgeWinding(contourList, &wrapper, &allocator)
- : !bridgeXor(contourList, &wrapper, &allocator))
+ bool closable;
+ if (builder.xorMask() == kWinding_PathOpsMask
+ ? !bridgeWinding(contourList, &wrapper, &allocator, &closable)
+ : !bridgeXor(contourList, &wrapper, &allocator, &closable)) {
+ return false;
+ }
+ if (!closable)
{ // if some edges could not be resolved, assemble remaining fragments
SkPath temp;
temp.setFillType(fillType);