SimplifyFindNext_Test.cpp revision afe56de6361a81eef537ddd8f6d5626c8546d4c7
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#define DEBUG_TEST 1 9 10#include "Simplify.h" 11 12namespace SimplifyFindNextTest { 13 14#include "Simplify.cpp" 15 16} // end of SimplifyFindNextTest namespace 17 18#include "Intersection_Tests.h" 19 20static const SimplifyFindNextTest::Segment* testCommon( 21 int winding, int startIndex, int endIndex, 22 SkTArray<SimplifyFindNextTest::Contour>& contours) { 23 SkTDArray<SimplifyFindNextTest::Contour*> contourList; 24 makeContourList(contours, contourList); 25 addIntersectTs(contourList[0], contourList[0]); 26 if (contours.count() > 1) { 27 SkASSERT(contours.count() == 2); 28 addIntersectTs(contourList[0], contourList[1]); 29 addIntersectTs(contourList[1], contourList[1]); 30 } 31 fixOtherTIndex(contourList); 32 SimplifyFindNextTest::Segment& segment = contours[0].debugSegments()[0]; 33 SkPoint pts[2]; 34 pts[0] = segment.xyAtT(&segment.span(endIndex)); 35 int nextStart, nextEnd; 36 SkTDArray<SimplifyFindNextTest::Span*> chaseArray; 37 SimplifyFindNextTest::Segment* next = segment.findNext(chaseArray, winding, 38 0, true, true, startIndex, endIndex, nextStart, nextEnd, winding); 39 pts[1] = next->xyAtT(&next->span(nextStart)); 40 SkASSERT(pts[0] == pts[1]); 41 return next; 42} 43 44static void test(const SkPath& path) { 45 SkTArray<SimplifyFindNextTest::Contour> contours; 46 SimplifyFindNextTest::EdgeBuilder builder(path, contours); 47 int winding = 0; 48 int start = 0; 49 int end = 1; 50 testCommon(winding, start, end, contours); 51} 52 53static void test(const SkPath& path, int start, int end) { 54 SkTArray<SimplifyFindNextTest::Contour> contours; 55 SimplifyFindNextTest::EdgeBuilder builder(path, contours); 56 int winding = 0; 57 testCommon(winding, start, end, contours); 58} 59 60static void testLine1() { 61 SkPath path; 62 path.moveTo(2,0); 63 path.lineTo(1,1); 64 path.lineTo(0,0); 65 path.close(); 66 test(path); 67} 68 69static void addInnerCWTriangle(SkPath& path) { 70 path.moveTo(3,0); 71 path.lineTo(4,1); 72 path.lineTo(2,1); 73 path.close(); 74} 75 76#if DEBUG_UNUSED 77static void addInnerCCWTriangle(SkPath& path) { 78 path.moveTo(3,0); 79 path.lineTo(2,1); 80 path.lineTo(4,1); 81 path.close(); 82} 83#endif 84 85static void addOuterCWTriangle(SkPath& path) { 86 path.moveTo(3,0); 87 path.lineTo(6,2); 88 path.lineTo(0,2); 89 path.close(); 90} 91 92#if DEBUG_UNUSED 93static void addOuterCCWTriangle(SkPath& path) { 94 path.moveTo(3,0); 95 path.lineTo(0,2); 96 path.lineTo(6,2); 97 path.close(); 98} 99#endif 100 101static void testLine2() { 102 SkPath path; 103 addInnerCWTriangle(path); 104 addOuterCWTriangle(path); 105 test(path, 0, 3); 106} 107 108static void testLine3() { 109 SkPath path; 110 addInnerCWTriangle(path); 111 addOuterCWTriangle(path); 112 test(path, 3, 0); 113} 114 115static void testLine4() { 116 SkPath path; 117 addInnerCWTriangle(path); 118 addOuterCWTriangle(path); 119 test(path, 3, 2); 120} 121 122static void (*tests[])() = { 123 testLine1, 124 testLine2, 125 testLine3, 126 testLine4, 127}; 128 129static const size_t testCount = sizeof(tests) / sizeof(tests[0]); 130 131static void (*firstTest)() = 0; 132static bool skipAll = false; 133 134void SimplifyFindNext_Test() { 135 if (skipAll) { 136 return; 137 } 138 size_t index = 0; 139 if (firstTest) { 140 while (index < testCount && tests[index] != firstTest) { 141 ++index; 142 } 143 } 144 bool firstTestComplete = false; 145 for ( ; index < testCount; ++index) { 146 (*tests[index])(); 147 firstTestComplete = true; 148 } 149} 150