PathOpsCubicConicIntersectionTest.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2015 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 "src/pathops/SkIntersections.h"
  8. #include "src/pathops/SkPathOpsConic.h"
  9. #include "src/pathops/SkPathOpsCubic.h"
  10. #include "src/pathops/SkReduceOrder.h"
  11. #include "tests/PathOpsTestCommon.h"
  12. #include "tests/Test.h"
  13. static struct cubicConic {
  14. CubicPts cubic;
  15. ConicPts conic;
  16. } cubicConicTests[] = {
  17. #if 0
  18. // FIXME: this triggers an assert in bool SkTSect::extractCoincident() at
  19. // SkOPASSERT(oppStartT < oppEndT);
  20. // Throwing an error here breaks one test, but only in release.
  21. // More work to be done to figure this out.
  22. {{{{2.1883804947719909e-05, 3.6366123822517693e-05 },
  23. {2.9145950975362211e-05, 2.9117207304807380e-05 },
  24. {2.9113532946212217e-05, 2.9173743314458989e-05 },
  25. {0.00000000000000000, 5.8282588724978268e-05 }}},
  26. {{{{0.00000000000000000, 5.8282581449020654e-05 },
  27. {0.00000000000000000, 5.8282563259126619e-05 },
  28. {5.8282588724978268e-05, 0.00000000000000000 }}}, 53684.6563f}},
  29. #endif
  30. {{{{188.60000610351562, 2041.5999755859375}, {188.60000610351562, 2065.39990234375},
  31. {208, 2084.800048828125}, {231.80000305175781, 2084.800048828125}}},
  32. {{{{231.80000305175781, 2084.800048828125}, {188.60000610351562, 2084.800048828125},
  33. {188.60000610351562, 2041.5999755859375}}}, 0.707107008f}},
  34. {{{{231.80000305175781, 2084.800048828125}, {255.60000610351562, 2084.800048828125},
  35. {275, 2065.39990234375}, {275, 2041.5999755859375}}},
  36. {{{{275, 2041.5999755859375}, {275, 2084.800048828125},
  37. {231.80000305175781, 2084.800048828125}}}, 0.707107008f}},
  38. };
  39. static const int cubicConicTests_count = (int) SK_ARRAY_COUNT(cubicConicTests);
  40. static void cubicConicIntersection(skiatest::Reporter* reporter, int index) {
  41. const CubicPts& cu = cubicConicTests[index].cubic;
  42. SkDCubic cubic;
  43. cubic.debugSet(cu.fPts);
  44. SkASSERT(ValidCubic(cubic));
  45. const ConicPts& co = cubicConicTests[index].conic;
  46. SkDConic conic;
  47. conic.debugSet(co.fPts.fPts, co.fWeight);
  48. SkASSERT(ValidConic(conic));
  49. SkReduceOrder reduce1;
  50. SkReduceOrder reduce2;
  51. int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics);
  52. int order2 = reduce2.reduce(conic.fPts);
  53. if (order1 != 4) {
  54. SkDebugf("[%d] cubic order=%d\n", index, order1);
  55. REPORTER_ASSERT(reporter, 0);
  56. }
  57. if (order2 != 3) {
  58. SkDebugf("[%d] conic order=%d\n", index, order2);
  59. REPORTER_ASSERT(reporter, 0);
  60. }
  61. SkIntersections i;
  62. int roots = i.intersect(cubic, conic);
  63. for (int pt = 0; pt < roots; ++pt) {
  64. double tt1 = i[0][pt];
  65. SkDPoint xy1 = cubic.ptAtT(tt1);
  66. double tt2 = i[1][pt];
  67. SkDPoint xy2 = conic.ptAtT(tt2);
  68. if (!xy1.approximatelyEqual(xy2)) {
  69. SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
  70. __FUNCTION__, index, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY);
  71. }
  72. REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
  73. }
  74. reporter->bumpTestCount();
  75. }
  76. DEF_TEST(PathOpsCubicConicIntersection, reporter) {
  77. for (int index = 0; index < cubicConicTests_count; ++index) {
  78. cubicConicIntersection(reporter, index);
  79. reporter->bumpTestCount();
  80. }
  81. }
  82. DEF_TEST(PathOpsCubicConicIntersectionOneOff, reporter) {
  83. cubicConicIntersection(reporter, 0);
  84. }