OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "PathOpsTestCommon.h" | 7 #include "PathOpsTestCommon.h" |
8 #include "SkIntersections.h" | 8 #include "SkIntersections.h" |
9 #include "SkOpContour.h" | 9 #include "SkOpContour.h" |
10 #include "SkOpSegment.h" | 10 #include "SkOpSegment.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 angle, rAngle, diff, (int) (diff / FLT_EPSILON)); | 187 angle, rAngle, diff, (int) (diff / FLT_EPSILON)); |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 class PathOpsAngleTester { | 191 class PathOpsAngleTester { |
192 public: | 192 public: |
193 static int After(SkOpAngle& lh, SkOpAngle& rh) { | 193 static int After(SkOpAngle& lh, SkOpAngle& rh) { |
194 return lh.after(&rh); | 194 return lh.after(&rh); |
195 } | 195 } |
196 | 196 |
| 197 static int AllOnOneSide(SkOpAngle& lh, SkOpAngle& rh) { |
| 198 return lh.allOnOneSide(&rh); |
| 199 } |
| 200 |
197 static int ConvexHullOverlaps(SkOpAngle& lh, SkOpAngle& rh) { | 201 static int ConvexHullOverlaps(SkOpAngle& lh, SkOpAngle& rh) { |
198 return lh.convexHullOverlaps(&rh); | 202 return lh.convexHullOverlaps(&rh); |
199 } | 203 } |
200 | 204 |
201 static int Orderable(SkOpAngle& lh, SkOpAngle& rh) { | 205 static int Orderable(SkOpAngle& lh, SkOpAngle& rh) { |
202 return lh.orderable(&rh); | 206 return lh.orderable(&rh); |
203 } | 207 } |
204 | 208 |
205 static int EndsIntersect(SkOpAngle& lh, SkOpAngle& rh) { | 209 static int EndsIntersect(SkOpAngle& lh, SkOpAngle& rh) { |
206 return lh.endsIntersect(&rh); | 210 return lh.endsIntersect(&rh); |
(...skipping 21 matching lines...) Expand all Loading... |
228 { {{{313.0155029296875, 207.90290832519531}, {320.05078125, 227.587432861328
12}}}, 2, {} }, | 232 { {{{313.0155029296875, 207.90290832519531}, {320.05078125, 227.587432861328
12}}}, 2, {} }, |
229 { {{{313.0155029296875, 207.90290832519531}, {313.98246891063195, 219.336152
03830394}, | 233 { {{{313.0155029296875, 207.90290832519531}, {313.98246891063195, 219.336152
03830394}, |
230 {320.05078125, 227.58743286132812}}}, 3, {} }, | 234 {320.05078125, 227.58743286132812}}}, 3, {} }, |
231 }; | 235 }; |
232 | 236 |
233 static const int circleDataSetSize = (int) SK_ARRAY_COUNT(circleDataSet); | 237 static const int circleDataSetSize = (int) SK_ARRAY_COUNT(circleDataSet); |
234 | 238 |
235 DEF_TEST(PathOpsAngleCircle, reporter) { | 239 DEF_TEST(PathOpsAngleCircle, reporter) { |
236 SkChunkAlloc allocator(4096); | 240 SkChunkAlloc allocator(4096); |
237 SkOpContourHead contour; | 241 SkOpContourHead contour; |
238 SkOpGlobalState state(nullptr, &contour SkDEBUGPARAMS(false) SkDEBUGPARAMS(
nullptr)); | 242 SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARA
MS(nullptr)); |
239 contour.init(&state, false, false); | 243 contour.init(&state, false, false); |
240 for (int index = 0; index < circleDataSetSize; ++index) { | 244 for (int index = 0; index < circleDataSetSize; ++index) { |
241 CircleData& data = circleDataSet[index]; | 245 CircleData& data = circleDataSet[index]; |
242 for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) { | 246 for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) { |
243 data.fShortPts[idx2] = data.fPts.fPts[idx2].asSkPoint(); | 247 data.fShortPts[idx2] = data.fPts.fPts[idx2].asSkPoint(); |
244 } | 248 } |
245 switch (data.fPtCount) { | 249 switch (data.fPtCount) { |
246 case 2: | 250 case 2: |
247 contour.addLine(data.fShortPts, &allocator); | 251 contour.addLine(data.fShortPts); |
248 break; | 252 break; |
249 case 3: | 253 case 3: |
250 contour.addQuad(data.fShortPts, &allocator); | 254 contour.addQuad(data.fShortPts); |
251 break; | 255 break; |
252 case 4: | 256 case 4: |
253 contour.addCubic(data.fShortPts, &allocator); | 257 contour.addCubic(data.fShortPts); |
254 break; | 258 break; |
255 } | 259 } |
256 } | 260 } |
257 SkOpSegment* first = contour.first(); | 261 SkOpSegment* first = contour.first(); |
258 first->debugAddAngle(0, 1, &allocator); | 262 first->debugAddAngle(0, 1); |
259 SkOpSegment* next = first->next(); | 263 SkOpSegment* next = first->next(); |
260 next->debugAddAngle(0, 1, &allocator); | 264 next->debugAddAngle(0, 1); |
261 PathOpsAngleTester::Orderable(*first->debugLastAngle(), *next->debugLastAngl
e()); | 265 PathOpsAngleTester::Orderable(*first->debugLastAngle(), *next->debugLastAngl
e()); |
262 } | 266 } |
263 | 267 |
264 struct IntersectData { | 268 struct IntersectData { |
265 const SkDCubic fPts; | 269 const SkDCubic fPts; |
266 const int fPtCount; | 270 const int fPtCount; |
267 double fTStart; | 271 double fTStart; |
268 double fTEnd; | 272 double fTEnd; |
269 SkPoint fShortPts[4]; | 273 SkPoint fShortPts[4]; |
270 }; | 274 }; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 424 |
421 static const int intersectDataSetsSize = (int) SK_ARRAY_COUNT(intersectDataSetSi
zes); | 425 static const int intersectDataSetsSize = (int) SK_ARRAY_COUNT(intersectDataSetSi
zes); |
422 | 426 |
423 struct FourPoints { | 427 struct FourPoints { |
424 SkPoint pts[4]; | 428 SkPoint pts[4]; |
425 }; | 429 }; |
426 | 430 |
427 DEF_TEST(PathOpsAngleAfter, reporter) { | 431 DEF_TEST(PathOpsAngleAfter, reporter) { |
428 SkChunkAlloc allocator(4096); | 432 SkChunkAlloc allocator(4096); |
429 SkOpContourHead contour; | 433 SkOpContourHead contour; |
430 SkOpGlobalState state(nullptr, &contour SkDEBUGPARAMS(false) SkDEBUGPARAMS(
nullptr)); | 434 SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARA
MS(nullptr)); |
431 contour.init(&state, false, false); | 435 contour.init(&state, false, false); |
432 for (int index = intersectDataSetsSize - 1; index >= 0; --index) { | 436 for (int index = intersectDataSetsSize - 1; index >= 0; --index) { |
433 IntersectData* dataArray = intersectDataSets[index]; | 437 IntersectData* dataArray = intersectDataSets[index]; |
434 const int dataSize = intersectDataSetSizes[index]; | 438 const int dataSize = intersectDataSetSizes[index]; |
435 for (int index2 = 0; index2 < dataSize - 2; ++index2) { | 439 for (int index2 = 0; index2 < dataSize - 2; ++index2) { |
436 allocator.reset(); | 440 allocator.reset(); |
437 contour.reset(); | 441 contour.reset(); |
438 for (int index3 = 0; index3 < 3; ++index3) { | 442 for (int index3 = 0; index3 < 3; ++index3) { |
439 IntersectData& data = dataArray[index2 + index3]; | 443 IntersectData& data = dataArray[index2 + index3]; |
440 SkPoint* temp = (SkPoint*) SkOpTAllocator<FourPoints>::Allocate(
&allocator); | 444 SkPoint* temp = (SkPoint*) SkOpTAllocator<FourPoints>::Allocate(
&allocator); |
441 for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) { | 445 for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) { |
442 temp[idx2] = data.fPts.fPts[idx2].asSkPoint(); | 446 temp[idx2] = data.fPts.fPts[idx2].asSkPoint(); |
443 } | 447 } |
444 switch (data.fPtCount) { | 448 switch (data.fPtCount) { |
445 case 2: { | 449 case 2: { |
446 contour.addLine(temp, &allocator); | 450 contour.addLine(temp); |
447 } break; | 451 } break; |
448 case 3: { | 452 case 3: { |
449 contour.addQuad(temp, &allocator); | 453 contour.addQuad(temp); |
450 } break; | 454 } break; |
451 case 4: { | 455 case 4: { |
452 contour.addCubic(temp, &allocator); | 456 contour.addCubic(temp); |
453 } break; | 457 } break; |
454 } | 458 } |
455 } | 459 } |
456 SkOpSegment* seg1 = contour.first(); | 460 SkOpSegment* seg1 = contour.first(); |
457 seg1->debugAddAngle(dataArray[index2 + 0].fTStart, dataArray[index2
+ 0].fTEnd, &allocator); | 461 seg1->debugAddAngle(dataArray[index2 + 0].fTStart, dataArray[index2
+ 0].fTEnd); |
458 SkOpSegment* seg2 = seg1->next(); | 462 SkOpSegment* seg2 = seg1->next(); |
459 seg2->debugAddAngle(dataArray[index2 + 1].fTStart, dataArray[index2
+ 1].fTEnd, &allocator); | 463 seg2->debugAddAngle(dataArray[index2 + 1].fTStart, dataArray[index2
+ 1].fTEnd); |
460 SkOpSegment* seg3 = seg2->next(); | 464 SkOpSegment* seg3 = seg2->next(); |
461 seg3->debugAddAngle(dataArray[index2 + 2].fTStart, dataArray[index2
+ 2].fTEnd, &allocator); | 465 seg3->debugAddAngle(dataArray[index2 + 2].fTStart, dataArray[index2
+ 2].fTEnd); |
462 SkOpAngle& angle1 = *seg1->debugLastAngle(); | 466 SkOpAngle& angle1 = *seg1->debugLastAngle(); |
463 SkOpAngle& angle2 = *seg2->debugLastAngle(); | 467 SkOpAngle& angle2 = *seg2->debugLastAngle(); |
464 SkOpAngle& angle3 = *seg3->debugLastAngle(); | 468 SkOpAngle& angle3 = *seg3->debugLastAngle(); |
465 PathOpsAngleTester::SetNext(angle1, angle3); | 469 PathOpsAngleTester::SetNext(angle1, angle3); |
466 // These data sets are seeded when the set itself fails, so likely the da
taset does not | 470 // These data sets are seeded when the set itself fails, so likely the da
taset does not |
467 // match the expected result. The tests above return 1 when first added,
but | 471 // match the expected result. The tests above return 1 when first added,
but |
468 // return 0 after the bug is fixed. | 472 // return 0 after the bug is fixed. |
469 SkDEBUGCODE(int result =) PathOpsAngleTester::After(angle2, angle1); | 473 SkDEBUGCODE(int result =) PathOpsAngleTester::After(angle2, angle1); |
470 SkASSERT(result == 0 || result == 1); | 474 SkASSERT(result == 0 || result == 1); |
471 } | 475 } |
472 } | 476 } |
473 } | 477 } |
474 | 478 |
475 void SkOpSegment::debugAddAngle(double startT, double endT, SkChunkAlloc* alloca
tor) { | 479 void SkOpSegment::debugAddAngle(double startT, double endT) { |
476 SkOpPtT* startPtT = startT == 0 ? fHead.ptT() : startT == 1 ? fTail.ptT() | 480 SkOpPtT* startPtT = startT == 0 ? fHead.ptT() : startT == 1 ? fTail.ptT() |
477 : this->addT(startT, kNoAlias, allocator); | 481 : this->addT(startT, kNoAliasMatch, nullptr); |
478 SkOpPtT* endPtT = endT == 0 ? fHead.ptT() : endT == 1 ? fTail.ptT() | 482 SkOpPtT* endPtT = endT == 0 ? fHead.ptT() : endT == 1 ? fTail.ptT() |
479 : this->addT(endT, kNoAlias, allocator); | 483 : this->addT(endT, kNoAliasMatch, nullptr); |
480 SkOpAngle* angle = SkOpTAllocator<SkOpAngle>::Allocate(allocator); | 484 SkOpAngle* angle = SkOpTAllocator<SkOpAngle>::Allocate(this->globalState()->
allocator()); |
481 SkOpSpanBase* startSpan = &fHead; | 485 SkOpSpanBase* startSpan = &fHead; |
482 while (startSpan->ptT() != startPtT) { | 486 while (startSpan->ptT() != startPtT) { |
483 startSpan = startSpan->upCast()->next(); | 487 startSpan = startSpan->upCast()->next(); |
484 } | 488 } |
485 SkOpSpanBase* endSpan = &fHead; | 489 SkOpSpanBase* endSpan = &fHead; |
486 while (endSpan->ptT() != endPtT) { | 490 while (endSpan->ptT() != endPtT) { |
487 endSpan = endSpan->upCast()->next(); | 491 endSpan = endSpan->upCast()->next(); |
488 } | 492 } |
489 angle->set(startSpan, endSpan); | 493 angle->set(startSpan, endSpan); |
490 if (startT < endT) { | 494 if (startT < endT) { |
491 startSpan->upCast()->setToAngle(angle); | 495 startSpan->upCast()->setToAngle(angle); |
492 endSpan->setFromAngle(angle); | 496 endSpan->setFromAngle(angle); |
493 } else { | 497 } else { |
494 endSpan->upCast()->setToAngle(angle); | 498 endSpan->upCast()->setToAngle(angle); |
495 startSpan->setFromAngle(angle); | 499 startSpan->setFromAngle(angle); |
496 } | 500 } |
497 } | 501 } |
| 502 |
| 503 DEF_TEST(PathOpsAngleAllOnOneSide, reporter) { |
| 504 SkChunkAlloc allocator(4096); |
| 505 SkOpContourHead contour; |
| 506 SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARA
MS(nullptr)); |
| 507 contour.init(&state, false, false); |
| 508 SkPoint conicPts[3] = {{494.37100219726562f, 224.66200256347656f}, |
| 509 {494.37360910682298f, 224.6729026561527f}, |
| 510 {494.37600708007813f, 224.68400573730469f}}; |
| 511 SkPoint linePts[2] = {{494.371002f, 224.662003f}, {494.375000f, 224.675995f}
}; |
| 512 for (int i = 10; i >= 0; --i) { |
| 513 SkPoint modLinePts[2] = { linePts[0], linePts[1] }; |
| 514 modLinePts[1].fX += i * .1f; |
| 515 contour.addLine(modLinePts); |
| 516 contour.addQuad(conicPts); |
| 517 // contour.addConic(conicPts, 0.999935746f, &allocator); |
| 518 SkOpSegment* first = contour.first(); |
| 519 first->debugAddAngle(0, 1); |
| 520 SkOpSegment* next = first->next(); |
| 521 next->debugAddAngle(0, 1); |
| 522 /* int result = */ |
| 523 PathOpsAngleTester::AllOnOneSide(*first->debugLastAngle(), *next->de
bugLastAngle()); |
| 524 // SkDebugf("i=%d result=%d\n", i , result); |
| 525 // SkDebugf(""); |
| 526 } |
| 527 } |
OLD | NEW |