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 | */ |
| 7 | #include "SkPathOpsPoint.h" |
| 8 | #include "Test.h" |
| 9 | |
| 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 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 20 | static const size_t tests_count = SK_ARRAY_COUNT(tests); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 21 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 22 | static void PathOpsDVectorTest(skiatest::Reporter* reporter) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 23 | for (size_t index = 0; index < tests_count - 1; ++index) { |
| 24 | SkDVector v1 = tests[index + 1] - tests[index]; |
| 25 | SkDVector v2 = tests[index] - tests[index + 1]; |
| 26 | v1 += v2; |
| 27 | REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0); |
| 28 | SkDPoint p = tests[index + 1] + v2; |
| 29 | REPORTER_ASSERT(reporter, p == tests[index]); |
| 30 | v2 -= v2; |
| 31 | REPORTER_ASSERT(reporter, v2.fX == 0 && v2.fY == 0); |
| 32 | v1 = tests[index + 1] - tests[index]; |
| 33 | v1 /= 2; |
| 34 | v1 *= 2; |
| 35 | v1 -= tests[index + 1] - tests[index]; |
| 36 | REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0); |
| 37 | SkVector sv = v1.asSkVector(); |
| 38 | REPORTER_ASSERT(reporter, sv.fX == 0 && sv.fY == 0); |
| 39 | v1 = tests[index + 1] - tests[index]; |
| 40 | double lenSq = v1.lengthSquared(); |
| 41 | double v1Dot = v1.dot(v1); |
| 42 | REPORTER_ASSERT(reporter, lenSq == v1Dot); |
| 43 | REPORTER_ASSERT(reporter, approximately_equal(sqrt(lenSq), v1.length())); |
| 44 | double v1Cross = v1.cross(v1); |
| 45 | REPORTER_ASSERT(reporter, v1Cross == 0); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | #include "TestClassDef.h" |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 50 | DEFINE_TESTCLASS_SHORT(PathOpsDVectorTest) |