2012-08-27 14:11: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-02-03 22:07:47 +00:00
|
|
|
#include "CurveIntersection.h"
|
2012-01-25 18:57:23 +00:00
|
|
|
#include "CubicIntersection_TestData.h"
|
|
|
|
#include "Intersection_Tests.h"
|
|
|
|
#include "QuadraticIntersection_TestData.h"
|
|
|
|
#include "TestUtilities.h"
|
|
|
|
|
|
|
|
void CubicReduceOrder_Test() {
|
|
|
|
size_t index;
|
|
|
|
Cubic reduce;
|
|
|
|
int order;
|
|
|
|
enum {
|
|
|
|
RunAll,
|
|
|
|
RunPointDegenerates,
|
|
|
|
RunNotPointDegenerates,
|
|
|
|
RunLines,
|
|
|
|
RunNotLines,
|
|
|
|
RunModEpsilonLines,
|
|
|
|
RunLessEpsilonLines,
|
|
|
|
RunNegEpsilonLines,
|
|
|
|
RunQuadraticLines,
|
|
|
|
RunQuadraticModLines,
|
|
|
|
RunComputedLines,
|
|
|
|
RunNone
|
|
|
|
} run = RunAll;
|
|
|
|
int firstTestIndex = 0;
|
|
|
|
#if 0
|
|
|
|
run = RunComputedLines;
|
|
|
|
firstTestIndex = 18;
|
|
|
|
#endif
|
2013-01-29 20:28:49 +00:00
|
|
|
int firstPointDegeneratesTest = run == RunAll ? 0 : run == RunPointDegenerates ? firstTestIndex : SK_MaxS32;
|
|
|
|
int firstNotPointDegeneratesTest = run == RunAll ? 0 : run == RunNotPointDegenerates ? firstTestIndex : SK_MaxS32;
|
|
|
|
int firstLinesTest = run == RunAll ? 0 : run == RunLines ? firstTestIndex : SK_MaxS32;
|
|
|
|
int firstNotLinesTest = run == RunAll ? 0 : run == RunNotLines ? firstTestIndex : SK_MaxS32;
|
|
|
|
int firstModEpsilonTest = run == RunAll ? 0 : run == RunModEpsilonLines ? firstTestIndex : SK_MaxS32;
|
|
|
|
int firstLessEpsilonTest = run == RunAll ? 0 : run == RunLessEpsilonLines ? firstTestIndex : SK_MaxS32;
|
|
|
|
int firstNegEpsilonTest = run == RunAll ? 0 : run == RunNegEpsilonLines ? firstTestIndex : SK_MaxS32;
|
|
|
|
int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex : SK_MaxS32;
|
|
|
|
int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex : SK_MaxS32;
|
|
|
|
int firstComputedLinesTest = run == RunAll ? 0 : run == RunComputedLines ? firstTestIndex : SK_MaxS32;
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-01-25 18:57:23 +00:00
|
|
|
for (index = firstPointDegeneratesTest; index < pointDegenerates_count; ++index) {
|
|
|
|
const Cubic& cubic = pointDegenerates[index];
|
2013-02-17 01:41:25 +00:00
|
|
|
order = reduceOrder(cubic, reduce, kReduceOrder_QuadraticsAllowed,
|
|
|
|
kReduceOrder_TreatAsFill);
|
2012-01-25 18:57:23 +00:00
|
|
|
if (order != 1) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] pointDegenerates order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index = firstNotPointDegeneratesTest; index < notPointDegenerates_count; ++index) {
|
|
|
|
const Cubic& cubic = notPointDegenerates[index];
|
2013-02-17 01:41:25 +00:00
|
|
|
order = reduceOrder(cubic, reduce, kReduceOrder_QuadraticsAllowed,
|
|
|
|
kReduceOrder_TreatAsFill);
|
2012-01-25 18:57:23 +00:00
|
|
|
if (order == 1) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] notPointDegenerates order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index = firstLinesTest; index < lines_count; ++index) {
|
|
|
|
const Cubic& cubic = lines[index];
|
2013-02-17 01:41:25 +00:00
|
|
|
order = reduceOrder(cubic, reduce, kReduceOrder_QuadraticsAllowed,
|
|
|
|
kReduceOrder_TreatAsFill);
|
2012-01-25 18:57:23 +00:00
|
|
|
if (order != 2) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] lines order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index = firstNotLinesTest; index < notLines_count; ++index) {
|
|
|
|
const Cubic& cubic = notLines[index];
|
2013-02-17 01:41:25 +00:00
|
|
|
order = reduceOrder(cubic, reduce, kReduceOrder_QuadraticsAllowed,
|
|
|
|
kReduceOrder_TreatAsFill);
|
2012-01-25 18:57:23 +00:00
|
|
|
if (order == 2) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] notLines order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index = firstModEpsilonTest; index < modEpsilonLines_count; ++index) {
|
|
|
|
const Cubic& cubic = modEpsilonLines[index];
|
2013-02-17 01:41:25 +00:00
|
|
|
order = reduceOrder(cubic, reduce, kReduceOrder_QuadraticsAllowed,
|
|
|
|
kReduceOrder_TreatAsFill);
|
2012-01-25 18:57:23 +00:00
|
|
|
if (order == 2) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] line mod by epsilon order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index = firstLessEpsilonTest; index < lessEpsilonLines_count; ++index) {
|
|
|
|
const Cubic& cubic = lessEpsilonLines[index];
|
2013-02-17 01:41:25 +00:00
|
|
|
order = reduceOrder(cubic, reduce, kReduceOrder_QuadraticsAllowed,
|
|
|
|
kReduceOrder_TreatAsFill);
|
2012-01-25 18:57:23 +00:00
|
|
|
if (order != 2) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] line less by epsilon/2 order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index = firstNegEpsilonTest; index < negEpsilonLines_count; ++index) {
|
|
|
|
const Cubic& cubic = negEpsilonLines[index];
|
2013-02-17 01:41:25 +00:00
|
|
|
order = reduceOrder(cubic, reduce, kReduceOrder_QuadraticsAllowed,
|
|
|
|
kReduceOrder_TreatAsFill);
|
2012-01-25 18:57:23 +00:00
|
|
|
if (order != 2) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] line neg by epsilon/2 order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) {
|
|
|
|
const Quadratic& quad = quadraticLines[index];
|
|
|
|
Cubic cubic;
|
|
|
|
quad_to_cubic(quad, cubic);
|
2013-02-17 01:41:25 +00:00
|
|
|
order = reduceOrder(cubic, reduce, kReduceOrder_QuadraticsAllowed,
|
|
|
|
kReduceOrder_TreatAsFill);
|
2012-01-25 18:57:23 +00:00
|
|
|
if (order != 2) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] line quad order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) {
|
|
|
|
const Quadratic& quad = quadraticModEpsilonLines[index];
|
|
|
|
Cubic cubic;
|
|
|
|
quad_to_cubic(quad, cubic);
|
2013-02-17 01:41:25 +00:00
|
|
|
order = reduceOrder(cubic, reduce, kReduceOrder_QuadraticsAllowed,
|
|
|
|
kReduceOrder_TreatAsFill);
|
2012-01-25 18:57:23 +00:00
|
|
|
if (order != 3) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] line mod quad order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-01-25 18:57:23 +00:00
|
|
|
// test if computed line end points are valid
|
|
|
|
for (index = firstComputedLinesTest; index < lines_count; ++index) {
|
|
|
|
const Cubic& cubic = lines[index];
|
2012-08-23 18:14:13 +00:00
|
|
|
bool controlsInside = controls_inside(cubic);
|
2013-02-17 01:41:25 +00:00
|
|
|
order = reduceOrder(cubic, reduce, kReduceOrder_QuadraticsAllowed,
|
|
|
|
kReduceOrder_TreatAsFill);
|
2012-01-25 18:57:23 +00:00
|
|
|
if (reduce[0].x == reduce[1].x && reduce[0].y == reduce[1].y) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] line computed ends match order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
if (controlsInside) {
|
2012-12-10 12:50:53 +00:00
|
|
|
if ( (reduce[0].x != cubic[0].x && reduce[0].x != cubic[3].x)
|
|
|
|
|| (reduce[0].y != cubic[0].y && reduce[0].y != cubic[3].y)
|
|
|
|
|| (reduce[1].x != cubic[0].x && reduce[1].x != cubic[3].x)
|
|
|
|
|| (reduce[1].y != cubic[0].y && reduce[1].y != cubic[3].y)) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] line computed ends order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// binary search for extrema, compare against actual results
|
|
|
|
// while a control point is outside of bounding box formed by end points, split
|
|
|
|
_Rect bounds = {DBL_MAX, DBL_MAX, -DBL_MAX, -DBL_MAX};
|
|
|
|
find_tight_bounds(cubic, bounds);
|
2013-01-04 19:41:13 +00:00
|
|
|
if ( (!AlmostEqualUlps(reduce[0].x, bounds.left) && !AlmostEqualUlps(reduce[0].x, bounds.right))
|
|
|
|
|| (!AlmostEqualUlps(reduce[0].y, bounds.top) && !AlmostEqualUlps(reduce[0].y, bounds.bottom))
|
|
|
|
|| (!AlmostEqualUlps(reduce[1].x, bounds.left) && !AlmostEqualUlps(reduce[1].x, bounds.right))
|
|
|
|
|| (!AlmostEqualUlps(reduce[1].y, bounds.top) && !AlmostEqualUlps(reduce[1].y, bounds.bottom))) {
|
2013-01-29 20:28:49 +00:00
|
|
|
SkDebugf("[%d] line computed tight bounds order=%d\n", (int) index, order);
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-01-25 18:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|