PathOpsThreeWayTest.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2014 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/private/SkTDArray.h"
  8. #include "src/pathops/SkIntersections.h"
  9. #include "tests/PathOpsTestCommon.h"
  10. #include "tests/Test.h"
  11. // check intersections for consistency
  12. struct Curve {
  13. int ptCount;
  14. CubicPts curve; // largest can hold lines / quads/ cubics
  15. };
  16. static const Curve testSet0[] = { // extracted from skpClip2
  17. {4, {{{134,11414}, {131.990234,11414}, {130.32666,11415.4824}, {130.042755,11417.4131}}} },
  18. {4, {{{130.042755,11417.4131}, {130.233124,11418.3193}, {131.037079,11419}, {132,11419}}} },
  19. {4, {{{132,11419}, {130.895432,11419}, {130,11418.1045}, {130,11417}}} },
  20. };
  21. static const Curve testSet1[] = { // extracted from cubicOp85i
  22. {4, {{{3,4}, {1,5}, {4,3}, {6,4}}} },
  23. {1, {{{6,4}, {3,4}}} },
  24. {4, {{{3,4}, {4,6}, {4,3}, {5,1}}} },
  25. {1, {{{5,1}, {3,4}}} },
  26. };
  27. static const struct TestSet {
  28. const Curve* tests;
  29. int testCount;
  30. } testSets[] = {
  31. { testSet0, (int) SK_ARRAY_COUNT(testSet0) },
  32. { testSet1, (int) SK_ARRAY_COUNT(testSet1) },
  33. };
  34. static const int testSetsCount = (int) SK_ARRAY_COUNT(testSets);
  35. static void testSetTest(skiatest::Reporter* reporter, int index) {
  36. const TestSet& testSet = testSets[index];
  37. int testCount = testSet.testCount;
  38. SkASSERT(testCount > 1);
  39. SkTDArray<SkIntersections> combos;
  40. for (int outer = 0; outer < testCount - 1; ++outer) {
  41. const Curve& oTest = testSet.tests[outer];
  42. for (int inner = outer + 1; inner < testCount; ++inner) {
  43. const Curve& iTest = testSet.tests[inner];
  44. SkIntersections* i = combos.append();
  45. sk_bzero(i, sizeof(SkIntersections));
  46. SkDLine oLine = {{ oTest.curve.fPts[0], oTest.curve.fPts[1] }};
  47. SkDLine iLine = {{ iTest.curve.fPts[0], iTest.curve.fPts[1] }};
  48. SkDCubic iCurve, oCurve;
  49. iCurve.debugSet(iTest.curve.fPts);
  50. oCurve.debugSet(oTest.curve.fPts);
  51. if (oTest.ptCount == 1 && iTest.ptCount == 1) {
  52. i->intersect(oLine, iLine);
  53. } else if (oTest.ptCount == 1 && iTest.ptCount == 4) {
  54. i->intersect(iCurve, oLine);
  55. } else if (oTest.ptCount == 4 && iTest.ptCount == 1) {
  56. i->intersect(oCurve, iLine);
  57. } else if (oTest.ptCount == 4 && iTest.ptCount == 4) {
  58. i->intersect(oCurve, iCurve);
  59. } else {
  60. SkASSERT(0);
  61. }
  62. // i->dump();
  63. }
  64. }
  65. }
  66. DEF_TEST(PathOpsThreeWay, reporter) {
  67. for (int index = 0; index < testSetsCount; ++index) {
  68. testSetTest(reporter, index);
  69. reporter->bumpTestCount();
  70. }
  71. }
  72. DEF_TEST(PathOpsThreeWayOneOff, reporter) {
  73. int index = 0;
  74. testSetTest(reporter, index);
  75. }