caryclark@google.com | 9e49fb6 | 2012-08-27 14:11:33 +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 | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 7 | #include "CurveIntersection.h" |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 8 | #include "Intersection_Tests.h" |
caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame] | 9 | #include "IntersectionUtilities.h" |
| 10 | |
| 11 | static void assert_that(int x, int y, const char* s) { |
| 12 | if (x == y) { |
| 13 | return; |
| 14 | } |
caryclark@google.com | aa35831 | 2013-01-29 20:28:49 +0000 | [diff] [blame] | 15 | SkDebugf("result=%d expected=%d %s\n", x, y, s); |
caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | static void side_test() { |
| 19 | assert_that(side(-1), 0, "side(-1) != 0"); |
| 20 | assert_that(side(0), 1, "side(0) != 1"); |
| 21 | assert_that(side(1), 2, "side(1) != 2"); |
| 22 | } |
| 23 | |
| 24 | static void sideBit_test() { |
| 25 | assert_that(sideBit(-1), 1, "sideBit(-1) != 1"); |
| 26 | assert_that(sideBit(0), 2, "sideBit(0) != 2"); |
| 27 | assert_that(sideBit(1), 4, "sideBit(1) != 4"); |
| 28 | } |
| 29 | |
| 30 | static void other_two_test() { |
| 31 | for (int x = 0; x < 4; ++x) { |
| 32 | for (int y = 0; y < 4; ++y) { |
| 33 | if (x == y) { |
| 34 | continue; |
| 35 | } |
| 36 | int mask = other_two(x, y); |
| 37 | int all = 1 << x; |
| 38 | all |= 1 << y; |
| 39 | all |= 1 << (x ^ mask); |
| 40 | all |= 1 << (y ^ mask); |
| 41 | if (all == 0x0F) { |
| 42 | continue; |
| 43 | } |
caryclark@google.com | aa35831 | 2013-01-29 20:28:49 +0000 | [diff] [blame] | 44 | SkDebugf("[%d,%d] other_two failed mask=%d [%d,%d]\n", |
caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame] | 45 | x, y, mask, x ^ mask, y ^ mask); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void Inline_Tests() { |
| 51 | side_test(); |
| 52 | sideBit_test(); |
| 53 | other_two_test(); |
| 54 | } |