2012-05-22 21:12:00 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Simplify.h"
|
|
|
|
|
|
|
|
namespace SimplifyNewTest {
|
|
|
|
|
|
|
|
#include "Simplify.cpp"
|
|
|
|
|
|
|
|
} // end of SimplifyNewTest namespace
|
|
|
|
|
|
|
|
#include "EdgeWalker_Test.h"
|
|
|
|
#include "Intersection_Tests.h"
|
|
|
|
|
2012-06-07 21:09:20 +00:00
|
|
|
static bool testSimplifyx(const SkPath& path) {
|
2012-05-22 21:12:00 +00:00
|
|
|
if (false) {
|
|
|
|
showPath(path);
|
|
|
|
}
|
2012-06-07 21:09:20 +00:00
|
|
|
SkPath out;
|
2012-05-23 18:09:25 +00:00
|
|
|
simplifyx(path, out);
|
2012-05-22 21:12:00 +00:00
|
|
|
if (false) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-06-07 21:09:20 +00:00
|
|
|
SkBitmap bitmap;
|
2012-05-22 21:12:00 +00:00
|
|
|
return comparePaths(path, out, bitmap, 0) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testLine1() {
|
|
|
|
SkPath path, simple;
|
|
|
|
path.moveTo(2,0);
|
|
|
|
path.lineTo(1,1);
|
|
|
|
path.lineTo(0,0);
|
|
|
|
path.close();
|
2012-06-07 21:09:20 +00:00
|
|
|
testSimplifyx(path);
|
2012-05-22 21:12:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void addInnerCWTriangle(SkPath& path) {
|
|
|
|
path.moveTo(3,0);
|
|
|
|
path.lineTo(4,1);
|
|
|
|
path.lineTo(2,1);
|
|
|
|
path.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addInnerCCWTriangle(SkPath& path) {
|
|
|
|
path.moveTo(3,0);
|
|
|
|
path.lineTo(2,1);
|
|
|
|
path.lineTo(4,1);
|
|
|
|
path.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addOuterCWTriangle(SkPath& path) {
|
|
|
|
path.moveTo(3,0);
|
|
|
|
path.lineTo(6,2);
|
|
|
|
path.lineTo(0,2);
|
|
|
|
path.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addOuterCCWTriangle(SkPath& path) {
|
|
|
|
path.moveTo(3,0);
|
|
|
|
path.lineTo(0,2);
|
|
|
|
path.lineTo(6,2);
|
|
|
|
path.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testLine2() {
|
|
|
|
SkPath path, simple;
|
|
|
|
addInnerCWTriangle(path);
|
|
|
|
addOuterCWTriangle(path);
|
2012-06-07 21:09:20 +00:00
|
|
|
testSimplifyx(path);
|
2012-05-22 21:12:00 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 13:13:11 +00:00
|
|
|
static void testLine3() {
|
|
|
|
SkPath path, simple;
|
|
|
|
addInnerCCWTriangle(path);
|
|
|
|
addOuterCWTriangle(path);
|
2012-06-07 21:09:20 +00:00
|
|
|
testSimplifyx(path);
|
2012-05-31 13:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void testLine4() {
|
|
|
|
SkPath path, simple;
|
|
|
|
addOuterCCWTriangle(path);
|
|
|
|
addOuterCWTriangle(path);
|
2012-06-07 21:09:20 +00:00
|
|
|
testSimplifyx(path);
|
2012-05-31 13:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void testLine5() {
|
|
|
|
SkPath path, simple;
|
|
|
|
addOuterCWTriangle(path);
|
|
|
|
addOuterCWTriangle(path);
|
2012-06-07 21:09:20 +00:00
|
|
|
testSimplifyx(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testLine6() {
|
|
|
|
SkPath path, simple;
|
|
|
|
path.moveTo(0,0);
|
|
|
|
path.lineTo(4,0);
|
|
|
|
path.lineTo(2,2);
|
|
|
|
path.close();
|
|
|
|
path.moveTo(2,0);
|
|
|
|
path.lineTo(6,0);
|
|
|
|
path.lineTo(4,2);
|
|
|
|
path.close();
|
|
|
|
testSimplifyx(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testLine7() {
|
|
|
|
SkPath path, simple;
|
|
|
|
path.moveTo(0,0);
|
|
|
|
path.lineTo(4,0);
|
|
|
|
path.lineTo(2,2);
|
|
|
|
path.close();
|
|
|
|
path.moveTo(6,0);
|
|
|
|
path.lineTo(2,0);
|
|
|
|
path.lineTo(4,2);
|
|
|
|
path.close();
|
|
|
|
testSimplifyx(path);
|
2012-05-31 13:13:11 +00:00
|
|
|
}
|
2012-05-22 21:12:00 +00:00
|
|
|
|
2012-06-07 21:09:20 +00:00
|
|
|
static void testLine8() {
|
|
|
|
SkPath path, simple;
|
|
|
|
path.moveTo(0,4);
|
|
|
|
path.lineTo(4,4);
|
|
|
|
path.lineTo(2,2);
|
|
|
|
path.close();
|
|
|
|
path.moveTo(2,4);
|
|
|
|
path.lineTo(6,4);
|
|
|
|
path.lineTo(4,2);
|
|
|
|
path.close();
|
|
|
|
testSimplifyx(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testLine9() {
|
|
|
|
SkPath path, simple;
|
|
|
|
path.moveTo(0,4);
|
|
|
|
path.lineTo(4,4);
|
|
|
|
path.lineTo(2,2);
|
|
|
|
path.close();
|
|
|
|
path.moveTo(6,4);
|
|
|
|
path.lineTo(2,4);
|
|
|
|
path.lineTo(4,2);
|
|
|
|
path.close();
|
|
|
|
testSimplifyx(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-22 21:12:00 +00:00
|
|
|
static void (*tests[])() = {
|
|
|
|
testLine1,
|
|
|
|
testLine2,
|
2012-05-31 13:13:11 +00:00
|
|
|
testLine3,
|
|
|
|
testLine4,
|
2012-06-07 21:09:20 +00:00
|
|
|
testLine5,
|
|
|
|
testLine6,
|
|
|
|
testLine7,
|
|
|
|
testLine8,
|
|
|
|
testLine9
|
2012-05-22 21:12:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
|
|
|
|
|
2012-06-07 21:09:20 +00:00
|
|
|
static void (*firstTest)() = 0;
|
2012-05-22 21:12:00 +00:00
|
|
|
static bool skipAll = false;
|
|
|
|
|
|
|
|
void SimplifyNew_Test() {
|
|
|
|
if (skipAll) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
size_t index = 0;
|
|
|
|
if (firstTest) {
|
|
|
|
while (index < testCount && tests[index] != firstTest) {
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool firstTestComplete = false;
|
|
|
|
for ( ; index < testCount; ++index) {
|
2012-06-01 17:44:28 +00:00
|
|
|
SkDebugf("%s [%d]\n", __FUNCTION__, index + 1);
|
2012-05-22 21:12:00 +00:00
|
|
|
(*tests[index])();
|
|
|
|
firstTestComplete = true;
|
|
|
|
}
|
|
|
|
}
|