2013-04-08 11:50: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 "PathOpsExtendedTest.h"
|
2013-07-16 16:11:16 +00:00
|
|
|
#include "PathOpsTestCommon.h"
|
2013-04-08 11:50:00 +00:00
|
|
|
#include "SkIntersections.h"
|
|
|
|
#include "SkPathOpsLine.h"
|
|
|
|
#include "SkPathOpsQuad.h"
|
|
|
|
#include "SkReduceOrder.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
2018-06-18 19:11:00 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2013-04-08 11:50:00 +00:00
|
|
|
static struct lineQuad {
|
2016-10-20 15:32:18 +00:00
|
|
|
QuadPts quad;
|
2013-04-08 11:50:00 +00:00
|
|
|
SkDLine line;
|
|
|
|
int result;
|
|
|
|
SkDPoint expected[2];
|
|
|
|
} lineQuadTests[] = {
|
|
|
|
// quad line results
|
|
|
|
{{{{1, 1}, {2, 1}, {0, 2}}}, {{{0, 0}, {1, 1}}}, 1, {{1, 1}, {0, 0}} },
|
|
|
|
{{{{0, 0}, {1, 1}, {3, 1}}}, {{{0, 0}, {3, 1}}}, 2, {{0, 0}, {3, 1}} },
|
|
|
|
{{{{2, 0}, {1, 1}, {2, 2}}}, {{{0, 0}, {0, 2}}}, 0, {{0, 0}, {0, 0}} },
|
|
|
|
{{{{4, 0}, {0, 1}, {4, 2}}}, {{{3, 1}, {4, 1}}}, 0, {{0, 0}, {0, 0}} },
|
|
|
|
{{{{0, 0}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}, 1, {{.25, .75}, {0, 0}} },
|
|
|
|
};
|
|
|
|
|
2013-04-15 19:13:59 +00:00
|
|
|
static size_t lineQuadTests_count = SK_ARRAY_COUNT(lineQuadTests);
|
2013-04-08 11:50:00 +00:00
|
|
|
|
|
|
|
static int doIntersect(SkIntersections& intersections, const SkDQuad& quad, const SkDLine& line,
|
|
|
|
bool& flipped) {
|
|
|
|
int result;
|
|
|
|
flipped = false;
|
|
|
|
if (line[0].fX == line[1].fX) {
|
|
|
|
double top = line[0].fY;
|
|
|
|
double bottom = line[1].fY;
|
|
|
|
flipped = top > bottom;
|
|
|
|
if (flipped) {
|
2018-06-18 19:11:00 +00:00
|
|
|
using std::swap;
|
|
|
|
swap(top, bottom);
|
2013-04-08 11:50:00 +00:00
|
|
|
}
|
|
|
|
result = intersections.vertical(quad, top, bottom, line[0].fX, flipped);
|
|
|
|
} else if (line[0].fY == line[1].fY) {
|
|
|
|
double left = line[0].fX;
|
|
|
|
double right = line[1].fX;
|
|
|
|
flipped = left > right;
|
|
|
|
if (flipped) {
|
2018-06-18 19:11:00 +00:00
|
|
|
using std::swap;
|
|
|
|
swap(left, right);
|
2013-04-08 11:50:00 +00:00
|
|
|
}
|
|
|
|
result = intersections.horizontal(quad, left, right, line[0].fY, flipped);
|
|
|
|
} else {
|
|
|
|
intersections.intersect(quad, line);
|
|
|
|
result = intersections.used();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct oneLineQuad {
|
2016-10-20 15:32:18 +00:00
|
|
|
QuadPts quad;
|
2013-04-08 11:50:00 +00:00
|
|
|
SkDLine line;
|
|
|
|
} oneOffs[] = {
|
2014-04-14 17:08:59 +00:00
|
|
|
{{{{97.9337616,100}, {88,112.94265}, {88,130}}},
|
|
|
|
{{{88.919838,120}, {107.058823,120}}}},
|
2013-11-02 07:02:02 +00:00
|
|
|
{{{{447.96701049804687, 894.4381103515625}, {448.007080078125, 894.4239501953125},
|
|
|
|
{448.0140380859375, 894.4215087890625}}},
|
2013-11-01 17:36:03 +00:00
|
|
|
{{{490.43548583984375, 879.40740966796875}, {405.59262084960937, 909.435546875}}}},
|
2013-09-16 15:55:01 +00:00
|
|
|
{{{{142.589081, 102.283646}, {149.821579, 100}, {158, 100}}},
|
|
|
|
{{{90, 230}, {160, 60}}}},
|
2013-07-15 13:29:13 +00:00
|
|
|
{{{{1101, 10}, {1101, 8.3431453704833984}, {1099.828857421875, 7.1711997985839844}}},
|
|
|
|
{{{1099.828857421875,7.1711711883544922}, {1099.121337890625,7.8786783218383789}}}},
|
2013-05-07 18:51:31 +00:00
|
|
|
{{{{973, 507}, {973, 508.24264526367187}, {972.12158203125, 509.12161254882812}}},
|
|
|
|
{{{930, 467}, {973, 510}}}},
|
2013-04-08 11:50:00 +00:00
|
|
|
{{{{369.848602, 145.680267}, {382.360413, 121.298294}, {406.207703, 121.298294}}},
|
2013-07-15 13:29:13 +00:00
|
|
|
{{{406.207703, 121.298294}, {348.781738, 123.864815}}}},
|
|
|
|
};
|
2013-04-08 11:50:00 +00:00
|
|
|
|
2013-04-15 19:13:59 +00:00
|
|
|
static size_t oneOffs_count = SK_ARRAY_COUNT(oneOffs);
|
2013-04-08 11:50:00 +00:00
|
|
|
|
|
|
|
static void testOneOffs(skiatest::Reporter* reporter) {
|
|
|
|
bool flipped = false;
|
|
|
|
for (size_t index = 0; index < oneOffs_count; ++index) {
|
2016-10-20 15:32:18 +00:00
|
|
|
const QuadPts& q = oneOffs[index].quad;
|
|
|
|
SkDQuad quad;
|
|
|
|
quad.debugSet(q.fPts);
|
2013-07-16 16:11:16 +00:00
|
|
|
SkASSERT(ValidQuad(quad));
|
2013-04-08 11:50:00 +00:00
|
|
|
const SkDLine& line = oneOffs[index].line;
|
2013-07-16 16:11:16 +00:00
|
|
|
SkASSERT(ValidLine(line));
|
2013-05-07 18:51:31 +00:00
|
|
|
SkIntersections intersections;
|
2013-04-08 11:50:00 +00:00
|
|
|
int result = doIntersect(intersections, quad, line, flipped);
|
|
|
|
for (int inner = 0; inner < result; ++inner) {
|
|
|
|
double quadT = intersections[0][inner];
|
2013-07-23 15:27:41 +00:00
|
|
|
SkDPoint quadXY = quad.ptAtT(quadT);
|
2013-04-08 11:50:00 +00:00
|
|
|
double lineT = intersections[1][inner];
|
2013-07-23 15:27:41 +00:00
|
|
|
SkDPoint lineXY = line.ptAtT(lineT);
|
2013-10-02 14:49:34 +00:00
|
|
|
if (!quadXY.approximatelyEqual(lineXY)) {
|
|
|
|
quadXY.approximatelyEqual(lineXY);
|
|
|
|
SkDebugf("");
|
|
|
|
}
|
2013-04-08 11:50:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, quadXY.approximatelyEqual(lineXY));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-02 21:45:03 +00:00
|
|
|
DEF_TEST(PathOpsQuadLineIntersectionOneOff, reporter) {
|
2013-04-08 11:50:00 +00:00
|
|
|
testOneOffs(reporter);
|
2013-07-15 13:29:13 +00:00
|
|
|
}
|
|
|
|
|
2014-01-02 21:45:03 +00:00
|
|
|
DEF_TEST(PathOpsQuadLineIntersection, reporter) {
|
2013-04-08 11:50:00 +00:00
|
|
|
for (size_t index = 0; index < lineQuadTests_count; ++index) {
|
|
|
|
int iIndex = static_cast<int>(index);
|
2016-10-20 15:32:18 +00:00
|
|
|
const QuadPts& q = lineQuadTests[index].quad;
|
|
|
|
SkDQuad quad;
|
|
|
|
quad.debugSet(q.fPts);
|
2013-07-16 16:11:16 +00:00
|
|
|
SkASSERT(ValidQuad(quad));
|
2013-04-08 11:50:00 +00:00
|
|
|
const SkDLine& line = lineQuadTests[index].line;
|
2013-07-16 16:11:16 +00:00
|
|
|
SkASSERT(ValidLine(line));
|
2013-04-08 11:50:00 +00:00
|
|
|
SkReduceOrder reducer1, reducer2;
|
2013-11-25 14:18:21 +00:00
|
|
|
int order1 = reducer1.reduce(quad);
|
2013-04-08 11:50:00 +00:00
|
|
|
int order2 = reducer2.reduce(line);
|
|
|
|
if (order1 < 3) {
|
|
|
|
SkDebugf("%s [%d] quad order=%d\n", __FUNCTION__, iIndex, order1);
|
|
|
|
REPORTER_ASSERT(reporter, 0);
|
|
|
|
}
|
|
|
|
if (order2 < 2) {
|
|
|
|
SkDebugf("%s [%d] line order=%d\n", __FUNCTION__, iIndex, order2);
|
|
|
|
REPORTER_ASSERT(reporter, 0);
|
|
|
|
}
|
|
|
|
SkIntersections intersections;
|
|
|
|
bool flipped = false;
|
|
|
|
int result = doIntersect(intersections, quad, line, flipped);
|
|
|
|
REPORTER_ASSERT(reporter, result == lineQuadTests[index].result);
|
|
|
|
if (intersections.used() <= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (int pt = 0; pt < result; ++pt) {
|
|
|
|
double tt1 = intersections[0][pt];
|
|
|
|
REPORTER_ASSERT(reporter, tt1 >= 0 && tt1 <= 1);
|
2013-07-23 15:27:41 +00:00
|
|
|
SkDPoint t1 = quad.ptAtT(tt1);
|
2013-04-08 11:50:00 +00:00
|
|
|
double tt2 = intersections[1][pt];
|
|
|
|
REPORTER_ASSERT(reporter, tt2 >= 0 && tt2 <= 1);
|
2013-07-23 15:27:41 +00:00
|
|
|
SkDPoint t2 = line.ptAtT(tt2);
|
2013-04-08 11:50:00 +00:00
|
|
|
if (!t1.approximatelyEqual(t2)) {
|
|
|
|
SkDebugf("%s [%d,%d] x!= t1=%1.9g (%1.9g,%1.9g) t2=%1.9g (%1.9g,%1.9g)\n",
|
|
|
|
__FUNCTION__, iIndex, pt, tt1, t1.fX, t1.fY, tt2, t2.fX, t2.fY);
|
|
|
|
REPORTER_ASSERT(reporter, 0);
|
|
|
|
}
|
|
|
|
if (!t1.approximatelyEqual(lineQuadTests[index].expected[0])
|
|
|
|
&& (lineQuadTests[index].result == 1
|
|
|
|
|| !t1.approximatelyEqual(lineQuadTests[index].expected[1]))) {
|
|
|
|
SkDebugf("%s t1=(%1.9g,%1.9g)\n", __FUNCTION__, t1.fX, t1.fY);
|
|
|
|
REPORTER_ASSERT(reporter, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|