diff options
author | caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-25 12:05:18 +0000 |
---|---|---|
committer | caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-25 12:05:18 +0000 |
commit | 18063441c23b334ab2ee7075c39ceeb8378e6fcf (patch) | |
tree | c94503a7cf874cf6e2652b68c043a9343f296b58 /experimental | |
parent | 4c2a2f7c5e8ec77771153f94c454adf21fd33805 (diff) |
shape ops work in progress
git-svn-id: http://skia.googlecode.com/svn/trunk@4746 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/Intersection/Simplify.cpp | 92 | ||||
-rw-r--r-- | experimental/Intersection/SimplifyNew_Test.cpp | 20 | ||||
-rw-r--r-- | experimental/Intersection/op.htm | 14 |
3 files changed, 83 insertions, 43 deletions
diff --git a/experimental/Intersection/Simplify.cpp b/experimental/Intersection/Simplify.cpp index 9dcd305460..ad24008467 100644 --- a/experimental/Intersection/Simplify.cpp +++ b/experimental/Intersection/Simplify.cpp @@ -50,7 +50,7 @@ const bool gRunTestsInOneThread = true; #define DEBUG_ACTIVE_SPANS 1 #define DEBUG_ADD_INTERSECTING_TS 0 #define DEBUG_ADD_T_PAIR 0 -#define DEBUG_CONCIDENT 0 +#define DEBUG_CONCIDENT 01 #define DEBUG_CROSS 1 #define DEBUG_DUMP 1 #define DEBUG_MARK_DONE 1 @@ -885,27 +885,27 @@ public: ; Span* test = &fTs[index]; Span* oTest = &other.fTs[oIndex]; + SkTDArray<double> outsideTs; + SkTDArray<double> oOutsideTs; do { bool decrement = test->fWindValue && oTest->fWindValue; Span* end = test; + double startT = end->fT; + double oStartT = oTest->fT; do { if (decrement) { - SkASSERT(end->fWindValue > 0); - if (--(end->fWindValue) == 0) { - end->fDone = true; - ++fDoneSpans; - } + decrementSpan(end); + } else { + TrackOutside(outsideTs, end->fT, oStartT); } end = &fTs[++index]; } while (end->fT - test->fT < FLT_EPSILON); Span* oTestStart = oTest; do { if (decrement) { - SkASSERT(oTestStart->fWindValue > 0); - if (--(oTestStart->fWindValue) == 0) { - oTestStart->fDone = true; - ++other.fDoneSpans; - } + other.decrementSpan(oTestStart); + } else { + TrackOutside(oOutsideTs, oTestStart->fT, startT); } if (!oIndex) { break; @@ -916,6 +916,13 @@ public: oTest = oTestStart; } while (test->fT < endT - FLT_EPSILON); SkASSERT(!oIndex || oTest->fT <= oStartT - FLT_EPSILON); + // FIXME: determine if canceled edges need outside ts added + if (false && !done() && outsideTs.count()) { + addTOutsides(outsideTs, other, oEndT); + } + if (false && !other.done() && oOutsideTs.count()) { + other.addTOutsides(oOutsideTs, *this, endT); + } } // set spans from start to end to increment the greater by one and decrement @@ -947,18 +954,8 @@ public: if (decrementOther) { SkASSERT(abs(end->fWindValue) < gDebugMaxWindValue); ++(end->fWindValue); - } else { - SkASSERT(end->fWindValue > 0); - if (--(end->fWindValue) == 0) { - end->fDone = true; - ++fDoneSpans; - int outCount = outsideTs.count(); - if (outCount == 0 || end->fT - outsideTs[outCount - 2] - >= FLT_EPSILON) { - *outsideTs.append() = end->fT; - *outsideTs.append() = oStartT; - } - } + } else if (decrementSpan(end)) { + TrackOutside(outsideTs, end->fT, oStartT); } } end = &fTs[++index]; @@ -966,21 +963,11 @@ public: Span* oEnd = oTest; do { if (transfer) { - if (decrementOther) { - SkASSERT(oEnd->fWindValue > 0); - if (--(oEnd->fWindValue) == 0) { - oEnd->fDone = true; - ++other.fDoneSpans; - int oOutCount = oOutsideTs.count(); - if (oOutCount == 0 || oEnd->fT - - oOutsideTs[oOutCount - 2] >= FLT_EPSILON) { - *oOutsideTs.append() = oEnd->fT; - *oOutsideTs.append() = startT; - } - } - } else { + if (!decrementOther) { SkASSERT(abs(oEnd->fWindValue) < gDebugMaxWindValue); ++(oEnd->fWindValue); + } else if (other.decrementSpan(oEnd)) { + TrackOutside(oOutsideTs, oEnd->fT, startT); } } oEnd = &other.fTs[++oIndex]; @@ -1190,7 +1177,17 @@ public: } while (fTs[end].fT != 1); return bestT; } - + + bool decrementSpan(Span* span) { + SkASSERT(span->fWindValue > 0); + if (--(span->fWindValue) == 0) { + span->fDone = true; + ++fDoneSpans; + return true; + } + return false; + } + bool done() const { SkASSERT(fDoneSpans <= fTs.count()); return fDoneSpans == fTs.count(); @@ -1261,7 +1258,11 @@ public: markDone(SkMin32(startIndex, endIndex), sumWinding); other = endSpan->fOther; nextStart = endSpan->fOtherIndex; - nextEnd = nextStart + step; + double startT = other->fTs[nextStart].fT; + nextEnd = nextStart; + do { + nextEnd += step; + } while (fabs(startT - other->fTs[nextEnd].fT) < FLT_EPSILON); SkASSERT(step < 0 ? nextEnd >= 0 : nextEnd < other->fTs.count()); return other; } @@ -1288,9 +1289,7 @@ public: int startWinding = sumWinding; // SkASSERT(SkSign32(sumWinding) == SkSign32(winding) || winding == 0); if (doBump || insideContour) { - int prior = windBump(sorted[firstIndex]); - SkDebugf("%s prior=%d\n", __FUNCTION__, prior); - sumWinding -= prior; + sumWinding -= windBump(sorted[firstIndex]); } int nextIndex = firstIndex + 1; int lastIndex = firstIndex != 0 ? firstIndex : angleCount; @@ -1851,7 +1850,16 @@ public: double t(int tIndex) const { return fTs[tIndex].fT; } - + + static void TrackOutside(SkTDArray<double>& outsideTs, double end, + double start) { + int outCount = outsideTs.count(); + if (outCount == 0 || end - outsideTs[outCount - 2] >= FLT_EPSILON) { + *outsideTs.append() = end; + *outsideTs.append() = start; + } + } + void updatePts(const SkPoint pts[]) { fPts = pts; } diff --git a/experimental/Intersection/SimplifyNew_Test.cpp b/experimental/Intersection/SimplifyNew_Test.cpp index 4557228014..9483b6d353 100644 --- a/experimental/Intersection/SimplifyNew_Test.cpp +++ b/experimental/Intersection/SimplifyNew_Test.cpp @@ -550,12 +550,30 @@ static void testLine55() { testSimplifyx(path); } -static void (*firstTest)() = testLine55; +static void testLine56() { + SkPath path, simple; + path.addRect(0, 20, 20, 20, (SkPath::Direction) 0); + path.addRect(18, 20, 30, 30, (SkPath::Direction) 0); + path.addRect(12, 0, 21, 21, (SkPath::Direction) 1); + testSimplifyx(path); +} + +static void testLine57() { + SkPath path, simple; + path.addRect(20, 0, 40, 40, (SkPath::Direction) 0); + path.addRect(20, 0, 30, 40, (SkPath::Direction) 0); + path.addRect(12, 0, 21, 21, (SkPath::Direction) 1); + testSimplifyx(path); +} + +static void (*firstTest)() = testLine57; static struct { void (*fun)(); const char* str; } tests[] = { + TEST(testLine57), + TEST(testLine56), TEST(testLine55), TEST(testLine54), TEST(testLine53), diff --git a/experimental/Intersection/op.htm b/experimental/Intersection/op.htm index ac55d35c40..2e0a44f699 100644 --- a/experimental/Intersection/op.htm +++ b/experimental/Intersection/op.htm @@ -548,11 +548,25 @@ path.close(); path.addRect(4, 4, 13, 13, (SkPath::Direction) 1); </div> +<div id="testLine56"> + path.addRect(0, 20, 20, 20, (SkPath::Direction) 0); + path.addRect(18, 20, 30, 30, (SkPath::Direction) 0); + path.addRect(12, 0, 21, 21, (SkPath::Direction) 1); +</div> + +<div id="testLine57"> + path.addRect(20, 0, 40, 40, (SkPath::Direction) 0); + path.addRect(20, 0, 30, 40, (SkPath::Direction) 0); + path.addRect(12, 0, 21, 21, (SkPath::Direction) 1); +</div> + </div> <script type="text/javascript"> var testDivs = [ + testLine57, + testLine56, testLine55, testLine54, testLine53, |