PathOpsBoundsTest.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2013 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/SkPathOpsBounds.h"
  8. #include "src/pathops/SkPathOpsCurve.h"
  9. #include "tests/PathOpsTestCommon.h"
  10. #include "tests/Test.h"
  11. static const SkRect sectTests[][2] = {
  12. {{2, 0, 4, 1}, {4, 0, 6, 1}},
  13. {{2, 0, 4, 1}, {3, 0, 5, 1}},
  14. {{2, 0, 4, 1}, {3, 0, 5, 0}},
  15. {{2, 0, 4, 1}, {3, 1, 5, 2}},
  16. {{2, 1, 4, 2}, {1, 0, 5, 3}},
  17. {{2, 1, 5, 3}, {3, 1, 4, 2}},
  18. {{2, 0, 4, 1}, {3, 0, 3, 0}}, // intersecting an empty bounds is OK
  19. {{2, 0, 4, 1}, {4, 1, 5, 2}}, // touching just on a corner is OK
  20. };
  21. static const size_t sectTestsCount = SK_ARRAY_COUNT(sectTests);
  22. static const SkRect noSectTests[][2] = {
  23. {{2, 0, 4, 1}, {5, 0, 6, 1}},
  24. {{2, 0, 4, 1}, {3, 2, 5, 2}},
  25. };
  26. static const size_t noSectTestsCount = SK_ARRAY_COUNT(noSectTests);
  27. DEF_TEST(PathOpsBounds, reporter) {
  28. for (size_t index = 0; index < sectTestsCount; ++index) {
  29. const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sectTests[index][0]);
  30. SkASSERT(ValidBounds(bounds1));
  31. const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sectTests[index][1]);
  32. SkASSERT(ValidBounds(bounds2));
  33. bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
  34. REPORTER_ASSERT(reporter, touches);
  35. }
  36. for (size_t index = 0; index < noSectTestsCount; ++index) {
  37. const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noSectTests[index][0]);
  38. SkASSERT(ValidBounds(bounds1));
  39. const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noSectTests[index][1]);
  40. SkASSERT(ValidBounds(bounds2));
  41. bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
  42. REPORTER_ASSERT(reporter, !touches);
  43. }
  44. SkPathOpsBounds bounds;
  45. bounds.setEmpty();
  46. bounds.add(1, 2, 3, 4);
  47. SkPathOpsBounds expected;
  48. expected.set(0, 0, 3, 4);
  49. REPORTER_ASSERT(reporter, bounds == expected);
  50. bounds.setEmpty();
  51. SkPathOpsBounds ordinal;
  52. ordinal.set(1, 2, 3, 4);
  53. bounds.add(ordinal);
  54. REPORTER_ASSERT(reporter, bounds == expected);
  55. bounds.setEmpty();
  56. SkDPoint botRight = {3, 4};
  57. bounds.add(botRight);
  58. REPORTER_ASSERT(reporter, bounds == expected);
  59. const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}};
  60. SkDCurve curve;
  61. curve.fQuad.set(curvePts);
  62. curve.setQuadBounds(curvePts, 1, 0, 1, &bounds);
  63. expected.set(0, 0, 3, 4);
  64. REPORTER_ASSERT(reporter, bounds == expected);
  65. curve.fCubic.set(curvePts);
  66. curve.setCubicBounds(curvePts, 1, 0, 1, &bounds);
  67. expected.set(0, 0, 5, 6);
  68. REPORTER_ASSERT(reporter, bounds == expected);
  69. }