caryclark@google.com | af46cff | 2012-05-22 21:12:00 +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 | |
| 8 | #include "Simplify.h" |
| 9 | |
| 10 | namespace SimplifyNewTest { |
| 11 | |
| 12 | #include "Simplify.cpp" |
| 13 | |
| 14 | } // end of SimplifyNewTest namespace |
| 15 | |
| 16 | #include "EdgeWalker_Test.h" |
| 17 | #include "Intersection_Tests.h" |
| 18 | |
| 19 | static SkBitmap bitmap; |
| 20 | |
caryclark@google.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame] | 21 | static bool testSimplifyx(const SkPath& path, SkPath& out, SkBitmap& bitmap) { |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 22 | if (false) { |
| 23 | showPath(path); |
| 24 | } |
caryclark@google.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame] | 25 | simplifyx(path, out); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 26 | if (false) { |
| 27 | return true; |
| 28 | } |
| 29 | return comparePaths(path, out, bitmap, 0) == 0; |
| 30 | } |
| 31 | |
| 32 | static void testLine1() { |
| 33 | SkPath path, simple; |
| 34 | path.moveTo(2,0); |
| 35 | path.lineTo(1,1); |
| 36 | path.lineTo(0,0); |
| 37 | path.close(); |
caryclark@google.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame] | 38 | testSimplifyx(path, simple, bitmap); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | static void addInnerCWTriangle(SkPath& path) { |
| 42 | path.moveTo(3,0); |
| 43 | path.lineTo(4,1); |
| 44 | path.lineTo(2,1); |
| 45 | path.close(); |
| 46 | } |
| 47 | |
| 48 | static void addInnerCCWTriangle(SkPath& path) { |
| 49 | path.moveTo(3,0); |
| 50 | path.lineTo(2,1); |
| 51 | path.lineTo(4,1); |
| 52 | path.close(); |
| 53 | } |
| 54 | |
| 55 | static void addOuterCWTriangle(SkPath& path) { |
| 56 | path.moveTo(3,0); |
| 57 | path.lineTo(6,2); |
| 58 | path.lineTo(0,2); |
| 59 | path.close(); |
| 60 | } |
| 61 | |
| 62 | static void addOuterCCWTriangle(SkPath& path) { |
| 63 | path.moveTo(3,0); |
| 64 | path.lineTo(0,2); |
| 65 | path.lineTo(6,2); |
| 66 | path.close(); |
| 67 | } |
| 68 | |
| 69 | static void testLine2() { |
| 70 | SkPath path, simple; |
| 71 | addInnerCWTriangle(path); |
| 72 | addOuterCWTriangle(path); |
caryclark@google.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame] | 73 | testSimplifyx(path, simple, bitmap); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 74 | } |
| 75 | |
caryclark@google.com | 495f8e4 | 2012-05-31 13:13:11 +0000 | [diff] [blame] | 76 | static void testLine3() { |
| 77 | SkPath path, simple; |
| 78 | addInnerCCWTriangle(path); |
| 79 | addOuterCWTriangle(path); |
| 80 | testSimplifyx(path, simple, bitmap); |
| 81 | } |
| 82 | |
| 83 | static void testLine4() { |
| 84 | SkPath path, simple; |
| 85 | addOuterCCWTriangle(path); |
| 86 | addOuterCWTriangle(path); |
| 87 | testSimplifyx(path, simple, bitmap); |
| 88 | } |
| 89 | |
| 90 | static void testLine5() { |
| 91 | SkPath path, simple; |
| 92 | addOuterCWTriangle(path); |
| 93 | addOuterCWTriangle(path); |
| 94 | testSimplifyx(path, simple, bitmap); |
| 95 | } |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 96 | |
| 97 | static void (*tests[])() = { |
| 98 | testLine1, |
| 99 | testLine2, |
caryclark@google.com | 495f8e4 | 2012-05-31 13:13:11 +0000 | [diff] [blame] | 100 | testLine3, |
| 101 | testLine4, |
| 102 | testLine5 |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | static const size_t testCount = sizeof(tests) / sizeof(tests[0]); |
| 106 | |
caryclark@google.com | 06c279e | 2012-06-06 11:52:28 +0000 | [diff] [blame^] | 107 | static void (*firstTest)() = testLine5; |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 108 | static bool skipAll = false; |
| 109 | |
| 110 | void SimplifyNew_Test() { |
| 111 | if (skipAll) { |
| 112 | return; |
| 113 | } |
| 114 | size_t index = 0; |
| 115 | if (firstTest) { |
| 116 | while (index < testCount && tests[index] != firstTest) { |
| 117 | ++index; |
| 118 | } |
| 119 | } |
| 120 | bool firstTestComplete = false; |
| 121 | for ( ; index < testCount; ++index) { |
caryclark@google.com | a3f05fa | 2012-06-01 17:44:28 +0000 | [diff] [blame] | 122 | SkDebugf("%s [%d]\n", __FUNCTION__, index + 1); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 123 | (*tests[index])(); |
| 124 | firstTestComplete = true; |
| 125 | } |
| 126 | } |