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-08-23 18:14:13 +00:00
|
|
|
|
2012-07-02 20:27:02 +00:00
|
|
|
#define DEBUG_TEST 1
|
2012-08-23 18:14:13 +00:00
|
|
|
|
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-07-27 18:26:38 +00:00
|
|
|
int contourWinding, int spanWinding, 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-12-06 21:47:48 +00:00
|
|
|
makeContourList(contours, contourList, false, false);
|
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-08-20 12:43:57 +00:00
|
|
|
int nextStart = startIndex;
|
|
|
|
int nextEnd = endIndex;
|
2012-07-11 17:52:32 +00:00
|
|
|
SkTDArray<SimplifyFindNextTest::Span*> chaseArray;
|
2012-10-16 12:06:27 +00:00
|
|
|
bool unsortable = false;
|
2012-08-20 12:43:57 +00:00
|
|
|
SimplifyFindNextTest::Segment* next = segment.findNextWinding(chaseArray,
|
2013-01-03 21:18:16 +00:00
|
|
|
nextStart, nextEnd, unsortable);
|
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-07-27 18:26:38 +00:00
|
|
|
int contourWinding = 0;
|
|
|
|
int spanWinding = 1;
|
2012-05-18 20:50:33 +00:00
|
|
|
int start = 0;
|
2012-05-22 17:01:14 +00:00
|
|
|
int end = 1;
|
2012-07-27 18:26:38 +00:00
|
|
|
testCommon(contourWinding, spanWinding, 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-07-27 18:26:38 +00:00
|
|
|
int contourWinding = 0;
|
|
|
|
int spanWinding = 1;
|
|
|
|
testCommon(contourWinding, spanWinding, 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;
|
|
|
|
}
|
|
|
|
}
|