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(PathOpsDVector, reporter) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 24 | for (size_t index = 0; index < tests_count - 1; ++index) { |
| 25 | SkDVector v1 = tests[index + 1] - tests[index]; |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 26 | SkASSERT(ValidVector(v1)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 27 | SkDVector v2 = tests[index] - tests[index + 1]; |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 28 | SkASSERT(ValidVector(v2)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 29 | v1 += v2; |
| 30 | REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 31 | v2 -= v2; |
| 32 | REPORTER_ASSERT(reporter, v2.fX == 0 && v2.fY == 0); |
| 33 | v1 = tests[index + 1] - tests[index]; |
| 34 | v1 /= 2; |
| 35 | v1 *= 2; |
| 36 | v1 -= tests[index + 1] - tests[index]; |
| 37 | REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0); |
| 38 | SkVector sv = v1.asSkVector(); |
| 39 | REPORTER_ASSERT(reporter, sv.fX == 0 && sv.fY == 0); |
| 40 | v1 = tests[index + 1] - tests[index]; |
| 41 | double lenSq = v1.lengthSquared(); |
| 42 | double v1Dot = v1.dot(v1); |
| 43 | REPORTER_ASSERT(reporter, lenSq == v1Dot); |
| 44 | REPORTER_ASSERT(reporter, approximately_equal(sqrt(lenSq), v1.length())); |
| 45 | double v1Cross = v1.cross(v1); |
| 46 | REPORTER_ASSERT(reporter, v1Cross == 0); |
| 47 | } |
| 48 | } |