skia2/experimental/Intersection/SimplifyFindNext_Test.cpp
caryclark@google.com 8dcf114db9 shape ops work in progress
M    Intersection/DataTypes.cpp
M    Intersection/QuadraticIntersection_Test.cpp
M    Intersection/EdgeWalker.cpp
M    Intersection/LineQuadraticIntersection_Test.cpp
M    Intersection/LineIntersection_Test.cpp
M    Intersection/LineIntersection.cpp
D    Intersection/edge.xcodeproj
M    Intersection/SimplifyFindTop_Test.cpp
M    Intersection/DataTypes.h
A    Intersection/SimplifyRect4x4_Test.cpp
M    Intersection/CubicIntersection_Test.cpp
M    Intersection/QuadraticUtilities.h
M    Intersection/LineCubicIntersection_Test.cpp
A    Intersection/CurveUtilities.h
M    Intersection/QuadraticBezierClip.cpp
M    Intersection/QuadraticBounds.cpp
M    Intersection/LineUtilities.h
M    Intersection/Intersection_Tests.cpp
M    Intersection/Simplify.cpp
M    Intersection/EdgeWalker_TestUtility.cpp
M    Intersection/QuadraticUtilities.cpp
M    Intersection/thingsToDo.txt
M    Intersection/LineUtilities.cpp
M    Intersection/CubicUtilities.h
M    Intersection/SimplifyFindNext_Test.cpp
M    Intersection/Intersection_Tests.h
M    Intersection/CubicBezierClip.cpp
M    Intersection/ActiveEdge_Test.cpp
M    Intersection/CubicBounds.cpp
M    Intersection/Simplify.h
M    Intersection/SimplifyNew_Test.cpp
M    Intersection/EdgeWalker_Test.h
M    Intersection/CubicUtilities.cpp
M    Intersection/op.htm
M    Intersection/ConvexHull.cpp
D    Intersection/RectUtilities.cpp
M    Intersection/SimplifyAddIntersectingTs_Test.cpp



git-svn-id: http://skia.googlecode.com/svn/trunk@4429 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-07-02 20:27:02 +00:00

149 lines
3.4 KiB
C++

/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#define DEBUG_TEST 1
#include "Simplify.h"
namespace SimplifyFindNextTest {
#include "Simplify.cpp"
} // end of SimplifyFindNextTest namespace
#include "Intersection_Tests.h"
static const SimplifyFindNextTest::Segment* testCommon(
int winding, int startIndex, int endIndex,
SkTArray<SimplifyFindNextTest::Contour>& contours) {
SkTDArray<SimplifyFindNextTest::Contour*> contourList;
makeContourList(contours, contourList);
addIntersectTs(contourList[0], contourList[0]);
if (contours.count() > 1) {
SkASSERT(contours.count() == 2);
addIntersectTs(contourList[0], contourList[1]);
addIntersectTs(contourList[1], contourList[1]);
}
fixOtherTIndex(contourList);
SimplifyFindNextTest::Segment& segment = contours[0].debugSegments()[0];
SkPoint pts[2];
pts[0] = segment.xyAtT(&segment.span(endIndex));
int nextStart, nextEnd;
SimplifyFindNextTest::Segment* next = segment.findNext(winding,
startIndex, endIndex, nextStart, nextEnd, true);
pts[1] = next->xyAtT(&next->span(nextStart));
SkASSERT(pts[0] == pts[1]);
return next;
}
static void test(const SkPath& path) {
SkTArray<SimplifyFindNextTest::Contour> contours;
SimplifyFindNextTest::EdgeBuilder builder(path, contours);
int winding = 0;
int start = 0;
int end = 1;
testCommon(winding, start, end, contours);
}
static void test(const SkPath& path, int start, int end) {
SkTArray<SimplifyFindNextTest::Contour> contours;
SimplifyFindNextTest::EdgeBuilder builder(path, contours);
int winding = 0;
testCommon(winding, start, end, contours);
}
static void testLine1() {
SkPath path;
path.moveTo(2,0);
path.lineTo(1,1);
path.lineTo(0,0);
path.close();
test(path);
}
static void addInnerCWTriangle(SkPath& path) {
path.moveTo(3,0);
path.lineTo(4,1);
path.lineTo(2,1);
path.close();
}
#if DEBUG_UNUSED
static void addInnerCCWTriangle(SkPath& path) {
path.moveTo(3,0);
path.lineTo(2,1);
path.lineTo(4,1);
path.close();
}
#endif
static void addOuterCWTriangle(SkPath& path) {
path.moveTo(3,0);
path.lineTo(6,2);
path.lineTo(0,2);
path.close();
}
#if DEBUG_UNUSED
static void addOuterCCWTriangle(SkPath& path) {
path.moveTo(3,0);
path.lineTo(0,2);
path.lineTo(6,2);
path.close();
}
#endif
static void testLine2() {
SkPath path;
addInnerCWTriangle(path);
addOuterCWTriangle(path);
test(path, 0, 3);
}
static void testLine3() {
SkPath path;
addInnerCWTriangle(path);
addOuterCWTriangle(path);
test(path, 3, 0);
}
static void testLine4() {
SkPath path;
addInnerCWTriangle(path);
addOuterCWTriangle(path);
test(path, 3, 2);
}
static void (*tests[])() = {
testLine1,
testLine2,
testLine3,
testLine4,
};
static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
static void (*firstTest)() = 0;
static bool skipAll = false;
void SimplifyFindNext_Test() {
if (skipAll) {
return;
}
size_t index = 0;
if (firstTest) {
while (index < testCount && tests[index] != firstTest) {
++index;
}
}
bool firstTestComplete = false;
for ( ; index < testCount; ++index) {
(*tests[index])();
firstTestComplete = true;
}
}