PathOpsConicQuadIntersectionTest.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/SkPathOpsQuad.h"
  10. #include "src/pathops/SkReduceOrder.h"
  11. #include "tests/PathOpsTestCommon.h"
  12. #include "tests/Test.h"
  13. static struct conicQuad {
  14. ConicPts conic;
  15. QuadPts quad;
  16. } conicQuadTests[] = {
  17. {{{{{0.00000000000000000, -1.8135968446731567 },
  18. {0.00000000000000000, -1.0033817291259766 },
  19. {-0.0073835160583257675, 0.00000000000000000 }}}, 2.26585215e+11f},
  20. {{{0.00000000000000000, -1.0000113248825073 },
  21. {-2.4824290449032560e-05, -1.0000115633010864 },
  22. {-0.0073835160583257675, 0.00000000000000000 }}}},
  23. {{{{{494.348663,224.583771}, {494.365143,224.633194}, {494.376404,224.684067}}}, 0.998645842f},
  24. {{{494.30481,224.474213}, {494.334961,224.538284}, {494.355774,224.605927}}}},
  25. {{{{{494.348663,224.583771}, {494.365143,224.633194}, {494.376404,224.684067}}}, 0.998645842f},
  26. {{{494.355774f, 224.605927f}, {494.363708f, 224.631714f}, {494.370148f, 224.657471f}}}},
  27. };
  28. static const int conicQuadTests_count = (int) SK_ARRAY_COUNT(conicQuadTests);
  29. static void conicQuadIntersection(skiatest::Reporter* reporter, int index) {
  30. const ConicPts& c = conicQuadTests[index].conic;
  31. SkDConic conic;
  32. conic.debugSet(c.fPts.fPts, c.fWeight);
  33. SkASSERT(ValidConic(conic));
  34. const QuadPts& q = conicQuadTests[index].quad;
  35. SkDQuad quad;
  36. quad.debugSet(q.fPts);
  37. SkASSERT(ValidQuad(quad));
  38. SkReduceOrder reduce1;
  39. SkReduceOrder reduce2;
  40. int order1 = reduce2.reduce(conic.fPts);
  41. int order2 = reduce1.reduce(quad);
  42. if (order2 != 3) {
  43. SkDebugf("[%d] conic order=%d\n", index, order1);
  44. REPORTER_ASSERT(reporter, 0);
  45. }
  46. if (order1 != 3) {
  47. SkDebugf("[%d] quad order=%d\n", index, order2);
  48. REPORTER_ASSERT(reporter, 0);
  49. }
  50. SkIntersections i;
  51. int roots = i.intersect(conic, quad);
  52. for (int pt = 0; pt < roots; ++pt) {
  53. double tt1 = i[0][pt];
  54. SkDPoint xy1 = conic.ptAtT(tt1);
  55. double tt2 = i[1][pt];
  56. SkDPoint xy2 = quad.ptAtT(tt2);
  57. if (!xy1.approximatelyEqual(xy2)) {
  58. SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
  59. __FUNCTION__, index, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY);
  60. }
  61. REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
  62. }
  63. reporter->bumpTestCount();
  64. }
  65. DEF_TEST(PathOpsConicQuadIntersection, reporter) {
  66. for (int index = 0; index < conicQuadTests_count; ++index) {
  67. conicQuadIntersection(reporter, index);
  68. reporter->bumpTestCount();
  69. }
  70. }
  71. DEF_TEST(PathOpsConicQuadIntersectionOneOff, reporter) {
  72. conicQuadIntersection(reporter, 0);
  73. }