PathOpsQuadReduceOrderTest.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2012 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/SkPathOpsRect.h"
  9. #include "src/pathops/SkReduceOrder.h"
  10. #include "tests/PathOpsQuadIntersectionTestData.h"
  11. #include "tests/Test.h"
  12. static const QuadPts testSet[] = {
  13. {{{1, 1}, {2, 2}, {1, 1.000003}}},
  14. {{{1, 0}, {2, 6}, {3, 0}}}
  15. };
  16. static const size_t testSetCount = SK_ARRAY_COUNT(testSet);
  17. static void oneOffTest(skiatest::Reporter* reporter) {
  18. for (size_t index = 0; index < testSetCount; ++index) {
  19. const QuadPts& q = testSet[index];
  20. SkDQuad quad;
  21. quad.debugSet(q.fPts);
  22. SkReduceOrder reducer;
  23. SkDEBUGCODE(int result = ) reducer.reduce(quad);
  24. SkASSERT(result == 3);
  25. }
  26. }
  27. static void standardTestCases(skiatest::Reporter* reporter) {
  28. size_t index;
  29. SkReduceOrder reducer;
  30. int order;
  31. enum {
  32. RunAll,
  33. RunQuadraticLines,
  34. RunQuadraticModLines,
  35. RunNone
  36. } run = RunAll;
  37. int firstTestIndex = 0;
  38. #if 0
  39. run = RunQuadraticLines;
  40. firstTestIndex = 1;
  41. #endif
  42. int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex
  43. : SK_MaxS32;
  44. int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex
  45. : SK_MaxS32;
  46. for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) {
  47. const QuadPts& q = quadraticLines[index];
  48. SkDQuad quad;
  49. quad.debugSet(q.fPts);
  50. order = reducer.reduce(quad);
  51. if (order != 2) {
  52. SkDebugf("[%d] line quad order=%d\n", (int) index, order);
  53. }
  54. }
  55. for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) {
  56. const QuadPts& q = quadraticModEpsilonLines[index];
  57. SkDQuad quad;
  58. quad.debugSet(q.fPts);
  59. order = reducer.reduce(quad);
  60. if (order != 2 && order != 3) { // FIXME: data probably is not good
  61. SkDebugf("[%d] line mod quad order=%d\n", (int) index, order);
  62. }
  63. }
  64. }
  65. DEF_TEST(PathOpsReduceOrderQuad, reporter) {
  66. oneOffTest(reporter);
  67. standardTestCases(reporter);
  68. }