2013-04-15 19:13:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#include "SkOpSegment.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
static const SkPoint cubics[][4] = {
|
2013-05-07 18:51:31 +00:00
|
|
|
{{0, 1}, {2, 6}, {4, 2}, {5, 3}},
|
|
|
|
{{10, 234}, {10, 229.581726f}, {13.5817204f, 226}, {18, 226}},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SkPoint quads[][3] = {
|
|
|
|
{{12.3423996f, 228.342407f}, {10, 230.686295f}, {10, 234}},
|
2013-04-15 19:13:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const SkPoint lines[][2] = {
|
2013-05-07 18:51:31 +00:00
|
|
|
{{6, 2}, {2, 4}},
|
2013-04-15 19:13:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SortSet {
|
|
|
|
const SkPoint* ptData;
|
|
|
|
int ptCount;
|
|
|
|
double tStart;
|
|
|
|
double tEnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SortSet set1[] = {
|
2013-04-17 15:49:16 +00:00
|
|
|
{cubics[0], 4, 0.66666987081928919, 0.875},
|
|
|
|
{lines[0], 2, 0.574070336, 0.388888889},
|
|
|
|
{cubics[0], 4, 0.66666987081928919, 0.4050371120499307 },
|
|
|
|
{lines[0], 2, 0.574070336, 0.9140625},
|
2013-04-15 19:13:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const SortSet set2[] = {
|
2013-04-17 15:49:16 +00:00
|
|
|
{cubics[0], 4, 0.666666667, 0.875},
|
2013-04-15 19:13:59 +00:00
|
|
|
{lines[0], 2, 0.574074074, 0.388888889},
|
|
|
|
{cubics[0], 4, 0.666666667, 0.405037112},
|
|
|
|
{lines[0], 2, 0.574074074, 0.9140625},
|
|
|
|
};
|
|
|
|
|
2013-05-07 18:51:31 +00:00
|
|
|
static const SortSet set3[] = {
|
|
|
|
{cubics[1], 4, 0, 1},
|
|
|
|
{quads[0], 3, 1, 0},
|
|
|
|
};
|
|
|
|
|
2013-04-15 19:13:59 +00:00
|
|
|
struct SortSetTests {
|
|
|
|
const SortSet* set;
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SortSetTests tests[] = {
|
2013-05-07 18:51:31 +00:00
|
|
|
{ set3, SK_ARRAY_COUNT(set3) },
|
2013-04-17 15:49:16 +00:00
|
|
|
{ set2, SK_ARRAY_COUNT(set2) },
|
2013-05-07 18:51:31 +00:00
|
|
|
{ set1, SK_ARRAY_COUNT(set1) },
|
2013-04-15 19:13:59 +00:00
|
|
|
};
|
|
|
|
|
2013-04-16 07:01:17 +00:00
|
|
|
static void setup(const SortSet* set, const size_t idx, SkPoint const ** data,
|
2013-04-17 15:49:16 +00:00
|
|
|
SkOpSegment* seg, int* ts) {
|
2013-04-15 19:13:59 +00:00
|
|
|
SkPoint start, end;
|
2013-05-07 18:51:31 +00:00
|
|
|
*data = set[idx].ptData;
|
|
|
|
switch(set[idx].ptCount) {
|
|
|
|
case 2: {
|
|
|
|
seg->addLine(*data, false, false);
|
|
|
|
SkDLine dLine;
|
|
|
|
dLine.set(set[idx].ptData);
|
|
|
|
start = dLine.xyAtT(set[idx].tStart).asSkPoint();
|
|
|
|
end = dLine.xyAtT(set[idx].tEnd).asSkPoint();
|
|
|
|
} break;
|
|
|
|
case 3: {
|
|
|
|
seg->addQuad(*data, false, false);
|
|
|
|
SkDQuad dQuad;
|
|
|
|
dQuad.set(set[idx].ptData);
|
|
|
|
start = dQuad.xyAtT(set[idx].tStart).asSkPoint();
|
|
|
|
end = dQuad.xyAtT(set[idx].tEnd).asSkPoint();
|
|
|
|
} break;
|
|
|
|
case 4: {
|
|
|
|
seg->addCubic(*data, false, false);
|
|
|
|
SkDCubic dCubic;
|
|
|
|
dCubic.set(set[idx].ptData);
|
|
|
|
start = dCubic.xyAtT(set[idx].tStart).asSkPoint();
|
|
|
|
end = dCubic.xyAtT(set[idx].tEnd).asSkPoint();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
double tStart = set[idx].tStart;
|
|
|
|
double tEnd = set[idx].tEnd;
|
|
|
|
seg->addT(NULL, start, tStart);
|
|
|
|
seg->addT(NULL, end, tEnd);
|
|
|
|
double tLeft = tStart < tEnd ? 0 : 1;
|
|
|
|
if (tStart != tLeft && tEnd != tLeft) {
|
|
|
|
seg->addT(NULL, set[idx].ptData[0], tLeft);
|
|
|
|
}
|
|
|
|
double tRight = tStart < tEnd ? 1 : 0;
|
|
|
|
if (tStart != tRight && tEnd != tRight) {
|
|
|
|
seg->addT(NULL, set[idx].ptData[set[idx].ptCount - 1], tRight);
|
2013-04-15 19:13:59 +00:00
|
|
|
}
|
2013-04-17 15:49:16 +00:00
|
|
|
int tIndex = 0;
|
|
|
|
do {
|
|
|
|
if (seg->t(tIndex) == set[idx].tStart) {
|
|
|
|
ts[0] = tIndex;
|
|
|
|
}
|
|
|
|
if (seg->t(tIndex) == set[idx].tEnd) {
|
|
|
|
ts[1] = tIndex;
|
|
|
|
}
|
|
|
|
if (seg->t(tIndex) >= 1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (++tIndex);
|
2013-04-15 19:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PathOpsAngleTest(skiatest::Reporter* reporter) {
|
|
|
|
for (size_t index = 0; index < SK_ARRAY_COUNT(tests); ++index) {
|
|
|
|
const SortSetTests& test = tests[index];
|
|
|
|
for (size_t idxL = 0; idxL < test.count - 1; ++idxL) {
|
|
|
|
SkOpSegment lesser, greater;
|
2013-04-17 15:49:16 +00:00
|
|
|
int lesserTs[2], greaterTs[2];
|
2013-04-15 19:13:59 +00:00
|
|
|
const SkPoint* lesserData, * greaterData;
|
|
|
|
const SortSet* set = test.set;
|
2013-04-17 15:49:16 +00:00
|
|
|
setup(set, idxL, &lesserData, &lesser, lesserTs);
|
2013-04-15 19:13:59 +00:00
|
|
|
size_t idxG = idxL + 1;
|
2013-04-17 15:49:16 +00:00
|
|
|
setup(set, idxG, &greaterData, &greater, greaterTs);
|
2013-04-15 19:13:59 +00:00
|
|
|
SkOpAngle first, second;
|
|
|
|
first.set(lesserData, (SkPath::Verb) (set[idxL].ptCount - 1), &lesser,
|
2013-04-17 15:49:16 +00:00
|
|
|
lesserTs[0], lesserTs[1], lesser.spans());
|
2013-04-15 19:13:59 +00:00
|
|
|
second.set(greaterData, (SkPath::Verb) (set[idxG].ptCount - 1), &greater,
|
2013-04-17 15:49:16 +00:00
|
|
|
greaterTs[0], greaterTs[1], greater.spans());
|
2013-04-15 19:13:59 +00:00
|
|
|
bool compare = first < second;
|
|
|
|
if (!compare) {
|
|
|
|
SkDebugf("%s test[%d]: lesser[%d] > greater[%d]\n", __FUNCTION__,
|
|
|
|
index, idxL, idxG);
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, compare);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
|
|
|
DEFINE_TESTCLASS_SHORT(PathOpsAngleTest)
|