PathOpsDPointTest.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/SkPathOpsPoint.h"
  8. #include "tests/PathOpsTestCommon.h"
  9. #include "tests/Test.h"
  10. static const SkDPoint tests[] = {
  11. {0, 0},
  12. {1, 0},
  13. {0, 1},
  14. {2, 1},
  15. {1, 2},
  16. {1, 1},
  17. {2, 2}
  18. };
  19. static const size_t tests_count = SK_ARRAY_COUNT(tests);
  20. DEF_TEST(PathOpsDPoint, reporter) {
  21. for (size_t index = 0; index < tests_count; ++index) {
  22. const SkDPoint& pt = tests[index];
  23. SkASSERT(ValidPoint(pt));
  24. SkDPoint p = pt;
  25. REPORTER_ASSERT(reporter, p == pt);
  26. REPORTER_ASSERT(reporter, !(pt != pt));
  27. SkDVector v = p - pt;
  28. p += v;
  29. REPORTER_ASSERT(reporter, p == pt);
  30. p -= v;
  31. REPORTER_ASSERT(reporter, p == pt);
  32. REPORTER_ASSERT(reporter, p.approximatelyEqual(pt));
  33. SkPoint sPt = pt.asSkPoint();
  34. p.set(sPt);
  35. REPORTER_ASSERT(reporter, p == pt);
  36. REPORTER_ASSERT(reporter, p.approximatelyEqual(sPt));
  37. REPORTER_ASSERT(reporter, p.roughlyEqual(pt));
  38. p.fX = p.fY = 0;
  39. REPORTER_ASSERT(reporter, p.fX == 0 && p.fY == 0);
  40. REPORTER_ASSERT(reporter, p.approximatelyZero());
  41. REPORTER_ASSERT(reporter, pt.distanceSquared(p) == pt.fX * pt.fX + pt.fY * pt.fY);
  42. REPORTER_ASSERT(reporter, approximately_equal(pt.distance(p),
  43. sqrt(pt.fX * pt.fX + pt.fY * pt.fY)));
  44. }
  45. }