PathOpsDVectorTest.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(PathOpsDVector, reporter) {
  21. for (size_t index = 0; index < tests_count - 1; ++index) {
  22. SkDVector v1 = tests[index + 1] - tests[index];
  23. SkASSERT(ValidVector(v1));
  24. SkDVector v2 = tests[index] - tests[index + 1];
  25. SkASSERT(ValidVector(v2));
  26. v1 += v2;
  27. REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0);
  28. v2 -= static_cast<decltype(v2)&>(v2);
  29. REPORTER_ASSERT(reporter, v2.fX == 0 && v2.fY == 0);
  30. v1 = tests[index + 1] - tests[index];
  31. v1 /= 2;
  32. v1 *= 2;
  33. v1 -= tests[index + 1] - tests[index];
  34. REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0);
  35. SkVector sv = v1.asSkVector();
  36. REPORTER_ASSERT(reporter, sv.fX == 0 && sv.fY == 0);
  37. v1 = tests[index + 1] - tests[index];
  38. double lenSq = v1.lengthSquared();
  39. double v1Dot = v1.dot(v1);
  40. REPORTER_ASSERT(reporter, lenSq == v1Dot);
  41. REPORTER_ASSERT(reporter, approximately_equal(sqrt(lenSq), v1.length()));
  42. double v1Cross = v1.cross(v1);
  43. REPORTER_ASSERT(reporter, v1Cross == 0);
  44. }
  45. }