PathOpsDRectTest.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/SkPathOpsCubic.h"
  8. #include "src/pathops/SkPathOpsLine.h"
  9. #include "src/pathops/SkPathOpsQuad.h"
  10. #include "src/pathops/SkPathOpsRect.h"
  11. #include "tests/PathOpsTestCommon.h"
  12. #include "tests/Test.h"
  13. static const QuadPts quadTests[] = {
  14. {{{1, 1}, {2, 1}, {0, 2}}},
  15. {{{0, 0}, {1, 1}, {3, 1}}},
  16. {{{2, 0}, {1, 1}, {2, 2}}},
  17. {{{4, 0}, {0, 1}, {4, 2}}},
  18. {{{0, 0}, {0, 1}, {1, 1}}},
  19. };
  20. static const CubicPts cubicTests[] = {
  21. {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}},
  22. {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}},
  23. {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}},
  24. };
  25. static const size_t quadTests_count = SK_ARRAY_COUNT(quadTests);
  26. static const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests);
  27. static void setRawBounds(const SkDQuad& quad, SkDRect* rect) {
  28. rect->set(quad[0]);
  29. rect->add(quad[1]);
  30. rect->add(quad[2]);
  31. }
  32. static void setRawBounds(const SkDCubic& cubic, SkDRect* rect) {
  33. rect->set(cubic[0]);
  34. rect->add(cubic[1]);
  35. rect->add(cubic[2]);
  36. rect->add(cubic[3]);
  37. }
  38. DEF_TEST(PathOpsDRect, reporter) {
  39. size_t index;
  40. SkDRect rect, rect2;
  41. for (index = 0; index < quadTests_count; ++index) {
  42. const QuadPts& q = quadTests[index];
  43. SkDQuad quad;
  44. quad.debugSet(q.fPts);
  45. SkASSERT(ValidQuad(quad));
  46. setRawBounds(quad, &rect);
  47. rect2.setBounds(quad);
  48. REPORTER_ASSERT(reporter, rect.intersects(rect2));
  49. // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
  50. SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
  51. REPORTER_ASSERT(reporter, rect.contains(leftTop));
  52. SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
  53. REPORTER_ASSERT(reporter, rect.contains(rightBottom));
  54. }
  55. for (index = 0; index < cubicTests_count; ++index) {
  56. const CubicPts& c = cubicTests[index];
  57. SkDCubic cubic;
  58. cubic.debugSet(c.fPts);
  59. SkASSERT(ValidCubic(cubic));
  60. setRawBounds(cubic, &rect);
  61. rect2.setBounds(cubic);
  62. REPORTER_ASSERT(reporter, rect.intersects(rect2));
  63. // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
  64. SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
  65. REPORTER_ASSERT(reporter, rect.contains(leftTop));
  66. SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
  67. REPORTER_ASSERT(reporter, rect.contains(rightBottom));
  68. }
  69. }