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 "SkPathOpsLine.h" |
| 8 | #include "Test.h" |
| 9 | |
| 10 | static const SkDLine tests[] = { |
| 11 | {{{2, 1}, {2, 1}}}, |
| 12 | {{{2, 1}, {1, 1}}}, |
| 13 | {{{2, 1}, {2, 2}}}, |
| 14 | {{{1, 1}, {2, 2}}}, |
| 15 | {{{3, 0}, {2, 1}}}, |
| 16 | {{{3, 2}, {1, 1}}}, |
| 17 | }; |
| 18 | |
| 19 | static const SkDPoint left[] = { |
| 20 | {2, 1}, |
| 21 | {1, 0}, |
| 22 | {1, 1}, |
| 23 | {1, 2}, |
| 24 | {2, 0}, |
| 25 | {2, 1} |
| 26 | }; |
| 27 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 28 | static const size_t tests_count = SK_ARRAY_COUNT(tests); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 29 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 30 | static void PathOpsLineUtilitiesTest(skiatest::Reporter* reporter) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 31 | for (size_t index = 0; index < tests_count; ++index) { |
| 32 | const SkDLine& line = tests[index]; |
| 33 | SkDLine line2; |
| 34 | SkPoint pts[2] = {line[0].asSkPoint(), line[1].asSkPoint()}; |
| 35 | line2.set(pts); |
| 36 | REPORTER_ASSERT(reporter, line[0] == line2[0] && line[1] == line2[1]); |
| 37 | const SkDPoint& pt = left[index]; |
| 38 | double result = line.isLeft(pt); |
| 39 | if ((result <= 0 && index >= 1) || (result < 0 && index == 0)) { |
| 40 | SkDebugf("%s [%d] expected left\n", __FUNCTION__, index); |
| 41 | REPORTER_ASSERT(reporter, 0); |
| 42 | } |
| 43 | line2 = line.subDivide(1, 0); |
| 44 | REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]); |
| 45 | line2 = SkDLine::SubDivide(pts, 1, 0); |
| 46 | REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]); |
| 47 | SkDPoint mid = line.xyAtT(.5); |
| 48 | REPORTER_ASSERT(reporter, approximately_equal((line[0].fX + line[1].fX) / 2, mid.fX)); |
| 49 | REPORTER_ASSERT(reporter, approximately_equal((line[0].fY + line[1].fY) / 2, mid.fY)); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | #include "TestClassDef.h" |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 54 | DEFINE_TESTCLASS_SHORT(PathOpsLineUtilitiesTest) |