9166dcb3a0
This CL depends on https://codereview.chromium.org/12827020/ "Add base types for path ops" The intersection of a line, quadratic, or cubic with another curve (or with itself) is found by solving the implicit equation for the curve pair. The curves are first reduced to find the simplest form that will describe the original, and to detect degenerate or special-case data like horizontal and vertical lines. For cubic self-intersection, and for a pair of cubics, the intersection is found by recursively approximating the cubic with a series of quadratics. The implicit solutions depend on the root finding contained in the DCubic and DQuad structs, and the quartic root finder included here. Review URL: https://codereview.chromium.org/12880016 git-svn-id: http://skia.googlecode.com/svn/trunk@8552 2bbb7eff-a529-9590-31e7-b0007b416f81
105 lines
2.9 KiB
C++
105 lines
2.9 KiB
C++
/*
|
|
* 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 "PathOpsQuadIntersectionTestData.h"
|
|
|
|
const SkDQuad quadraticPoints[] = {
|
|
{{{0, 0}, {1, 0}, {0, 0}}},
|
|
{{{0, 0}, {0, 1}, {0, 0}}},
|
|
{{{0, 0}, {1, 1}, {0, 0}}},
|
|
{{{1, 1}, {2, 2}, {1, 1}}},
|
|
};
|
|
|
|
const size_t quadraticPoints_count = sizeof(quadraticPoints) / sizeof(quadraticPoints[0]);
|
|
|
|
const SkDQuad quadraticLines[] = {
|
|
{{{0, 0}, {0, 0}, {1, 0}}},
|
|
{{{1, 0}, {0, 0}, {0, 0}}},
|
|
{{{1, 0}, {2, 0}, {3, 0}}},
|
|
{{{0, 0}, {0, 0}, {0, 1}}},
|
|
{{{0, 1}, {0, 0}, {0, 0}}},
|
|
{{{0, 1}, {0, 2}, {0, 3}}},
|
|
{{{0, 0}, {0, 0}, {1, 1}}},
|
|
{{{1, 1}, {0, 0}, {0, 0}}},
|
|
{{{1, 1}, {2, 2}, {3, 3}}},
|
|
{{{1, 1}, {3, 3}, {3, 3}}},
|
|
{{{1, 1}, {1, 1}, {2, 2}}},
|
|
{{{1, 1}, {1, 1}, {3, 3}}},
|
|
{{{1, 1}, {2, 2}, {4, 4}}}, // no coincident
|
|
{{{1, 1}, {3, 3}, {4, 4}}},
|
|
{{{1, 1}, {3, 3}, {2, 2}}},
|
|
{{{1, 1}, {4, 4}, {2, 2}}},
|
|
{{{1, 1}, {4, 4}, {3, 3}}},
|
|
{{{2, 2}, {1, 1}, {3, 3}}},
|
|
{{{2, 2}, {1, 1}, {4, 4}}},
|
|
{{{2, 2}, {3, 3}, {1, 1}}},
|
|
{{{2, 2}, {3, 3}, {4, 4}}},
|
|
{{{2, 2}, {4, 4}, {1, 1}}},
|
|
{{{2, 2}, {4, 4}, {3, 3}}},
|
|
};
|
|
|
|
const size_t quadraticLines_count = sizeof(quadraticLines) / sizeof(quadraticLines[0]);
|
|
|
|
static const double F = FLT_EPSILON * 3;
|
|
static const double H = FLT_EPSILON * 4;
|
|
static const double J = FLT_EPSILON * 5;
|
|
static const double K = FLT_EPSILON * 8; // INVESTIGATE: why are larger multiples necessary?
|
|
|
|
const SkDQuad quadraticModEpsilonLines[] = {
|
|
{{{0, F}, {0, 0}, {1, 0}}},
|
|
{{{0, 0}, {1, 0}, {0, F}}},
|
|
{{{1, 0}, {0, F}, {0, 0}}},
|
|
{{{1, H}, {2, 0}, {3, 0}}},
|
|
{{{F, 0}, {0, 0}, {0, 1}}},
|
|
{{{0, 0}, {0, 1}, {F, 0}}},
|
|
{{{0, 1}, {F, 0}, {0, 0}}},
|
|
{{{H, 1}, {0, 2}, {0, 3}}},
|
|
{{{0, F}, {0, 0}, {1, 1}}},
|
|
{{{0, 0}, {1, 1}, {F, 0}}},
|
|
{{{1, 1}, {F, 0}, {0, 0}}},
|
|
{{{1, 1+J}, {2, 2}, {3, 3}}},
|
|
{{{1, 1}, {3, 3}, {3+F, 3}}},
|
|
{{{1, 1}, {1+F, 1}, {2, 2}}},
|
|
{{{1, 1}, {2, 2}, {1, 1+F}}},
|
|
{{{1, 1}, {1, 1+F}, {3, 3}}},
|
|
{{{1+H, 1}, {2, 2}, {4, 4}}}, // no coincident
|
|
{{{1, 1+K}, {3, 3}, {4, 4}}},
|
|
{{{1, 1}, {3+F, 3}, {2, 2}}},
|
|
{{{1, 1}, {4, 4+F}, {2, 2}}},
|
|
{{{1, 1}, {4, 4}, {3+F, 3}}},
|
|
{{{2, 2}, {1, 1}, {3, 3+F}}},
|
|
{{{2+F, 2}, {1, 1}, {4, 4}}},
|
|
{{{2, 2+F}, {3, 3}, {1, 1}}},
|
|
{{{2, 2}, {3+F, 3}, {4, 4}}},
|
|
{{{2, 2}, {4, 4+F}, {1, 1}}},
|
|
{{{2, 2}, {4, 4}, {3+F, 3}}},
|
|
};
|
|
|
|
const size_t quadraticModEpsilonLines_count =
|
|
sizeof(quadraticModEpsilonLines) / sizeof(quadraticModEpsilonLines[0]);
|
|
|
|
const SkDQuad quadraticTests[][2] = {
|
|
{ // one intersection
|
|
{{{0, 0},
|
|
{0, 1},
|
|
{1, 1}}},
|
|
{{{0, 1},
|
|
{0, 0},
|
|
{1, 0}}}
|
|
},
|
|
{ // four intersections
|
|
{{{1, 0},
|
|
{2, 6},
|
|
{3, 0}}},
|
|
{{{0, 1},
|
|
{6, 2},
|
|
{0, 3}}}
|
|
}
|
|
};
|
|
|
|
const size_t quadraticTests_count = sizeof(quadraticTests) / sizeof(quadraticTests[0]);
|