caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 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 | */ |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 7 | #include "PathOpsTestCommon.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 8 | #include "SkPathOpsPoint.h" |
| 9 | #include "Test.h" |
| 10 | |
| 11 | static const SkDPoint tests[] = { |
| 12 | {0, 0}, |
| 13 | {1, 0}, |
| 14 | {0, 1}, |
| 15 | {2, 1}, |
| 16 | {1, 2}, |
| 17 | {1, 1}, |
| 18 | {2, 2} |
| 19 | }; |
| 20 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 21 | static const size_t tests_count = SK_ARRAY_COUNT(tests); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 22 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 23 | DEF_TEST(PathOpsDPoint, reporter) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 24 | for (size_t index = 0; index < tests_count; ++index) { |
| 25 | const SkDPoint& pt = tests[index]; |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 26 | SkASSERT(ValidPoint(pt)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 27 | SkDPoint p = pt; |
| 28 | REPORTER_ASSERT(reporter, p == pt); |
| 29 | REPORTER_ASSERT(reporter, !(pt != pt)); |
| 30 | SkDVector v = p - pt; |
| 31 | p += v; |
| 32 | REPORTER_ASSERT(reporter, p == pt); |
| 33 | p -= v; |
| 34 | REPORTER_ASSERT(reporter, p == pt); |
| 35 | REPORTER_ASSERT(reporter, p.approximatelyEqual(pt)); |
| 36 | SkPoint sPt = pt.asSkPoint(); |
| 37 | p.set(sPt); |
| 38 | REPORTER_ASSERT(reporter, p == pt); |
| 39 | REPORTER_ASSERT(reporter, p.approximatelyEqual(sPt)); |
| 40 | REPORTER_ASSERT(reporter, p.roughlyEqual(pt)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 41 | p.fX = p.fY = 0; |
| 42 | REPORTER_ASSERT(reporter, p.fX == 0 && p.fY == 0); |
| 43 | REPORTER_ASSERT(reporter, p.approximatelyZero()); |
| 44 | REPORTER_ASSERT(reporter, pt.distanceSquared(p) == pt.fX * pt.fX + pt.fY * pt.fY); |
| 45 | REPORTER_ASSERT(reporter, approximately_equal(pt.distance(p), |
| 46 | sqrt(pt.fX * pt.fX + pt.fY * pt.fY))); |
| 47 | } |
| 48 | } |