2012-05-18 20:50:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2012-07-02 20:27:02 +00:00
|
|
|
#define DEBUG_TEST 1
|
|
|
|
|
2012-05-18 20:50:33 +00:00
|
|
|
#include "Simplify.h"
|
|
|
|
|
|
|
|
namespace SimplifyFindNextTest {
|
|
|
|
|
|
|
|
#include "Simplify.cpp"
|
|
|
|
|
|
|
|
} // end of SimplifyFindNextTest namespace
|
|
|
|
|
|
|
|
#include "Intersection_Tests.h"
|
|
|
|
|
|
|
|
static const SimplifyFindNextTest::Segment* testCommon(
|
2012-05-22 17:01:14 +00:00
|
|
|
int winding, int startIndex, int endIndex,
|
2012-05-23 18:09:25 +00:00
|
|
|
SkTArray<SimplifyFindNextTest::Contour>& contours) {
|
2012-05-18 20:50:33 +00:00
|
|
|
SkTDArray<SimplifyFindNextTest::Contour*> contourList;
|
2012-05-22 17:01:14 +00:00
|
|
|
makeContourList(contours, contourList);
|
2012-05-23 18:09:25 +00:00
|
|
|
addIntersectTs(contourList[0], contourList[0]);
|
2012-05-18 20:50:33 +00:00
|
|
|
if (contours.count() > 1) {
|
|
|
|
SkASSERT(contours.count() == 2);
|
2012-05-23 18:09:25 +00:00
|
|
|
addIntersectTs(contourList[0], contourList[1]);
|
|
|
|
addIntersectTs(contourList[1], contourList[1]);
|
2012-05-18 20:50:33 +00:00
|
|
|
}
|
|
|
|
fixOtherTIndex(contourList);
|
2012-07-02 20:27:02 +00:00
|
|
|
SimplifyFindNextTest::Segment& segment = contours[0].debugSegments()[0];
|
2012-05-22 17:01:14 +00:00
|
|
|
SkPoint pts[2];
|
2012-06-01 17:44:28 +00:00
|
|
|
pts[0] = segment.xyAtT(&segment.span(endIndex));
|
2012-05-31 13:13:11 +00:00
|
|
|
int nextStart, nextEnd;
|
2012-05-22 17:01:14 +00:00
|
|
|
SimplifyFindNextTest::Segment* next = segment.findNext(winding,
|
2012-07-02 20:27:02 +00:00
|
|
|
startIndex, endIndex, nextStart, nextEnd, true);
|
2012-06-07 21:09:20 +00:00
|
|
|
pts[1] = next->xyAtT(&next->span(nextStart));
|
2012-05-22 17:01:14 +00:00
|
|
|
SkASSERT(pts[0] == pts[1]);
|
2012-05-18 20:50:33 +00:00
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test(const SkPath& path) {
|
|
|
|
SkTArray<SimplifyFindNextTest::Contour> contours;
|
|
|
|
SimplifyFindNextTest::EdgeBuilder builder(path, contours);
|
2012-05-22 17:01:14 +00:00
|
|
|
int winding = 0;
|
2012-05-18 20:50:33 +00:00
|
|
|
int start = 0;
|
2012-05-22 17:01:14 +00:00
|
|
|
int end = 1;
|
2012-05-23 18:09:25 +00:00
|
|
|
testCommon(winding, start, end, contours);
|
2012-05-22 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test(const SkPath& path, int start, int end) {
|
|
|
|
SkTArray<SimplifyFindNextTest::Contour> contours;
|
|
|
|
SimplifyFindNextTest::EdgeBuilder builder(path, contours);
|
2012-05-18 20:50:33 +00:00
|
|
|
int winding = 0;
|
2012-05-23 18:09:25 +00:00
|
|
|
testCommon(winding, start, end, contours);
|
2012-05-18 20:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void testLine1() {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(2,0);
|
|
|
|
path.lineTo(1,1);
|
|
|
|
path.lineTo(0,0);
|
|
|
|
path.close();
|
|
|
|
test(path);
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:01:14 +00:00
|
|
|
static void addInnerCWTriangle(SkPath& path) {
|
|
|
|
path.moveTo(3,0);
|
|
|
|
path.lineTo(4,1);
|
|
|
|
path.lineTo(2,1);
|
|
|
|
path.close();
|
|
|
|
}
|
|
|
|
|
2012-05-23 18:09:25 +00:00
|
|
|
#if DEBUG_UNUSED
|
2012-05-22 17:01:14 +00:00
|
|
|
static void addInnerCCWTriangle(SkPath& path) {
|
|
|
|
path.moveTo(3,0);
|
|
|
|
path.lineTo(2,1);
|
|
|
|
path.lineTo(4,1);
|
|
|
|
path.close();
|
|
|
|
}
|
2012-05-23 18:09:25 +00:00
|
|
|
#endif
|
2012-05-22 17:01:14 +00:00
|
|
|
|
|
|
|
static void addOuterCWTriangle(SkPath& path) {
|
|
|
|
path.moveTo(3,0);
|
|
|
|
path.lineTo(6,2);
|
|
|
|
path.lineTo(0,2);
|
|
|
|
path.close();
|
|
|
|
}
|
|
|
|
|
2012-05-23 18:09:25 +00:00
|
|
|
#if DEBUG_UNUSED
|
2012-05-22 17:01:14 +00:00
|
|
|
static void addOuterCCWTriangle(SkPath& path) {
|
|
|
|
path.moveTo(3,0);
|
|
|
|
path.lineTo(0,2);
|
|
|
|
path.lineTo(6,2);
|
|
|
|
path.close();
|
|
|
|
}
|
2012-05-23 18:09:25 +00:00
|
|
|
#endif
|
2012-05-22 17:01:14 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-05-18 20:50:33 +00:00
|
|
|
static void (*tests[])() = {
|
|
|
|
testLine1,
|
2012-05-22 17:01:14 +00:00
|
|
|
testLine2,
|
|
|
|
testLine3,
|
|
|
|
testLine4,
|
2012-05-18 20:50:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|