2012-02-03 22:07:47 +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-07-02 20:27:02 +00:00
|
|
|
#include "Simplify.h"
|
2012-02-03 22:07:47 +00:00
|
|
|
|
2012-04-17 11:40:34 +00:00
|
|
|
#undef SkASSERT
|
|
|
|
#define SkASSERT(cond) while (!(cond)) { sk_throw(); }
|
2012-03-20 21:11:59 +00:00
|
|
|
|
2012-04-17 11:40:34 +00:00
|
|
|
// FIXME: remove once debugging is complete
|
2012-04-26 21:01:06 +00:00
|
|
|
#if 01 // set to 1 for no debugging whatsoever
|
2012-04-17 11:40:34 +00:00
|
|
|
|
2012-07-23 12:14:49 +00:00
|
|
|
//const bool gRunTestsInOneThread = false;
|
2012-04-17 11:40:34 +00:00
|
|
|
|
|
|
|
#define DEBUG_ACTIVE_LESS_THAN 0
|
2012-03-20 21:11:59 +00:00
|
|
|
#define DEBUG_ADD 0
|
|
|
|
#define DEBUG_ADD_BOTTOM_TS 0
|
2012-04-17 11:40:34 +00:00
|
|
|
#define DEBUG_ADD_INTERSECTING_TS 0
|
|
|
|
#define DEBUG_ADJUST_COINCIDENT 0
|
2012-04-10 18:28:55 +00:00
|
|
|
#define DEBUG_ASSEMBLE 0
|
2012-04-17 11:40:34 +00:00
|
|
|
#define DEBUG_BOTTOM 0
|
2012-04-10 18:28:55 +00:00
|
|
|
#define DEBUG_BRIDGE 0
|
2012-04-17 11:40:34 +00:00
|
|
|
#define DEBUG_DUMP 0
|
2012-03-20 21:11:59 +00:00
|
|
|
#define DEBUG_SORT_HORIZONTAL 0
|
|
|
|
#define DEBUG_OUT 0
|
|
|
|
#define DEBUG_OUT_LESS_THAN 0
|
2012-03-30 18:47:02 +00:00
|
|
|
#define DEBUG_SPLIT 0
|
2012-04-10 18:28:55 +00:00
|
|
|
#define DEBUG_STITCH_EDGE 0
|
2012-04-17 11:40:34 +00:00
|
|
|
#define DEBUG_TRIM_LINE 0
|
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
#else
|
|
|
|
|
2012-07-23 12:14:49 +00:00
|
|
|
//const bool gRunTestsInOneThread = true;
|
2012-04-17 11:40:34 +00:00
|
|
|
|
|
|
|
#define DEBUG_ACTIVE_LESS_THAN 0
|
2012-03-20 21:11:59 +00:00
|
|
|
#define DEBUG_ADD 01
|
|
|
|
#define DEBUG_ADD_BOTTOM_TS 0
|
2012-04-17 11:40:34 +00:00
|
|
|
#define DEBUG_ADD_INTERSECTING_TS 0
|
|
|
|
#define DEBUG_ADJUST_COINCIDENT 1
|
2012-04-10 18:28:55 +00:00
|
|
|
#define DEBUG_ASSEMBLE 1
|
2012-04-17 11:40:34 +00:00
|
|
|
#define DEBUG_BOTTOM 0
|
2012-04-10 18:28:55 +00:00
|
|
|
#define DEBUG_BRIDGE 1
|
2012-04-17 11:40:34 +00:00
|
|
|
#define DEBUG_DUMP 1
|
2012-03-20 21:11:59 +00:00
|
|
|
#define DEBUG_SORT_HORIZONTAL 01
|
|
|
|
#define DEBUG_OUT 01
|
|
|
|
#define DEBUG_OUT_LESS_THAN 0
|
2012-03-30 18:47:02 +00:00
|
|
|
#define DEBUG_SPLIT 1
|
2012-04-10 18:28:55 +00:00
|
|
|
#define DEBUG_STITCH_EDGE 1
|
2012-04-17 11:40:34 +00:00
|
|
|
#define DEBUG_TRIM_LINE 1
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
#endif
|
|
|
|
|
2012-04-10 18:28:55 +00:00
|
|
|
#if DEBUG_ASSEMBLE || DEBUG_BRIDGE
|
|
|
|
static const char* kLVerbStr[] = {"", "line", "quad", "cubic"};
|
|
|
|
#endif
|
|
|
|
#if DEBUG_STITCH_EDGE
|
|
|
|
static const char* kUVerbStr[] = {"", "Line", "Quad", "Cubic"};
|
|
|
|
#endif
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
static int LineIntersect(const SkPoint a[2], const SkPoint b[2],
|
2012-03-28 16:20:21 +00:00
|
|
|
Intersections& intersections) {
|
|
|
|
const _Line aLine = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}};
|
|
|
|
const _Line bLine = {{b[0].fX, b[0].fY}, {b[1].fX, b[1].fY}};
|
2013-02-14 15:29:11 +00:00
|
|
|
return intersect(aLine, bLine, intersections);
|
2012-03-28 16:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int QuadLineIntersect(const SkPoint a[3], const SkPoint b[2],
|
|
|
|
Intersections& intersections) {
|
|
|
|
const Quadratic aQuad = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}, {a[2].fX, a[2].fY}};
|
|
|
|
const _Line bLine = {{b[0].fX, b[0].fY}, {b[1].fX, b[1].fY}};
|
2012-03-30 18:47:02 +00:00
|
|
|
intersect(aQuad, bLine, intersections);
|
|
|
|
return intersections.fUsed;
|
2012-03-28 16:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int CubicLineIntersect(const SkPoint a[2], const SkPoint b[3],
|
|
|
|
Intersections& intersections) {
|
|
|
|
const Cubic aCubic = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}, {a[2].fX, a[2].fY},
|
|
|
|
{a[3].fX, a[3].fY}};
|
|
|
|
const _Line bLine = {{b[0].fX, b[0].fY}, {b[1].fX, b[1].fY}};
|
2013-01-17 21:02:47 +00:00
|
|
|
return intersect(aCubic, bLine, intersections);
|
2012-03-28 16:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int QuadIntersect(const SkPoint a[3], const SkPoint b[3],
|
|
|
|
Intersections& intersections) {
|
|
|
|
const Quadratic aQuad = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}, {a[2].fX, a[2].fY}};
|
|
|
|
const Quadratic bQuad = {{b[0].fX, b[0].fY}, {b[1].fX, b[1].fY}, {b[2].fX, b[2].fY}};
|
2013-02-14 15:29:11 +00:00
|
|
|
intersect2(aQuad, bQuad, intersections);
|
2012-03-30 18:47:02 +00:00
|
|
|
return intersections.fUsed;
|
2012-03-28 16:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int CubicIntersect(const SkPoint a[4], const SkPoint b[4],
|
|
|
|
Intersections& intersections) {
|
|
|
|
const Cubic aCubic = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}, {a[2].fX, a[2].fY},
|
|
|
|
{a[3].fX, a[3].fY}};
|
|
|
|
const Cubic bCubic = {{b[0].fX, b[0].fY}, {b[1].fX, b[1].fY}, {b[2].fX, b[2].fY},
|
|
|
|
{b[3].fX, b[3].fY}};
|
2012-03-30 18:47:02 +00:00
|
|
|
intersect(aCubic, bCubic, intersections);
|
|
|
|
return intersections.fUsed;
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
static int LineIntersect(const SkPoint a[2], SkScalar left, SkScalar right,
|
|
|
|
SkScalar y, double aRange[2]) {
|
2012-03-28 16:20:21 +00:00
|
|
|
const _Line aLine = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}};
|
2012-03-20 21:11:59 +00:00
|
|
|
return horizontalLineIntersect(aLine, left, right, y, aRange);
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 18:47:02 +00:00
|
|
|
static int QuadIntersect(const SkPoint a[3], SkScalar left, SkScalar right,
|
|
|
|
SkScalar y, double aRange[3]) {
|
|
|
|
const Quadratic aQuad = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}, {a[2].fX, a[2].fY}};
|
|
|
|
return horizontalIntersect(aQuad, left, right, y, aRange);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CubicIntersect(const SkPoint a[4], SkScalar left, SkScalar right,
|
|
|
|
SkScalar y, double aRange[4]) {
|
|
|
|
const Cubic aCubic = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}, {a[2].fX, a[2].fY},
|
|
|
|
{a[3].fX, a[3].fY}};
|
|
|
|
return horizontalIntersect(aCubic, left, right, y, aRange);
|
|
|
|
}
|
|
|
|
|
2012-03-01 19:16:31 +00:00
|
|
|
static void LineXYAtT(const SkPoint a[2], double t, SkPoint* out) {
|
2012-03-28 16:20:21 +00:00
|
|
|
const _Line line = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}};
|
2012-03-01 19:16:31 +00:00
|
|
|
double x, y;
|
2012-03-28 16:20:21 +00:00
|
|
|
xy_at_t(line, t, x, y);
|
2012-03-01 19:16:31 +00:00
|
|
|
out->fX = SkDoubleToScalar(x);
|
|
|
|
out->fY = SkDoubleToScalar(y);
|
2012-02-28 16:57:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 16:20:21 +00:00
|
|
|
static void QuadXYAtT(const SkPoint a[3], double t, SkPoint* out) {
|
|
|
|
const Quadratic quad = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}, {a[2].fX, a[2].fY}};
|
|
|
|
double x, y;
|
|
|
|
xy_at_t(quad, t, x, y);
|
|
|
|
out->fX = SkDoubleToScalar(x);
|
|
|
|
out->fY = SkDoubleToScalar(y);
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 16:20:21 +00:00
|
|
|
static void CubicXYAtT(const SkPoint a[4], double t, SkPoint* out) {
|
|
|
|
const Cubic cubic = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}, {a[2].fX, a[2].fY},
|
|
|
|
{a[3].fX, a[3].fY}};
|
|
|
|
double x, y;
|
|
|
|
xy_at_t(cubic, t, x, y);
|
|
|
|
out->fX = SkDoubleToScalar(x);
|
|
|
|
out->fY = SkDoubleToScalar(y);
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
static SkScalar LineYAtT(const SkPoint a[2], double t) {
|
2012-03-28 16:20:21 +00:00
|
|
|
const _Line aLine = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}};
|
2012-02-07 22:10:51 +00:00
|
|
|
double y;
|
|
|
|
xy_at_t(aLine, t, *(double*) 0, y);
|
|
|
|
return SkDoubleToScalar(y);
|
|
|
|
}
|
|
|
|
|
2012-03-28 16:20:21 +00:00
|
|
|
static SkScalar QuadYAtT(const SkPoint a[3], double t) {
|
|
|
|
const Quadratic quad = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}, {a[2].fX, a[2].fY}};
|
|
|
|
double y;
|
|
|
|
xy_at_t(quad, t, *(double*) 0, y);
|
|
|
|
return SkDoubleToScalar(y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkScalar CubicYAtT(const SkPoint a[4], double t) {
|
|
|
|
const Cubic cubic = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}, {a[2].fX, a[2].fY},
|
|
|
|
{a[3].fX, a[3].fY}};
|
|
|
|
double y;
|
|
|
|
xy_at_t(cubic, t, *(double*) 0, y);
|
|
|
|
return SkDoubleToScalar(y);
|
|
|
|
}
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
static void LineSubDivide(const SkPoint a[2], double startT, double endT,
|
|
|
|
SkPoint sub[2]) {
|
2012-03-28 16:20:21 +00:00
|
|
|
const _Line aLine = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}};
|
2012-02-07 22:10:51 +00:00
|
|
|
_Line dst;
|
|
|
|
sub_divide(aLine, startT, endT, dst);
|
|
|
|
sub[0].fX = SkDoubleToScalar(dst[0].x);
|
|
|
|
sub[0].fY = SkDoubleToScalar(dst[0].y);
|
|
|
|
sub[1].fX = SkDoubleToScalar(dst[1].x);
|
|
|
|
sub[1].fY = SkDoubleToScalar(dst[1].y);
|
|
|
|
}
|
|
|
|
|
2012-03-28 16:20:21 +00:00
|
|
|
static void QuadSubDivide(const SkPoint a[3], double startT, double endT,
|
|
|
|
SkPoint sub[3]) {
|
2012-04-17 11:40:34 +00:00
|
|
|
const Quadratic aQuad = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY},
|
|
|
|
{a[2].fX, a[2].fY}};
|
2012-03-28 16:20:21 +00:00
|
|
|
Quadratic dst;
|
|
|
|
sub_divide(aQuad, startT, endT, dst);
|
|
|
|
sub[0].fX = SkDoubleToScalar(dst[0].x);
|
|
|
|
sub[0].fY = SkDoubleToScalar(dst[0].y);
|
|
|
|
sub[1].fX = SkDoubleToScalar(dst[1].x);
|
|
|
|
sub[1].fY = SkDoubleToScalar(dst[1].y);
|
|
|
|
sub[2].fX = SkDoubleToScalar(dst[2].x);
|
|
|
|
sub[2].fY = SkDoubleToScalar(dst[2].y);
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
2012-02-07 22:10:51 +00:00
|
|
|
|
2012-03-28 16:20:21 +00:00
|
|
|
static void CubicSubDivide(const SkPoint a[4], double startT, double endT,
|
|
|
|
SkPoint sub[4]) {
|
2012-04-17 11:40:34 +00:00
|
|
|
const Cubic aCubic = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY},
|
|
|
|
{a[2].fX, a[2].fY}, {a[3].fX, a[3].fY}};
|
2012-03-28 16:20:21 +00:00
|
|
|
Cubic dst;
|
|
|
|
sub_divide(aCubic, startT, endT, dst);
|
|
|
|
sub[0].fX = SkDoubleToScalar(dst[0].x);
|
|
|
|
sub[0].fY = SkDoubleToScalar(dst[0].y);
|
|
|
|
sub[1].fX = SkDoubleToScalar(dst[1].x);
|
|
|
|
sub[1].fY = SkDoubleToScalar(dst[1].y);
|
|
|
|
sub[2].fX = SkDoubleToScalar(dst[2].x);
|
|
|
|
sub[2].fY = SkDoubleToScalar(dst[2].y);
|
|
|
|
sub[3].fX = SkDoubleToScalar(dst[3].x);
|
|
|
|
sub[3].fY = SkDoubleToScalar(dst[3].y);
|
|
|
|
}
|
2012-04-10 18:28:55 +00:00
|
|
|
|
|
|
|
static void QuadSubBounds(const SkPoint a[3], double startT, double endT,
|
|
|
|
SkRect& bounds) {
|
|
|
|
SkPoint dst[3];
|
|
|
|
QuadSubDivide(a, startT, endT, dst);
|
|
|
|
bounds.fLeft = bounds.fRight = dst[0].fX;
|
|
|
|
bounds.fTop = bounds.fBottom = dst[0].fY;
|
|
|
|
for (int index = 1; index < 3; ++index) {
|
|
|
|
bounds.growToInclude(dst[index].fX, dst[index].fY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CubicSubBounds(const SkPoint a[4], double startT, double endT,
|
|
|
|
SkRect& bounds) {
|
|
|
|
SkPoint dst[4];
|
|
|
|
CubicSubDivide(a, startT, endT, dst);
|
|
|
|
bounds.fLeft = bounds.fRight = dst[0].fX;
|
|
|
|
bounds.fTop = bounds.fBottom = dst[0].fY;
|
|
|
|
for (int index = 1; index < 4; ++index) {
|
|
|
|
bounds.growToInclude(dst[index].fX, dst[index].fY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 11:40:34 +00:00
|
|
|
static SkPath::Verb QuadReduceOrder(SkPoint a[4]) {
|
|
|
|
const Quadratic aQuad = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY},
|
|
|
|
{a[2].fX, a[2].fY}};
|
|
|
|
Quadratic dst;
|
2013-02-17 01:41:25 +00:00
|
|
|
int order = reduceOrder(aQuad, dst, kReduceOrder_TreatAsFill);
|
2012-04-17 11:40:34 +00:00
|
|
|
for (int index = 0; index < order; ++index) {
|
|
|
|
a[index].fX = SkDoubleToScalar(dst[index].x);
|
|
|
|
a[index].fY = SkDoubleToScalar(dst[index].y);
|
|
|
|
}
|
|
|
|
if (order == 1) { // FIXME: allow returning points, caller should discard
|
|
|
|
a[1] = a[0];
|
|
|
|
return (SkPath::Verb) order;
|
|
|
|
}
|
|
|
|
return (SkPath::Verb) (order - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkPath::Verb CubicReduceOrder(SkPoint a[4]) {
|
|
|
|
const Cubic aCubic = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY},
|
|
|
|
{a[2].fX, a[2].fY}, {a[3].fX, a[3].fY}};
|
|
|
|
Cubic dst;
|
2013-02-17 01:41:25 +00:00
|
|
|
int order = reduceOrder(aCubic, dst, kReduceOrder_QuadraticsAllowed, kReduceOrder_TreatAsFill);
|
2012-04-17 11:40:34 +00:00
|
|
|
for (int index = 0; index < order; ++index) {
|
|
|
|
a[index].fX = SkDoubleToScalar(dst[index].x);
|
|
|
|
a[index].fY = SkDoubleToScalar(dst[index].y);
|
|
|
|
}
|
|
|
|
if (order == 1) { // FIXME: allow returning points, caller should discard
|
|
|
|
a[1] = a[0];
|
|
|
|
return (SkPath::Verb) order;
|
|
|
|
}
|
|
|
|
return (SkPath::Verb) (order - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsCoincident(const SkPoint a[2], const SkPoint& above,
|
|
|
|
const SkPoint& below) {
|
|
|
|
const _Line aLine = {{a[0].fX, a[0].fY}, {a[1].fX, a[1].fY}};
|
|
|
|
const _Line bLine = {{above.fX, above.fY}, {below.fX, below.fY}};
|
|
|
|
return implicit_matches_ulps(aLine, bLine, 32);
|
|
|
|
}
|
|
|
|
|
2012-02-03 22:07:47 +00:00
|
|
|
/*
|
|
|
|
list of edges
|
|
|
|
bounds for edge
|
|
|
|
sort
|
|
|
|
active T
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
if a contour's bounds is outside of the active area, no need to create edges
|
2012-02-03 22:07:47 +00:00
|
|
|
*/
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
/* given one or more paths,
|
2012-02-03 22:07:47 +00:00
|
|
|
find the bounds of each contour, select the active contours
|
|
|
|
for each active contour, compute a set of edges
|
|
|
|
each edge corresponds to one or more lines and curves
|
|
|
|
leave edges unbroken as long as possible
|
|
|
|
when breaking edges, compute the t at the break but leave the control points alone
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void contourBounds(const SkPath& path, SkTDArray<SkRect>& boundsArray) {
|
|
|
|
SkPath::Iter iter(path, false);
|
|
|
|
SkPoint pts[4];
|
|
|
|
SkPath::Verb verb;
|
|
|
|
SkRect bounds;
|
|
|
|
bounds.setEmpty();
|
|
|
|
int count = 0;
|
|
|
|
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
|
|
|
|
switch (verb) {
|
|
|
|
case SkPath::kMove_Verb:
|
|
|
|
if (!bounds.isEmpty()) {
|
|
|
|
*boundsArray.append() = bounds;
|
|
|
|
}
|
|
|
|
bounds.set(pts[0].fX, pts[0].fY, pts[0].fX, pts[0].fY);
|
|
|
|
count = 0;
|
|
|
|
break;
|
2012-08-23 18:14:13 +00:00
|
|
|
case SkPath::kLine_Verb:
|
2012-02-03 22:07:47 +00:00
|
|
|
count = 1;
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
count = 2;
|
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
count = 3;
|
|
|
|
break;
|
|
|
|
case SkPath::kClose_Verb:
|
|
|
|
count = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkDEBUGFAIL("bad verb");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int i = 1; i <= count; ++i) {
|
|
|
|
bounds.growToInclude(pts[i].fX, pts[i].fY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-09 22:04:27 +00:00
|
|
|
static bool extendLine(const SkPoint line[2], const SkPoint& add) {
|
|
|
|
// FIXME: allow this to extend lines that have slopes that are nearly equal
|
|
|
|
SkScalar dx1 = line[1].fX - line[0].fX;
|
|
|
|
SkScalar dy1 = line[1].fY - line[0].fY;
|
|
|
|
SkScalar dx2 = add.fX - line[0].fX;
|
|
|
|
SkScalar dy2 = add.fY - line[0].fY;
|
|
|
|
return dx1 * dy2 == dx2 * dy1;
|
|
|
|
}
|
2012-02-07 22:10:51 +00:00
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
// OPTIMIZATION: this should point to a list of input data rather than duplicating
|
|
|
|
// the line data here. This would reduce the need to assemble the results.
|
2012-02-09 22:04:27 +00:00
|
|
|
struct OutEdge {
|
|
|
|
bool operator<(const OutEdge& rh) const {
|
2012-02-28 16:57:05 +00:00
|
|
|
const SkPoint& first = fPts[0];
|
|
|
|
const SkPoint& rhFirst = rh.fPts[0];
|
2012-02-09 22:04:27 +00:00
|
|
|
return first.fY == rhFirst.fY
|
|
|
|
? first.fX < rhFirst.fX
|
|
|
|
: first.fY < rhFirst.fY;
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-02-28 16:57:05 +00:00
|
|
|
SkPoint fPts[4];
|
2012-03-20 21:11:59 +00:00
|
|
|
int fID; // id of edge generating data
|
2012-02-28 16:57:05 +00:00
|
|
|
uint8_t fVerb; // FIXME: not read from everywhere
|
2012-03-20 21:11:59 +00:00
|
|
|
bool fCloseCall; // edge is trimmable if not originally coincident
|
2012-02-09 22:04:27 +00:00
|
|
|
};
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
class OutEdgeBuilder {
|
|
|
|
public:
|
2012-02-09 22:04:27 +00:00
|
|
|
OutEdgeBuilder(bool fill)
|
|
|
|
: fFill(fill) {
|
|
|
|
}
|
|
|
|
|
2012-03-28 16:20:21 +00:00
|
|
|
void addCurve(const SkPoint line[4], SkPath::Verb verb, int id,
|
|
|
|
bool closeCall) {
|
2012-02-20 21:33:22 +00:00
|
|
|
OutEdge& newEdge = fEdges.push_back();
|
2012-03-28 16:20:21 +00:00
|
|
|
memcpy(newEdge.fPts, line, (verb + 1) * sizeof(SkPoint));
|
|
|
|
newEdge.fVerb = verb;
|
2012-03-20 21:11:59 +00:00
|
|
|
newEdge.fID = id;
|
|
|
|
newEdge.fCloseCall = closeCall;
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
bool trimLine(SkScalar y, int id) {
|
|
|
|
size_t count = fEdges.count();
|
|
|
|
while (count-- != 0) {
|
|
|
|
OutEdge& edge = fEdges[count];
|
|
|
|
if (edge.fID != id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (edge.fCloseCall) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
SkASSERT(edge.fPts[0].fY <= y);
|
|
|
|
if (edge.fPts[1].fY <= y) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
edge.fPts[1].fX = edge.fPts[0].fX + (y - edge.fPts[0].fY)
|
|
|
|
* (edge.fPts[1].fX - edge.fPts[0].fX)
|
|
|
|
/ (edge.fPts[1].fY - edge.fPts[0].fY);
|
|
|
|
edge.fPts[1].fY = y;
|
2012-04-17 11:40:34 +00:00
|
|
|
#if DEBUG_TRIM_LINE
|
|
|
|
SkDebugf("%s edge=%d %1.9g,%1.9g\n", __FUNCTION__, id,
|
|
|
|
edge.fPts[1].fX, y);
|
|
|
|
#endif
|
2012-03-20 21:11:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void assemble(SkPath& simple) {
|
2012-02-15 22:01:16 +00:00
|
|
|
size_t listCount = fEdges.count();
|
|
|
|
if (listCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2012-02-09 22:04:27 +00:00
|
|
|
do {
|
2012-02-15 22:01:16 +00:00
|
|
|
size_t listIndex = 0;
|
|
|
|
int advance = 1;
|
|
|
|
while (listIndex < listCount && fTops[listIndex] == 0) {
|
|
|
|
++listIndex;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-02-15 22:01:16 +00:00
|
|
|
if (listIndex >= listCount) {
|
|
|
|
break;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-03-05 22:01:21 +00:00
|
|
|
int closeEdgeIndex = -listIndex - 1;
|
2012-04-10 18:28:55 +00:00
|
|
|
// the curve is deferred and not added right away because the
|
|
|
|
// following edge may extend the first curve.
|
2012-03-28 16:20:21 +00:00
|
|
|
SkPoint firstPt, lastCurve[4];
|
|
|
|
uint8_t lastVerb;
|
2012-04-10 18:28:55 +00:00
|
|
|
#if DEBUG_ASSEMBLE
|
|
|
|
int firstIndex, lastIndex;
|
|
|
|
const int tab = 8;
|
|
|
|
#endif
|
2012-02-15 22:01:16 +00:00
|
|
|
bool doMove = true;
|
|
|
|
int edgeIndex;
|
|
|
|
do {
|
2012-02-28 16:57:05 +00:00
|
|
|
SkPoint* ptArray = fEdges[listIndex].fPts;
|
|
|
|
uint8_t verb = fEdges[listIndex].fVerb;
|
2012-04-10 18:28:55 +00:00
|
|
|
SkPoint* curve[4];
|
2012-02-15 22:01:16 +00:00
|
|
|
if (advance < 0) {
|
2012-04-10 18:28:55 +00:00
|
|
|
curve[0] = &ptArray[verb];
|
|
|
|
if (verb == SkPath::kCubic_Verb) {
|
|
|
|
curve[1] = &ptArray[2];
|
|
|
|
curve[2] = &ptArray[1];
|
|
|
|
}
|
|
|
|
curve[verb] = &ptArray[0];
|
2012-02-15 22:01:16 +00:00
|
|
|
} else {
|
2012-04-10 18:28:55 +00:00
|
|
|
curve[0] = &ptArray[0];
|
|
|
|
if (verb == SkPath::kCubic_Verb) {
|
|
|
|
curve[1] = &ptArray[1];
|
|
|
|
curve[2] = &ptArray[2];
|
|
|
|
}
|
|
|
|
curve[verb] = &ptArray[verb];
|
|
|
|
}
|
|
|
|
if (verb == SkPath::kQuad_Verb) {
|
|
|
|
curve[1] = &ptArray[1];
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-03-28 16:20:21 +00:00
|
|
|
if (doMove) {
|
2012-04-10 18:28:55 +00:00
|
|
|
firstPt = *curve[0];
|
|
|
|
simple.moveTo(curve[0]->fX, curve[0]->fY);
|
|
|
|
#if DEBUG_ASSEMBLE
|
|
|
|
SkDebugf("%s %d moveTo (%g,%g)\n", __FUNCTION__,
|
|
|
|
listIndex + 1, curve[0]->fX, curve[0]->fY);
|
|
|
|
firstIndex = listIndex;
|
|
|
|
#endif
|
|
|
|
for (int index = 0; index <= verb; ++index) {
|
|
|
|
lastCurve[index] = *curve[index];
|
2012-03-28 16:20:21 +00:00
|
|
|
}
|
|
|
|
doMove = false;
|
|
|
|
} else {
|
2012-04-10 18:28:55 +00:00
|
|
|
bool gap = lastCurve[lastVerb] != *curve[0];
|
|
|
|
if (gap || lastVerb != SkPath::kLine_Verb) { // output the accumulated curve before the gap
|
2012-03-28 16:20:21 +00:00
|
|
|
// FIXME: see comment in bridge -- this probably
|
|
|
|
// conceals errors
|
2012-04-10 18:28:55 +00:00
|
|
|
SkASSERT(fFill && UlpsDiff(lastCurve[lastVerb].fY,
|
|
|
|
curve[0]->fY) <= 10);
|
2012-03-28 16:20:21 +00:00
|
|
|
switch (lastVerb) {
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
simple.lineTo(lastCurve[1].fX, lastCurve[1].fY);
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
simple.quadTo(lastCurve[1].fX, lastCurve[1].fY,
|
|
|
|
lastCurve[2].fX, lastCurve[2].fY);
|
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
simple.cubicTo(lastCurve[1].fX, lastCurve[1].fY,
|
|
|
|
lastCurve[2].fX, lastCurve[2].fY,
|
|
|
|
lastCurve[3].fX, lastCurve[3].fY);
|
|
|
|
break;
|
2012-02-28 16:57:05 +00:00
|
|
|
}
|
2012-04-10 18:28:55 +00:00
|
|
|
#if DEBUG_ASSEMBLE
|
|
|
|
SkDebugf("%*s %d %sTo (%g,%g)\n", tab, "", lastIndex + 1,
|
|
|
|
kLVerbStr[lastVerb], lastCurve[lastVerb].fX,
|
|
|
|
lastCurve[lastVerb].fY);
|
|
|
|
#endif
|
2012-03-28 16:20:21 +00:00
|
|
|
}
|
2012-04-10 18:28:55 +00:00
|
|
|
int firstCopy = 1;
|
2012-04-17 11:40:34 +00:00
|
|
|
if (gap || (lastVerb == SkPath::kLine_Verb
|
|
|
|
&& (verb != SkPath::kLine_Verb
|
|
|
|
|| !extendLine(lastCurve, *curve[verb])))) {
|
2012-03-28 16:20:21 +00:00
|
|
|
// FIXME: see comment in bridge -- this probably
|
|
|
|
// conceals errors
|
2012-04-10 18:28:55 +00:00
|
|
|
SkASSERT(lastCurve[lastVerb] == *curve[0] ||
|
|
|
|
(fFill && UlpsDiff(lastCurve[lastVerb].fY,
|
|
|
|
curve[0]->fY) <= 10));
|
|
|
|
simple.lineTo(curve[0]->fX, curve[0]->fY);
|
|
|
|
#if DEBUG_ASSEMBLE
|
|
|
|
SkDebugf("%*s %d gap lineTo (%g,%g)\n", tab, "",
|
|
|
|
lastIndex + 1, curve[0]->fX, curve[0]->fY);
|
|
|
|
#endif
|
|
|
|
firstCopy = 0;
|
|
|
|
} else if (lastVerb != SkPath::kLine_Verb) {
|
|
|
|
firstCopy = 0;
|
2012-03-28 16:20:21 +00:00
|
|
|
}
|
2012-04-10 18:28:55 +00:00
|
|
|
for (int index = firstCopy; index <= verb; ++index) {
|
|
|
|
lastCurve[index] = *curve[index];
|
2012-03-28 16:20:21 +00:00
|
|
|
}
|
2012-02-15 22:01:16 +00:00
|
|
|
}
|
2012-04-10 18:28:55 +00:00
|
|
|
lastVerb = verb;
|
|
|
|
#if DEBUG_ASSEMBLE
|
|
|
|
lastIndex = listIndex;
|
|
|
|
#endif
|
2012-02-15 22:01:16 +00:00
|
|
|
if (advance < 0) {
|
|
|
|
edgeIndex = fTops[listIndex];
|
|
|
|
fTops[listIndex] = 0;
|
2012-04-10 18:28:55 +00:00
|
|
|
} else {
|
2012-02-15 22:01:16 +00:00
|
|
|
edgeIndex = fBottoms[listIndex];
|
|
|
|
fBottoms[listIndex] = 0;
|
|
|
|
}
|
2012-03-05 22:01:21 +00:00
|
|
|
if (edgeIndex) {
|
|
|
|
listIndex = abs(edgeIndex) - 1;
|
|
|
|
if (edgeIndex < 0) {
|
|
|
|
fTops[listIndex] = 0;
|
|
|
|
} else {
|
|
|
|
fBottoms[listIndex] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (edgeIndex == closeEdgeIndex || edgeIndex == 0) {
|
2012-04-10 18:28:55 +00:00
|
|
|
switch (lastVerb) {
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
simple.lineTo(lastCurve[1].fX, lastCurve[1].fY);
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
simple.quadTo(lastCurve[1].fX, lastCurve[1].fY,
|
|
|
|
lastCurve[2].fX, lastCurve[2].fY);
|
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
simple.cubicTo(lastCurve[1].fX, lastCurve[1].fY,
|
|
|
|
lastCurve[2].fX, lastCurve[2].fY,
|
|
|
|
lastCurve[3].fX, lastCurve[3].fY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#if DEBUG_ASSEMBLE
|
|
|
|
SkDebugf("%*s %d %sTo last (%g, %g)\n", tab, "",
|
|
|
|
lastIndex + 1, kLVerbStr[lastVerb],
|
|
|
|
lastCurve[lastVerb].fX, lastCurve[lastVerb].fY);
|
|
|
|
#endif
|
2012-03-28 16:20:21 +00:00
|
|
|
if (lastCurve[lastVerb] != firstPt) {
|
2012-04-10 18:28:55 +00:00
|
|
|
simple.lineTo(firstPt.fX, firstPt.fY);
|
|
|
|
#if DEBUG_ASSEMBLE
|
|
|
|
SkDebugf("%*s %d final line (%g, %g)\n", tab, "",
|
|
|
|
firstIndex + 1, firstPt.fX, firstPt.fY);
|
|
|
|
#endif
|
2012-03-05 22:01:21 +00:00
|
|
|
}
|
2012-02-28 16:57:05 +00:00
|
|
|
simple.close();
|
2012-04-10 18:28:55 +00:00
|
|
|
#if DEBUG_ASSEMBLE
|
|
|
|
SkDebugf("%*s close\n", tab, "");
|
|
|
|
#endif
|
2012-02-28 16:57:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-04-10 18:28:55 +00:00
|
|
|
// if this and next edge go different directions
|
|
|
|
#if DEBUG_ASSEMBLE
|
|
|
|
SkDebugf("%*s advance=%d edgeIndex=%d flip=%s\n", tab, "",
|
|
|
|
advance, edgeIndex, advance > 0 ^ edgeIndex < 0 ?
|
|
|
|
"true" : "false");
|
|
|
|
#endif
|
2012-02-15 22:01:16 +00:00
|
|
|
if (advance > 0 ^ edgeIndex < 0) {
|
|
|
|
advance = -advance;
|
|
|
|
}
|
2012-03-05 22:01:21 +00:00
|
|
|
} while (edgeIndex);
|
2012-02-15 22:01:16 +00:00
|
|
|
} while (true);
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-02-28 16:57:05 +00:00
|
|
|
// sort points by y, then x
|
|
|
|
// if x/y is identical, sort bottoms before tops
|
|
|
|
// if identical and both tops/bottoms, sort by angle
|
|
|
|
static bool lessThan(SkTArray<OutEdge>& edges, const int one,
|
|
|
|
const int two) {
|
|
|
|
const OutEdge& oneEdge = edges[abs(one) - 1];
|
|
|
|
int oneIndex = one < 0 ? 0 : oneEdge.fVerb;
|
|
|
|
const SkPoint& startPt1 = oneEdge.fPts[oneIndex];
|
|
|
|
const OutEdge& twoEdge = edges[abs(two) - 1];
|
|
|
|
int twoIndex = two < 0 ? 0 : twoEdge.fVerb;
|
|
|
|
const SkPoint& startPt2 = twoEdge.fPts[twoIndex];
|
|
|
|
if (startPt1.fY != startPt2.fY) {
|
2012-03-20 21:11:59 +00:00
|
|
|
#if DEBUG_OUT_LESS_THAN
|
|
|
|
SkDebugf("%s %d<%d (%g,%g) %s startPt1.fY < startPt2.fY\n", __FUNCTION__,
|
|
|
|
one, two, startPt1.fY, startPt2.fY,
|
|
|
|
startPt1.fY < startPt2.fY ? "true" : "false");
|
|
|
|
#endif
|
2012-02-28 16:57:05 +00:00
|
|
|
return startPt1.fY < startPt2.fY;
|
|
|
|
}
|
|
|
|
if (startPt1.fX != startPt2.fX) {
|
2012-03-20 21:11:59 +00:00
|
|
|
#if DEBUG_OUT_LESS_THAN
|
|
|
|
SkDebugf("%s %d<%d (%g,%g) %s startPt1.fX < startPt2.fX\n", __FUNCTION__,
|
|
|
|
one, two, startPt1.fX, startPt2.fX,
|
|
|
|
startPt1.fX < startPt2.fX ? "true" : "false");
|
|
|
|
#endif
|
2012-02-28 16:57:05 +00:00
|
|
|
return startPt1.fX < startPt2.fX;
|
|
|
|
}
|
|
|
|
const SkPoint& endPt1 = oneEdge.fPts[oneIndex ^ oneEdge.fVerb];
|
|
|
|
const SkPoint& endPt2 = twoEdge.fPts[twoIndex ^ twoEdge.fVerb];
|
|
|
|
SkScalar dy1 = startPt1.fY - endPt1.fY;
|
|
|
|
SkScalar dy2 = startPt2.fY - endPt2.fY;
|
|
|
|
SkScalar dy1y2 = dy1 * dy2;
|
|
|
|
if (dy1y2 < 0) { // different signs
|
2012-03-20 21:11:59 +00:00
|
|
|
#if DEBUG_OUT_LESS_THAN
|
2012-02-28 16:57:05 +00:00
|
|
|
SkDebugf("%s %d<%d %s dy1 > 0\n", __FUNCTION__, one, two,
|
|
|
|
dy1 > 0 ? "true" : "false");
|
2012-03-20 21:11:59 +00:00
|
|
|
#endif
|
2012-02-28 16:57:05 +00:00
|
|
|
return dy1 > 0; // one < two if one goes up and two goes down
|
|
|
|
}
|
|
|
|
if (dy1y2 == 0) {
|
2012-03-20 21:11:59 +00:00
|
|
|
#if DEBUG_OUT_LESS_THAN
|
|
|
|
SkDebugf("%s %d<%d %s endPt1.fX < endPt2.fX\n", __FUNCTION__,
|
|
|
|
one, two, endPt1.fX < endPt2.fX ? "true" : "false");
|
|
|
|
#endif
|
2012-02-28 16:57:05 +00:00
|
|
|
return endPt1.fX < endPt2.fX;
|
2012-08-23 18:14:13 +00:00
|
|
|
}
|
2012-02-28 16:57:05 +00:00
|
|
|
SkScalar dx1y2 = (startPt1.fX - endPt1.fX) * dy2;
|
|
|
|
SkScalar dx2y1 = (startPt2.fX - endPt2.fX) * dy1;
|
2012-03-20 21:11:59 +00:00
|
|
|
#if DEBUG_OUT_LESS_THAN
|
|
|
|
SkDebugf("%s %d<%d %s dy2 < 0 ^ dx1y2 < dx2y1\n", __FUNCTION__,
|
|
|
|
one, two, dy2 < 0 ^ dx1y2 < dx2y1 ? "true" : "false");
|
|
|
|
#endif
|
2012-02-28 16:57:05 +00:00
|
|
|
return dy2 > 0 ^ dx1y2 < dx2y1;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 22:01:16 +00:00
|
|
|
// Sort the indices of paired points and then create more indices so
|
|
|
|
// assemble() can find the next edge and connect the top or bottom
|
2012-02-09 22:04:27 +00:00
|
|
|
void bridge() {
|
|
|
|
size_t index;
|
|
|
|
size_t count = fEdges.count();
|
|
|
|
if (!count) {
|
|
|
|
return;
|
|
|
|
}
|
2012-02-28 16:57:05 +00:00
|
|
|
SkASSERT(!fFill || count > 1);
|
2012-02-09 22:04:27 +00:00
|
|
|
fTops.setCount(count);
|
|
|
|
sk_bzero(fTops.begin(), sizeof(fTops[0]) * count);
|
|
|
|
fBottoms.setCount(count);
|
|
|
|
sk_bzero(fBottoms.begin(), sizeof(fBottoms[0]) * count);
|
2012-02-15 22:01:16 +00:00
|
|
|
SkTDArray<int> order;
|
|
|
|
for (index = 1; index <= count; ++index) {
|
|
|
|
*order.append() = -index;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-02-28 16:57:05 +00:00
|
|
|
for (index = 1; index <= count; ++index) {
|
|
|
|
*order.append() = index;
|
|
|
|
}
|
|
|
|
QSort<SkTArray<OutEdge>, int>(fEdges, order.begin(), order.end() - 1, lessThan);
|
2012-02-15 22:01:16 +00:00
|
|
|
int* lastPtr = order.end() - 1;
|
|
|
|
int* leftPtr = order.begin();
|
|
|
|
while (leftPtr < lastPtr) {
|
|
|
|
int leftIndex = *leftPtr;
|
|
|
|
int leftOutIndex = abs(leftIndex) - 1;
|
|
|
|
const OutEdge& left = fEdges[leftOutIndex];
|
2012-02-09 22:04:27 +00:00
|
|
|
int* rightPtr = leftPtr + 1;
|
2012-02-15 22:01:16 +00:00
|
|
|
int rightIndex = *rightPtr;
|
|
|
|
int rightOutIndex = abs(rightIndex) - 1;
|
|
|
|
const OutEdge& right = fEdges[rightOutIndex];
|
2012-02-28 16:57:05 +00:00
|
|
|
bool pairUp = fFill;
|
|
|
|
if (!pairUp) {
|
|
|
|
const SkPoint& leftMatch =
|
|
|
|
left.fPts[leftIndex < 0 ? 0 : left.fVerb];
|
|
|
|
const SkPoint& rightMatch =
|
|
|
|
right.fPts[rightIndex < 0 ? 0 : right.fVerb];
|
|
|
|
pairUp = leftMatch == rightMatch;
|
|
|
|
} else {
|
2012-03-20 21:11:59 +00:00
|
|
|
#if DEBUG_OUT
|
2012-03-27 13:23:51 +00:00
|
|
|
// FIXME : not happy that error in low bit is allowed
|
|
|
|
// this probably conceals error elsewhere
|
|
|
|
if (UlpsDiff(left.fPts[leftIndex < 0 ? 0 : left.fVerb].fY,
|
|
|
|
right.fPts[rightIndex < 0 ? 0 : right.fVerb].fY) > 1) {
|
2012-03-20 21:11:59 +00:00
|
|
|
*fMismatches.append() = leftIndex;
|
|
|
|
if (rightPtr == lastPtr) {
|
|
|
|
*fMismatches.append() = rightIndex;
|
|
|
|
}
|
|
|
|
pairUp = false;
|
|
|
|
}
|
|
|
|
#else
|
2012-03-27 13:23:51 +00:00
|
|
|
SkASSERT(UlpsDiff(left.fPts[leftIndex < 0 ? 0 : left.fVerb].fY,
|
|
|
|
right.fPts[rightIndex < 0 ? 0 : right.fVerb].fY) <= 10);
|
2012-03-20 21:11:59 +00:00
|
|
|
#endif
|
2012-02-28 16:57:05 +00:00
|
|
|
}
|
|
|
|
if (pairUp) {
|
2012-02-15 22:01:16 +00:00
|
|
|
if (leftIndex < 0) {
|
|
|
|
fTops[leftOutIndex] = rightIndex;
|
|
|
|
} else {
|
|
|
|
fBottoms[leftOutIndex] = rightIndex;
|
|
|
|
}
|
|
|
|
if (rightIndex < 0) {
|
|
|
|
fTops[rightOutIndex] = leftIndex;
|
|
|
|
} else {
|
|
|
|
fBottoms[rightOutIndex] = leftIndex;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-02-15 22:01:16 +00:00
|
|
|
++rightPtr;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
|
|
|
leftPtr = rightPtr;
|
2012-02-07 22:10:51 +00:00
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
#if DEBUG_OUT
|
|
|
|
int* mismatch = fMismatches.begin();
|
|
|
|
while (mismatch != fMismatches.end()) {
|
|
|
|
int leftIndex = *mismatch++;
|
|
|
|
int leftOutIndex = abs(leftIndex) - 1;
|
|
|
|
const OutEdge& left = fEdges[leftOutIndex];
|
|
|
|
const SkPoint& leftPt = left.fPts[leftIndex < 0 ? 0 : left.fVerb];
|
|
|
|
SkDebugf("%s left=%d %s (%1.9g,%1.9g)\n",
|
|
|
|
__FUNCTION__, left.fID, leftIndex < 0 ? "top" : "bot",
|
|
|
|
leftPt.fX, leftPt.fY);
|
|
|
|
}
|
|
|
|
SkASSERT(fMismatches.count() == 0);
|
2012-04-10 18:28:55 +00:00
|
|
|
#endif
|
|
|
|
#if DEBUG_BRIDGE
|
|
|
|
for (index = 0; index < count; ++index) {
|
|
|
|
const OutEdge& edge = fEdges[index];
|
|
|
|
uint8_t verb = edge.fVerb;
|
2012-08-23 18:14:13 +00:00
|
|
|
SkDebugf("%s %d edge=%d %s (%1.9g,%1.9g) (%1.9g,%1.9g)\n",
|
2012-04-10 18:28:55 +00:00
|
|
|
index == 0 ? __FUNCTION__ : " ",
|
|
|
|
index + 1, edge.fID, kLVerbStr[verb], edge.fPts[0].fX,
|
|
|
|
edge.fPts[0].fY, edge.fPts[verb].fX, edge.fPts[verb].fY);
|
|
|
|
}
|
|
|
|
for (index = 0; index < count; ++index) {
|
|
|
|
SkDebugf(" top of % 2d connects to %s of % 2d\n", index + 1,
|
|
|
|
fTops[index] < 0 ? "top " : "bottom", abs(fTops[index]));
|
|
|
|
SkDebugf(" bottom of % 2d connects to %s of % 2d\n", index + 1,
|
|
|
|
fBottoms[index] < 0 ? "top " : "bottom", abs(fBottoms[index]));
|
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
#endif
|
2012-02-07 22:10:51 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 22:01:16 +00:00
|
|
|
protected:
|
2012-02-07 22:10:51 +00:00
|
|
|
SkTArray<OutEdge> fEdges;
|
2012-02-15 22:01:16 +00:00
|
|
|
SkTDArray<int> fTops;
|
|
|
|
SkTDArray<int> fBottoms;
|
2012-02-09 22:04:27 +00:00
|
|
|
bool fFill;
|
2012-03-20 21:11:59 +00:00
|
|
|
#if DEBUG_OUT
|
|
|
|
SkTDArray<int> fMismatches;
|
|
|
|
#endif
|
2012-02-07 22:10:51 +00:00
|
|
|
};
|
|
|
|
|
2012-02-03 22:07:47 +00:00
|
|
|
// Bounds, unlike Rect, does not consider a vertical line to be empty.
|
|
|
|
struct Bounds : public SkRect {
|
|
|
|
static bool Intersects(const Bounds& a, const Bounds& b) {
|
|
|
|
return a.fLeft <= b.fRight && b.fLeft <= a.fRight &&
|
|
|
|
a.fTop <= b.fBottom && b.fTop <= a.fBottom;
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-02-15 22:01:16 +00:00
|
|
|
bool isEmpty() {
|
|
|
|
return fLeft > fRight || fTop > fBottom
|
2012-12-10 12:50:53 +00:00
|
|
|
|| (fLeft == fRight && fTop == fBottom)
|
2012-02-15 22:01:16 +00:00
|
|
|
|| isnan(fLeft) || isnan(fRight)
|
|
|
|
|| isnan(fTop) || isnan(fBottom);
|
|
|
|
}
|
2012-02-03 22:07:47 +00:00
|
|
|
};
|
|
|
|
|
2012-03-05 22:01:21 +00:00
|
|
|
class Intercepts {
|
|
|
|
public:
|
|
|
|
Intercepts()
|
|
|
|
: fTopIntercepts(0)
|
2012-03-30 18:47:02 +00:00
|
|
|
, fBottomIntercepts(0)
|
|
|
|
, fExplicit(false) {
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-03-30 18:47:02 +00:00
|
|
|
Intercepts& operator=(const Intercepts& src) {
|
|
|
|
fTs = src.fTs;
|
|
|
|
fTopIntercepts = src.fTopIntercepts;
|
|
|
|
fBottomIntercepts = src.fBottomIntercepts;
|
2012-05-18 20:50:33 +00:00
|
|
|
return *this;
|
2012-03-30 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OPTIMIZATION: remove this function if it's never called
|
|
|
|
double t(int tIndex) const {
|
|
|
|
if (tIndex == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (tIndex > fTs.count()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return fTs[tIndex - 1];
|
2012-03-05 22:01:21 +00:00
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
#if DEBUG_DUMP
|
2012-03-28 16:20:21 +00:00
|
|
|
void dump(const SkPoint* pts, SkPath::Verb verb) {
|
2012-03-20 21:11:59 +00:00
|
|
|
const char className[] = "Intercepts";
|
|
|
|
const int tab = 8;
|
|
|
|
for (int i = 0; i < fTs.count(); ++i) {
|
|
|
|
SkPoint out;
|
2012-03-28 16:20:21 +00:00
|
|
|
switch (verb) {
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
LineXYAtT(pts, fTs[i], &out);
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
QuadXYAtT(pts, fTs[i], &out);
|
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
CubicXYAtT(pts, fTs[i], &out);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
SkDebugf("%*s.fTs[%d]=%1.9g (%1.9g,%1.9g)\n", tab + sizeof(className),
|
2012-03-20 21:11:59 +00:00
|
|
|
className, i, fTs[i], out.fX, out.fY);
|
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
SkDebugf("%*s.fTopIntercepts=%u\n", tab + sizeof(className),
|
2012-03-20 21:11:59 +00:00
|
|
|
className, fTopIntercepts);
|
2012-03-30 18:47:02 +00:00
|
|
|
SkDebugf("%*s.fBottomIntercepts=%u\n", tab + sizeof(className),
|
2012-03-20 21:11:59 +00:00
|
|
|
className, fBottomIntercepts);
|
2012-04-10 18:28:55 +00:00
|
|
|
SkDebugf("%*s.fExplicit=%d\n", tab + sizeof(className),
|
|
|
|
className, fExplicit);
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-03 22:07:47 +00:00
|
|
|
SkTDArray<double> fTs;
|
2012-03-30 18:47:02 +00:00
|
|
|
unsigned char fTopIntercepts; // 0=init state 1=1 edge >1=multiple edges
|
|
|
|
unsigned char fBottomIntercepts;
|
|
|
|
bool fExplicit; // if set, suppress 0 and 1
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-02-03 22:07:47 +00:00
|
|
|
};
|
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
struct HorizontalEdge {
|
|
|
|
bool operator<(const HorizontalEdge& rh) const {
|
|
|
|
return fY == rh.fY ? fLeft == rh.fLeft ? fRight < rh.fRight
|
|
|
|
: fLeft < rh.fLeft : fY < rh.fY;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_DUMP
|
|
|
|
void dump() {
|
|
|
|
const char className[] = "HorizontalEdge";
|
|
|
|
const int tab = 4;
|
2012-03-22 21:11:17 +00:00
|
|
|
SkDebugf("%*s.fLeft=%1.9g\n", tab + sizeof(className), className, fLeft);
|
|
|
|
SkDebugf("%*s.fRight=%1.9g\n", tab + sizeof(className), className, fRight);
|
|
|
|
SkDebugf("%*s.fY=%1.9g\n", tab + sizeof(className), className, fY);
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SkScalar fLeft;
|
|
|
|
SkScalar fRight;
|
|
|
|
SkScalar fY;
|
|
|
|
};
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
struct InEdge {
|
|
|
|
bool operator<(const InEdge& rh) const {
|
2012-02-03 22:07:47 +00:00
|
|
|
return fBounds.fTop == rh.fBounds.fTop
|
|
|
|
? fBounds.fLeft < rh.fBounds.fLeft
|
|
|
|
: fBounds.fTop < rh.fBounds.fTop;
|
|
|
|
}
|
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
// Avoid collapsing t values that are close to the same since
|
|
|
|
// we walk ts to describe consecutive intersections. Since a pair of ts can
|
|
|
|
// be nearly equal, any problems caused by this should be taken care
|
2012-08-23 18:14:13 +00:00
|
|
|
// of later.
|
2012-03-20 21:11:59 +00:00
|
|
|
int add(double* ts, size_t count, ptrdiff_t verbIndex) {
|
2012-02-03 22:07:47 +00:00
|
|
|
// FIXME: in the pathological case where there is a ton of intercepts, binary search?
|
2012-02-15 22:01:16 +00:00
|
|
|
bool foundIntercept = false;
|
2012-03-20 21:11:59 +00:00
|
|
|
int insertedAt = -1;
|
2012-02-15 22:01:16 +00:00
|
|
|
Intercepts& intercepts = fIntercepts[verbIndex];
|
2012-02-03 22:07:47 +00:00
|
|
|
for (size_t index = 0; index < count; ++index) {
|
|
|
|
double t = ts[index];
|
2012-03-05 22:01:21 +00:00
|
|
|
if (t <= 0) {
|
2012-03-30 18:47:02 +00:00
|
|
|
intercepts.fTopIntercepts <<= 1;
|
2012-03-05 22:01:21 +00:00
|
|
|
fContainsIntercepts |= ++intercepts.fTopIntercepts > 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (t >= 1) {
|
2012-03-30 18:47:02 +00:00
|
|
|
intercepts.fBottomIntercepts <<= 1;
|
2012-03-05 22:01:21 +00:00
|
|
|
fContainsIntercepts |= ++intercepts.fBottomIntercepts > 1;
|
2012-02-15 22:01:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
fIntersected = true;
|
2012-02-15 22:01:16 +00:00
|
|
|
foundIntercept = true;
|
2012-02-03 22:07:47 +00:00
|
|
|
size_t tCount = intercepts.fTs.count();
|
2012-03-20 21:11:59 +00:00
|
|
|
double delta;
|
2012-02-03 22:07:47 +00:00
|
|
|
for (size_t idx2 = 0; idx2 < tCount; ++idx2) {
|
|
|
|
if (t <= intercepts.fTs[idx2]) {
|
2012-03-20 21:11:59 +00:00
|
|
|
// FIXME: ? if (t < intercepts.fTs[idx2]) // failed
|
|
|
|
delta = intercepts.fTs[idx2] - t;
|
2012-03-01 19:16:31 +00:00
|
|
|
if (delta > 0) {
|
2012-03-20 21:11:59 +00:00
|
|
|
insertedAt = idx2;
|
2012-02-03 22:07:47 +00:00
|
|
|
*intercepts.fTs.insert(idx2) = t;
|
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
goto nextPt;
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
if (tCount == 0 || (delta = t - intercepts.fTs[tCount - 1]) > 0) {
|
|
|
|
insertedAt = tCount;
|
2012-02-03 22:07:47 +00:00
|
|
|
*intercepts.fTs.append() = t;
|
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
nextPt:
|
|
|
|
;
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
2012-03-05 22:01:21 +00:00
|
|
|
fContainsIntercepts |= foundIntercept;
|
2012-03-20 21:11:59 +00:00
|
|
|
return insertedAt;
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-04-10 18:28:55 +00:00
|
|
|
void addPartial(SkTArray<InEdge>& edges, int ptStart, int ptEnd,
|
2012-03-30 18:47:02 +00:00
|
|
|
int verbStart, int verbEnd) {
|
|
|
|
InEdge* edge = edges.push_back_n(1);
|
|
|
|
int verbCount = verbEnd - verbStart;
|
|
|
|
edge->fIntercepts.push_back_n(verbCount);
|
2012-06-01 17:44:28 +00:00
|
|
|
// uint8_t* verbs = &fVerbs[verbStart];
|
2012-03-30 18:47:02 +00:00
|
|
|
for (int ceptIdx = 0; ceptIdx < verbCount; ++ceptIdx) {
|
|
|
|
edge->fIntercepts[ceptIdx] = fIntercepts[verbStart + ceptIdx];
|
|
|
|
}
|
|
|
|
edge->fPts.append(ptEnd - ptStart, &fPts[ptStart]);
|
|
|
|
edge->fVerbs.append(verbCount, &fVerbs[verbStart]);
|
|
|
|
edge->setBounds();
|
|
|
|
edge->fWinding = fWinding;
|
|
|
|
edge->fContainsIntercepts = fContainsIntercepts; // FIXME: may not be correct -- but do we need to know?
|
|
|
|
}
|
|
|
|
|
2012-04-10 18:28:55 +00:00
|
|
|
void addSplit(SkTArray<InEdge>& edges, SkPoint* pts, uint8_t verb,
|
|
|
|
Intercepts& intercepts, int firstT, int lastT, bool flipped) {
|
2012-03-30 18:47:02 +00:00
|
|
|
InEdge* edge = edges.push_back_n(1);
|
|
|
|
edge->fIntercepts.push_back_n(1);
|
2012-04-10 18:28:55 +00:00
|
|
|
if (firstT == 0) {
|
|
|
|
*edge->fIntercepts[0].fTs.append() = 0;
|
|
|
|
} else {
|
|
|
|
*edge->fIntercepts[0].fTs.append() = intercepts.fTs[firstT - 1];
|
|
|
|
}
|
|
|
|
bool add1 = lastT == intercepts.fTs.count();
|
|
|
|
edge->fIntercepts[0].fTs.append(lastT - firstT, &intercepts.fTs[firstT]);
|
|
|
|
if (add1) {
|
|
|
|
*edge->fIntercepts[0].fTs.append() = 1;
|
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
edge->fIntercepts[0].fExplicit = true;
|
2012-04-10 18:28:55 +00:00
|
|
|
edge->fPts.append(verb + 1, pts);
|
2012-03-30 18:47:02 +00:00
|
|
|
edge->fVerbs.append(1, &verb);
|
2012-04-10 18:28:55 +00:00
|
|
|
// FIXME: bounds could be better for partial Ts
|
|
|
|
edge->setSubBounds();
|
2012-03-30 18:47:02 +00:00
|
|
|
edge->fContainsIntercepts = fContainsIntercepts; // FIXME: may not be correct -- but do we need to know?
|
|
|
|
if (flipped) {
|
2012-04-10 18:28:55 +00:00
|
|
|
edge->flipTs();
|
|
|
|
edge->fWinding = -fWinding;
|
|
|
|
} else {
|
|
|
|
edge->fWinding = fWinding;
|
2012-03-30 18:47:02 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-03 22:07:47 +00:00
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
bool cached(const InEdge* edge) {
|
2012-02-03 22:07:47 +00:00
|
|
|
// FIXME: in the pathological case where there is a ton of edges, binary search?
|
|
|
|
size_t count = fCached.count();
|
|
|
|
for (size_t index = 0; index < count; ++index) {
|
|
|
|
if (edge == fCached[index]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (edge < fCached[index]) {
|
|
|
|
*fCached.insert(index) = edge;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*fCached.append() = edge;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-10 18:28:55 +00:00
|
|
|
void complete(signed char winding) {
|
2012-03-30 18:47:02 +00:00
|
|
|
setBounds();
|
|
|
|
fIntercepts.push_back_n(fVerbs.count());
|
|
|
|
if ((fWinding = winding) < 0) { // reverse verbs, pts, if bottom to top
|
|
|
|
flip();
|
|
|
|
}
|
|
|
|
fContainsIntercepts = fIntersected = false;
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-04-10 18:28:55 +00:00
|
|
|
void flip() {
|
2012-03-30 18:47:02 +00:00
|
|
|
size_t index;
|
|
|
|
size_t last = fPts.count() - 1;
|
|
|
|
for (index = 0; index < last; ++index, --last) {
|
|
|
|
SkTSwap<SkPoint>(fPts[index], fPts[last]);
|
|
|
|
}
|
|
|
|
last = fVerbs.count() - 1;
|
|
|
|
for (index = 0; index < last; ++index, --last) {
|
|
|
|
SkTSwap<uint8_t>(fVerbs[index], fVerbs[last]);
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-04-10 18:28:55 +00:00
|
|
|
void flipTs() {
|
|
|
|
SkASSERT(fIntercepts.count() == 1);
|
|
|
|
Intercepts& intercepts = fIntercepts[0];
|
|
|
|
SkASSERT(intercepts.fExplicit);
|
|
|
|
SkTDArray<double>& ts = intercepts.fTs;
|
|
|
|
size_t index;
|
|
|
|
size_t last = ts.count() - 1;
|
|
|
|
for (index = 0; index < last; ++index, --last) {
|
|
|
|
SkTSwap<double>(ts[index], ts[last]);
|
|
|
|
}
|
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
|
|
|
|
void reset() {
|
|
|
|
fCached.reset();
|
|
|
|
fIntercepts.reset();
|
|
|
|
fPts.reset();
|
|
|
|
fVerbs.reset();
|
|
|
|
fBounds.set(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, SK_ScalarMax);
|
|
|
|
fWinding = 0;
|
|
|
|
fContainsIntercepts = false;
|
|
|
|
fIntersected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBounds() {
|
2012-02-03 22:07:47 +00:00
|
|
|
SkPoint* ptPtr = fPts.begin();
|
|
|
|
SkPoint* ptLast = fPts.end();
|
|
|
|
if (ptPtr == ptLast) {
|
2012-03-30 18:47:02 +00:00
|
|
|
SkDebugf("%s empty edge\n", __FUNCTION__);
|
2012-02-03 22:07:47 +00:00
|
|
|
SkASSERT(0);
|
|
|
|
// FIXME: delete empty edge?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fBounds.set(ptPtr->fX, ptPtr->fY, ptPtr->fX, ptPtr->fY);
|
|
|
|
++ptPtr;
|
|
|
|
while (ptPtr != ptLast) {
|
|
|
|
fBounds.growToInclude(ptPtr->fX, ptPtr->fY);
|
|
|
|
++ptPtr;
|
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-04-10 18:28:55 +00:00
|
|
|
// recompute bounds based on subrange of T values
|
|
|
|
void setSubBounds() {
|
|
|
|
SkASSERT(fIntercepts.count() == 1);
|
|
|
|
Intercepts& intercepts = fIntercepts[0];
|
|
|
|
SkASSERT(intercepts.fExplicit);
|
|
|
|
SkASSERT(fVerbs.count() == 1);
|
|
|
|
SkTDArray<double>& ts = intercepts.fTs;
|
|
|
|
if (fVerbs[0] == SkPath::kQuad_Verb) {
|
|
|
|
SkASSERT(fPts.count() == 3);
|
|
|
|
QuadSubBounds(fPts.begin(), ts[0], ts[ts.count() - 1], fBounds);
|
|
|
|
} else {
|
|
|
|
SkASSERT(fVerbs[0] == SkPath::kCubic_Verb);
|
|
|
|
SkASSERT(fPts.count() == 4);
|
|
|
|
CubicSubBounds(fPts.begin(), ts[0], ts[ts.count() - 1], fBounds);
|
|
|
|
}
|
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
|
2012-04-10 18:28:55 +00:00
|
|
|
void splitInflectionPts(SkTArray<InEdge>& edges) {
|
2012-03-30 18:47:02 +00:00
|
|
|
if (!fIntersected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t* verbs = fVerbs.begin();
|
|
|
|
SkPoint* pts = fPts.begin();
|
|
|
|
int lastVerb = 0;
|
|
|
|
int lastPt = 0;
|
|
|
|
uint8_t verb;
|
|
|
|
bool edgeSplit = false;
|
|
|
|
for (int ceptIdx = 0; ceptIdx < fIntercepts.count(); ++ceptIdx, pts += verb) {
|
|
|
|
Intercepts& intercepts = fIntercepts[ceptIdx];
|
|
|
|
verb = *verbs++;
|
|
|
|
if (verb <= SkPath::kLine_Verb) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
size_t tCount = intercepts.fTs.count();
|
|
|
|
if (!tCount) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-06-01 17:44:28 +00:00
|
|
|
size_t tIndex = (size_t) -1;
|
2012-03-30 18:47:02 +00:00
|
|
|
SkScalar y = pts[0].fY;
|
|
|
|
int lastSplit = 0;
|
|
|
|
int firstSplit = -1;
|
|
|
|
bool curveSplit = false;
|
|
|
|
while (++tIndex < tCount) {
|
|
|
|
double nextT = intercepts.fTs[tIndex];
|
|
|
|
SkScalar nextY = verb == SkPath::kQuad_Verb
|
|
|
|
? QuadYAtT(pts, nextT) : CubicYAtT(pts, nextT);
|
|
|
|
if (nextY < y) {
|
|
|
|
edgeSplit = curveSplit = true;
|
|
|
|
if (firstSplit < 0) {
|
|
|
|
firstSplit = tIndex;
|
|
|
|
int nextPt = pts - fPts.begin();
|
|
|
|
int nextVerb = verbs - 1 - fVerbs.begin();
|
|
|
|
if (lastVerb < nextVerb) {
|
2012-04-10 18:28:55 +00:00
|
|
|
addPartial(edges, lastPt, nextPt, lastVerb, nextVerb);
|
2012-03-30 18:47:02 +00:00
|
|
|
#if DEBUG_SPLIT
|
2012-04-10 18:28:55 +00:00
|
|
|
SkDebugf("%s addPartial 1\n", __FUNCTION__);
|
2012-03-30 18:47:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
lastPt = nextPt;
|
|
|
|
lastVerb = nextVerb;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (firstSplit >= 0) {
|
|
|
|
if (lastSplit < firstSplit) {
|
2012-04-10 18:28:55 +00:00
|
|
|
addSplit(edges, pts, verb, intercepts,
|
|
|
|
lastSplit, firstSplit, false);
|
2012-03-30 18:47:02 +00:00
|
|
|
#if DEBUG_SPLIT
|
2012-04-10 18:28:55 +00:00
|
|
|
SkDebugf("%s addSplit 1 tIndex=%d,%d\n",
|
|
|
|
__FUNCTION__, lastSplit, firstSplit);
|
2012-03-30 18:47:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
addSplit(edges, pts, verb, intercepts,
|
2012-04-10 18:28:55 +00:00
|
|
|
firstSplit, tIndex, true);
|
2012-03-30 18:47:02 +00:00
|
|
|
#if DEBUG_SPLIT
|
2012-04-10 18:28:55 +00:00
|
|
|
SkDebugf("%s addSplit 2 tIndex=%d,%d flip\n",
|
|
|
|
__FUNCTION__, firstSplit, tIndex);
|
2012-03-30 18:47:02 +00:00
|
|
|
#endif
|
|
|
|
lastSplit = tIndex;
|
|
|
|
firstSplit = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
y = nextY;
|
|
|
|
}
|
|
|
|
if (curveSplit) {
|
|
|
|
if (firstSplit < 0) {
|
|
|
|
firstSplit = lastSplit;
|
|
|
|
} else {
|
2012-04-10 18:28:55 +00:00
|
|
|
addSplit(edges, pts, verb, intercepts, lastSplit,
|
|
|
|
firstSplit, false);
|
2012-03-30 18:47:02 +00:00
|
|
|
#if DEBUG_SPLIT
|
2012-04-10 18:28:55 +00:00
|
|
|
SkDebugf("%s addSplit 3 tIndex=%d,%d\n", __FUNCTION__,
|
|
|
|
lastSplit, firstSplit);
|
2012-03-30 18:47:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
2012-04-10 18:28:55 +00:00
|
|
|
addSplit(edges, pts, verb, intercepts, firstSplit,
|
|
|
|
tIndex, pts[verb].fY < y);
|
2012-03-30 18:47:02 +00:00
|
|
|
#if DEBUG_SPLIT
|
2012-04-10 18:28:55 +00:00
|
|
|
SkDebugf("%s addSplit 4 tIndex=%d,%d %s\n", __FUNCTION__,
|
|
|
|
firstSplit, tIndex, pts[verb].fY < y ? "flip" : "");
|
2012-03-30 18:47:02 +00:00
|
|
|
#endif
|
2012-02-07 22:10:51 +00:00
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
}
|
|
|
|
// collapse remainder -- if there's nothing left, clear it somehow?
|
|
|
|
if (edgeSplit) {
|
|
|
|
int nextVerb = verbs - 1 - fVerbs.begin();
|
|
|
|
if (lastVerb < nextVerb) {
|
|
|
|
int nextPt = pts - fPts.begin();
|
2012-04-10 18:28:55 +00:00
|
|
|
addPartial(edges, lastPt, nextPt, lastVerb, nextVerb);
|
2012-03-30 18:47:02 +00:00
|
|
|
#if DEBUG_SPLIT
|
2012-04-10 18:28:55 +00:00
|
|
|
SkDebugf("%s addPartial 2\n", __FUNCTION__);
|
2012-03-30 18:47:02 +00:00
|
|
|
#endif
|
2012-02-07 22:10:51 +00:00
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
// OPTIMIZATION: reuse the edge instead of marking it empty
|
|
|
|
reset();
|
2012-02-07 22:10:51 +00:00
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_DUMP
|
|
|
|
void dump() {
|
|
|
|
int i;
|
|
|
|
const char className[] = "InEdge";
|
|
|
|
const int tab = 4;
|
|
|
|
SkDebugf("InEdge %p (edge=%d)\n", this, fID);
|
|
|
|
for (i = 0; i < fCached.count(); ++i) {
|
|
|
|
SkDebugf("%*s.fCached[%d]=0x%08x\n", tab + sizeof(className),
|
|
|
|
className, i, fCached[i]);
|
|
|
|
}
|
|
|
|
uint8_t* verbs = fVerbs.begin();
|
|
|
|
SkPoint* pts = fPts.begin();
|
|
|
|
for (i = 0; i < fIntercepts.count(); ++i) {
|
|
|
|
SkDebugf("%*s.fIntercepts[%d]:\n", tab + sizeof(className),
|
|
|
|
className, i);
|
2012-03-28 16:20:21 +00:00
|
|
|
fIntercepts[i].dump(pts, (SkPath::Verb) *verbs);
|
2012-03-20 21:11:59 +00:00
|
|
|
pts += *verbs++;
|
|
|
|
}
|
|
|
|
for (i = 0; i < fPts.count(); ++i) {
|
2012-03-22 21:11:17 +00:00
|
|
|
SkDebugf("%*s.fPts[%d]=(%1.9g,%1.9g)\n", tab + sizeof(className),
|
2012-03-20 21:11:59 +00:00
|
|
|
className, i, fPts[i].fX, fPts[i].fY);
|
|
|
|
}
|
|
|
|
for (i = 0; i < fVerbs.count(); ++i) {
|
|
|
|
SkDebugf("%*s.fVerbs[%d]=%d\n", tab + sizeof(className),
|
|
|
|
className, i, fVerbs[i]);
|
|
|
|
}
|
2012-04-10 18:28:55 +00:00
|
|
|
SkDebugf("%*s.fBounds=(%1.9g, %1.9g, %1.9g, %1.9g)\n", tab + sizeof(className),
|
2012-03-20 21:11:59 +00:00
|
|
|
className, fBounds.fLeft, fBounds.fTop,
|
|
|
|
fBounds.fRight, fBounds.fBottom);
|
|
|
|
SkDebugf("%*s.fWinding=%d\n", tab + sizeof(className), className,
|
|
|
|
fWinding);
|
|
|
|
SkDebugf("%*s.fContainsIntercepts=%d\n", tab + sizeof(className),
|
|
|
|
className, fContainsIntercepts);
|
2012-03-30 18:47:02 +00:00
|
|
|
SkDebugf("%*s.fIntersected=%d\n", tab + sizeof(className),
|
|
|
|
className, fIntersected);
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
#endif
|
2012-02-03 22:07:47 +00:00
|
|
|
|
2012-03-30 18:47:02 +00:00
|
|
|
// FIXME: temporary data : move this to a separate struct?
|
2012-02-07 22:10:51 +00:00
|
|
|
SkTDArray<const InEdge*> fCached; // list of edges already intercepted
|
2012-02-03 22:07:47 +00:00
|
|
|
SkTArray<Intercepts> fIntercepts; // one per verb
|
2012-03-05 22:01:21 +00:00
|
|
|
|
2012-02-03 22:07:47 +00:00
|
|
|
// persistent data
|
|
|
|
SkTDArray<SkPoint> fPts;
|
|
|
|
SkTDArray<uint8_t> fVerbs;
|
|
|
|
Bounds fBounds;
|
2012-03-20 21:11:59 +00:00
|
|
|
int fID;
|
2012-02-03 22:07:47 +00:00
|
|
|
signed char fWinding;
|
2012-02-07 22:10:51 +00:00
|
|
|
bool fContainsIntercepts;
|
2012-03-30 18:47:02 +00:00
|
|
|
bool fIntersected;
|
2012-02-03 22:07:47 +00:00
|
|
|
};
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
class InEdgeBuilder {
|
2012-02-03 22:07:47 +00:00
|
|
|
public:
|
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
InEdgeBuilder(const SkPath& path, bool ignoreHorizontal, SkTArray<InEdge>& edges,
|
2012-08-23 18:14:13 +00:00
|
|
|
SkTDArray<HorizontalEdge>& horizontalEdges)
|
2012-02-03 22:07:47 +00:00
|
|
|
: fPath(path)
|
|
|
|
, fCurrentEdge(NULL)
|
|
|
|
, fEdges(edges)
|
2012-03-20 21:11:59 +00:00
|
|
|
, fHorizontalEdges(horizontalEdges)
|
2012-02-03 22:07:47 +00:00
|
|
|
, fIgnoreHorizontal(ignoreHorizontal)
|
2012-03-30 18:47:02 +00:00
|
|
|
, fContainsCurves(false)
|
2012-02-03 22:07:47 +00:00
|
|
|
{
|
|
|
|
walk();
|
|
|
|
}
|
|
|
|
|
2012-03-30 18:47:02 +00:00
|
|
|
bool containsCurves() const {
|
|
|
|
return fContainsCurves;
|
|
|
|
}
|
|
|
|
|
2012-02-03 22:07:47 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
void addEdge() {
|
2012-02-09 22:04:27 +00:00
|
|
|
SkASSERT(fCurrentEdge);
|
2012-02-03 22:07:47 +00:00
|
|
|
fCurrentEdge->fPts.append(fPtCount - fPtOffset, &fPts[fPtOffset]);
|
|
|
|
fPtOffset = 1;
|
|
|
|
*fCurrentEdge->fVerbs.append() = fVerb;
|
|
|
|
}
|
|
|
|
|
2012-02-15 22:01:16 +00:00
|
|
|
bool complete() {
|
|
|
|
if (fCurrentEdge && fCurrentEdge->fVerbs.count()) {
|
2012-04-10 18:28:55 +00:00
|
|
|
fCurrentEdge->complete(fWinding);
|
2012-02-15 22:01:16 +00:00
|
|
|
fCurrentEdge = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-17 11:40:34 +00:00
|
|
|
int direction(SkPath::Verb verb) {
|
|
|
|
fPtCount = verb + 1;
|
2012-03-20 21:11:59 +00:00
|
|
|
if (fIgnoreHorizontal && isHorizontal()) {
|
2012-02-03 22:07:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-04-17 11:40:34 +00:00
|
|
|
return fPts[0].fY == fPts[verb].fY
|
|
|
|
? fPts[0].fX == fPts[verb].fX ? 0 : fPts[0].fX < fPts[verb].fX
|
|
|
|
? 1 : -1 : fPts[0].fY < fPts[verb].fY ? 1 : -1;
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isHorizontal() {
|
|
|
|
SkScalar y = fPts[0].fY;
|
|
|
|
for (int i = 1; i < fPtCount; ++i) {
|
|
|
|
if (fPts[i].fY != y) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void startEdge() {
|
2012-02-15 22:01:16 +00:00
|
|
|
if (!fCurrentEdge) {
|
|
|
|
fCurrentEdge = fEdges.push_back_n(1);
|
|
|
|
}
|
2012-02-03 22:07:47 +00:00
|
|
|
fWinding = 0;
|
|
|
|
fPtOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void walk() {
|
|
|
|
SkPath::Iter iter(fPath, true);
|
2012-03-20 21:11:59 +00:00
|
|
|
int winding = 0;
|
2012-02-03 22:07:47 +00:00
|
|
|
while ((fVerb = iter.next(fPts)) != SkPath::kDone_Verb) {
|
|
|
|
switch (fVerb) {
|
|
|
|
case SkPath::kMove_Verb:
|
|
|
|
startEdge();
|
|
|
|
continue;
|
|
|
|
case SkPath::kLine_Verb:
|
2012-04-17 11:40:34 +00:00
|
|
|
winding = direction(SkPath::kLine_Verb);
|
2012-02-03 22:07:47 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
2012-04-17 11:40:34 +00:00
|
|
|
fVerb = QuadReduceOrder(fPts);
|
|
|
|
winding = direction(fVerb);
|
|
|
|
fContainsCurves |= fVerb == SkPath::kQuad_Verb;
|
2012-02-03 22:07:47 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
2012-04-17 11:40:34 +00:00
|
|
|
fVerb = CubicReduceOrder(fPts);
|
|
|
|
winding = direction(fVerb);
|
|
|
|
fContainsCurves |= fVerb >= SkPath::kQuad_Verb;
|
2012-02-03 22:07:47 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kClose_Verb:
|
2012-02-09 22:04:27 +00:00
|
|
|
SkASSERT(fCurrentEdge);
|
2012-02-15 22:01:16 +00:00
|
|
|
complete();
|
2012-02-03 22:07:47 +00:00
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
SkDEBUGFAIL("bad verb");
|
|
|
|
return;
|
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
if (winding == 0) {
|
|
|
|
HorizontalEdge* horizontalEdge = fHorizontalEdges.append();
|
|
|
|
// FIXME: for degenerate quads and cubics, compute x extremes
|
|
|
|
horizontalEdge->fLeft = fPts[0].fX;
|
|
|
|
horizontalEdge->fRight = fPts[fVerb].fX;
|
|
|
|
horizontalEdge->fY = fPts[0].fY;
|
|
|
|
if (horizontalEdge->fLeft > horizontalEdge->fRight) {
|
|
|
|
SkTSwap<SkScalar>(horizontalEdge->fLeft, horizontalEdge->fRight);
|
|
|
|
}
|
2012-02-15 22:01:16 +00:00
|
|
|
if (complete()) {
|
|
|
|
startEdge();
|
|
|
|
}
|
2012-02-03 22:07:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (fWinding + winding == 0) {
|
|
|
|
// FIXME: if prior verb or this verb is a horizontal line, reverse
|
|
|
|
// it instead of starting a new edge
|
2012-02-09 22:04:27 +00:00
|
|
|
SkASSERT(fCurrentEdge);
|
2012-02-28 16:57:05 +00:00
|
|
|
if (complete()) {
|
|
|
|
startEdge();
|
|
|
|
}
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
|
|
|
fWinding = winding;
|
|
|
|
addEdge();
|
|
|
|
}
|
2012-02-16 21:24:41 +00:00
|
|
|
if (!complete()) {
|
|
|
|
if (fCurrentEdge) {
|
|
|
|
fEdges.pop_back();
|
|
|
|
}
|
|
|
|
}
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const SkPath& fPath;
|
2012-02-07 22:10:51 +00:00
|
|
|
InEdge* fCurrentEdge;
|
|
|
|
SkTArray<InEdge>& fEdges;
|
2012-03-20 21:11:59 +00:00
|
|
|
SkTDArray<HorizontalEdge>& fHorizontalEdges;
|
2012-02-03 22:07:47 +00:00
|
|
|
SkPoint fPts[4];
|
|
|
|
SkPath::Verb fVerb;
|
|
|
|
int fPtCount;
|
|
|
|
int fPtOffset;
|
|
|
|
int8_t fWinding;
|
|
|
|
bool fIgnoreHorizontal;
|
2012-03-30 18:47:02 +00:00
|
|
|
bool fContainsCurves;
|
2012-02-03 22:07:47 +00:00
|
|
|
};
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
struct WorkEdge {
|
2012-02-03 22:07:47 +00:00
|
|
|
SkScalar bottom() const {
|
2012-02-07 22:10:51 +00:00
|
|
|
return fPts[verb()].fY;
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
void init(const InEdge* edge) {
|
|
|
|
fEdge = edge;
|
|
|
|
fPts = edge->fPts.begin();
|
|
|
|
fVerb = edge->fVerbs.begin();
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
|
|
|
|
2012-02-28 16:57:05 +00:00
|
|
|
bool advance() {
|
2012-02-07 22:10:51 +00:00
|
|
|
SkASSERT(fVerb < fEdge->fVerbs.end());
|
|
|
|
fPts += *fVerb++;
|
|
|
|
return fVerb != fEdge->fVerbs.end();
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-04-17 11:40:34 +00:00
|
|
|
const SkPoint* lastPoints() const {
|
|
|
|
SkASSERT(fPts >= fEdge->fPts.begin() + lastVerb());
|
|
|
|
return &fPts[-lastVerb()];
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-03-01 19:16:31 +00:00
|
|
|
SkPath::Verb lastVerb() const {
|
|
|
|
SkASSERT(fVerb > fEdge->fVerbs.begin());
|
|
|
|
return (SkPath::Verb) fVerb[-1];
|
|
|
|
}
|
|
|
|
|
2012-04-17 11:40:34 +00:00
|
|
|
const SkPoint* points() const {
|
|
|
|
return fPts;
|
|
|
|
}
|
2012-02-03 22:07:47 +00:00
|
|
|
|
|
|
|
SkPath::Verb verb() const {
|
|
|
|
return (SkPath::Verb) *fVerb;
|
|
|
|
}
|
|
|
|
|
2012-02-15 22:01:16 +00:00
|
|
|
ptrdiff_t verbIndex() const {
|
2012-02-07 22:10:51 +00:00
|
|
|
return fVerb - fEdge->fVerbs.begin();
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
int winding() const {
|
|
|
|
return fEdge->fWinding;
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
const InEdge* fEdge;
|
2012-02-03 22:07:47 +00:00
|
|
|
const SkPoint* fPts;
|
|
|
|
const uint8_t* fVerb;
|
|
|
|
};
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
// always constructed with SkTDArray because new edges are inserted
|
|
|
|
// this may be a inappropriate optimization, suggesting that a separate array of
|
|
|
|
// ActiveEdge* may be faster to insert and search
|
2012-03-01 19:16:31 +00:00
|
|
|
|
|
|
|
// OPTIMIZATION: Brian suggests that global sorting should be unnecessary, since
|
|
|
|
// as active edges are introduced, only local sorting should be required
|
2012-03-20 21:11:59 +00:00
|
|
|
class ActiveEdge {
|
|
|
|
public:
|
2012-04-17 11:40:34 +00:00
|
|
|
// this logic must be kept in sync with tooCloseToCall
|
2012-04-26 21:01:06 +00:00
|
|
|
// callers expect this to only read fAbove, fTangent
|
2012-02-15 22:01:16 +00:00
|
|
|
bool operator<(const ActiveEdge& rh) const {
|
2012-04-26 21:01:06 +00:00
|
|
|
if (fVerb == rh.fVerb) {
|
|
|
|
// FIXME: don't know what to do if verb is quad, cubic
|
|
|
|
return abCompare(fAbove, fBelow, rh.fAbove, rh.fBelow);
|
|
|
|
}
|
|
|
|
// figure out which is quad, line
|
|
|
|
// if cached data says line did not intersect quad, use top/bottom
|
|
|
|
if (fVerb != SkPath::kLine_Verb ? noIntersect(rh) : rh.noIntersect(*this)) {
|
|
|
|
return abCompare(fAbove, fBelow, rh.fAbove, rh.fBelow);
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
// use whichever of top/tangent tangent/bottom overlaps more
|
2012-04-26 21:01:06 +00:00
|
|
|
// with line top/bot
|
|
|
|
// assumes quad/cubic can already be upconverted to cubic/cubic
|
|
|
|
const SkPoint* line[2];
|
|
|
|
const SkPoint* curve[4];
|
|
|
|
if (fVerb != SkPath::kLine_Verb) {
|
|
|
|
line[0] = &rh.fAbove;
|
|
|
|
line[1] = &rh.fBelow;
|
|
|
|
curve[0] = &fAbove;
|
|
|
|
curve[1] = &fTangent;
|
|
|
|
curve[2] = &fBelow;
|
|
|
|
} else {
|
|
|
|
line[0] = &fAbove;
|
|
|
|
line[1] = &fBelow;
|
|
|
|
curve[0] = &rh.fAbove;
|
|
|
|
curve[1] = &rh.fTangent;
|
|
|
|
curve[2] = &rh.fBelow;
|
|
|
|
}
|
2012-05-18 20:50:33 +00:00
|
|
|
// FIXME: code has been abandoned, incomplete....
|
|
|
|
return false;
|
2012-04-26 21:01:06 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-04-26 21:01:06 +00:00
|
|
|
bool abCompare(const SkPoint& a1, const SkPoint& a2, const SkPoint& b1,
|
|
|
|
const SkPoint& b2) const {
|
|
|
|
double topD = a1.fX - b1.fX;
|
|
|
|
if (b1.fY < a1.fY) {
|
|
|
|
topD = (b2.fY - b1.fY) * topD - (a1.fY - b1.fY) * (b2.fX - b1.fX);
|
|
|
|
} else if (b1.fY > a1.fY) {
|
|
|
|
topD = (a2.fY - a1.fY) * topD + (b1.fY - a1.fY) * (a2.fX - a1.fX);
|
|
|
|
}
|
|
|
|
double botD = a2.fX - b2.fX;
|
|
|
|
if (b2.fY > a2.fY) {
|
|
|
|
botD = (b2.fY - b1.fY) * botD - (a2.fY - b2.fY) * (b2.fX - b1.fX);
|
|
|
|
} else if (b2.fY < a2.fY) {
|
|
|
|
botD = (a2.fY - a1.fY) * botD + (b2.fY - a2.fY) * (a2.fX - a1.fX);
|
2012-03-27 13:23:51 +00:00
|
|
|
}
|
|
|
|
// return sign of greater absolute value
|
|
|
|
return (fabs(topD) > fabs(botD) ? topD : botD) < 0;
|
|
|
|
}
|
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
// If a pair of edges are nearly coincident for some span, add a T in the
|
|
|
|
// edge so it can be shortened to match the other edge. Note that another
|
|
|
|
// approach is to trim the edge after it is added to the OutBuilder list --
|
|
|
|
// FIXME: since this has no effect if the edge is already done (i.e.,
|
|
|
|
// fYBottom >= y) maybe this can only be done by calling trimLine later.
|
|
|
|
void addTatYBelow(SkScalar y) {
|
|
|
|
if (fBelow.fY <= y || fYBottom >= y) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addTatYInner(y);
|
|
|
|
fFixBelow = true;
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
void addTatYAbove(SkScalar y) {
|
|
|
|
if (fBelow.fY <= y) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addTatYInner(y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addTatYInner(SkScalar y) {
|
2012-03-22 21:11:17 +00:00
|
|
|
if (fWorkEdge.fPts[0].fY > y) {
|
|
|
|
backup(y);
|
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
SkScalar left = fWorkEdge.fPts[0].fX;
|
|
|
|
SkScalar right = fWorkEdge.fPts[1].fX;
|
|
|
|
if (left > right) {
|
|
|
|
SkTSwap(left, right);
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
double ts[2];
|
2012-04-17 11:40:34 +00:00
|
|
|
SkASSERT(fWorkEdge.fVerb[0] == SkPath::kLine_Verb);
|
2012-03-20 21:11:59 +00:00
|
|
|
int pts = LineIntersect(fWorkEdge.fPts, left, right, y, ts);
|
|
|
|
SkASSERT(pts == 1);
|
|
|
|
// An ActiveEdge or WorkEdge has no need to modify the T values computed
|
|
|
|
// in the InEdge, except in the following case. If a pair of edges are
|
|
|
|
// nearly coincident, this may not be detected when the edges are
|
|
|
|
// intersected. Later, when sorted, and this near-coincidence is found,
|
|
|
|
// an additional t value must be added, requiring the cast below.
|
|
|
|
InEdge* writable = const_cast<InEdge*>(fWorkEdge.fEdge);
|
|
|
|
int insertedAt = writable->add(ts, pts, fWorkEdge.verbIndex());
|
2012-03-22 21:11:17 +00:00
|
|
|
#if DEBUG_ADJUST_COINCIDENT
|
|
|
|
SkDebugf("%s edge=%d y=%1.9g t=%1.9g\n", __FUNCTION__, ID(), y, ts[0]);
|
|
|
|
#endif
|
2012-03-20 21:11:59 +00:00
|
|
|
if (insertedAt >= 0) {
|
|
|
|
if (insertedAt + 1 < fTIndex) {
|
|
|
|
SkASSERT(insertedAt + 2 == fTIndex);
|
|
|
|
--fTIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-15 22:01:16 +00:00
|
|
|
|
2012-03-01 19:16:31 +00:00
|
|
|
bool advanceT() {
|
2012-03-30 18:47:02 +00:00
|
|
|
SkASSERT(fTIndex <= fTs->count() - fExplicitTs);
|
|
|
|
return ++fTIndex <= fTs->count() - fExplicitTs;
|
2012-03-01 19:16:31 +00:00
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
|
2012-03-01 19:16:31 +00:00
|
|
|
bool advance() {
|
|
|
|
// FIXME: flip sense of next
|
|
|
|
bool result = fWorkEdge.advance();
|
|
|
|
fDone = !result;
|
|
|
|
initT();
|
|
|
|
return result;
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
|
|
|
void backup(SkScalar y) {
|
|
|
|
do {
|
|
|
|
SkASSERT(fWorkEdge.fEdge->fVerbs.begin() < fWorkEdge.fVerb);
|
|
|
|
fWorkEdge.fPts -= *--fWorkEdge.fVerb;
|
|
|
|
SkASSERT(fWorkEdge.fEdge->fPts.begin() <= fWorkEdge.fPts);
|
|
|
|
} while (fWorkEdge.fPts[0].fY >= y);
|
|
|
|
initT();
|
2012-03-30 18:47:02 +00:00
|
|
|
SkASSERT(!fExplicitTs);
|
2012-03-22 21:11:17 +00:00
|
|
|
fTIndex = fTs->count() + 1;
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-04-26 21:01:06 +00:00
|
|
|
void calcAboveBelow(double tAbove, double tBelow) {
|
|
|
|
fVerb = fWorkEdge.verb();
|
|
|
|
switch (fVerb) {
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
LineXYAtT(fWorkEdge.fPts, tAbove, &fAbove);
|
|
|
|
LineXYAtT(fWorkEdge.fPts, tBelow, &fTangent);
|
|
|
|
fBelow = fTangent;
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
// FIXME: put array in struct to avoid copy?
|
|
|
|
SkPoint quad[3];
|
|
|
|
QuadSubDivide(fWorkEdge.fPts, tAbove, tBelow, quad);
|
|
|
|
fAbove = quad[0];
|
|
|
|
fTangent = quad[0] != quad[1] ? quad[1] : quad[2];
|
|
|
|
fBelow = quad[2];
|
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
SkPoint cubic[3];
|
|
|
|
CubicSubDivide(fWorkEdge.fPts, tAbove, tBelow, cubic);
|
|
|
|
fAbove = cubic[0];
|
|
|
|
// FIXME: can't see how quad logic for how tangent is used
|
2012-08-23 18:14:13 +00:00
|
|
|
// extends to cubic
|
2012-04-26 21:01:06 +00:00
|
|
|
fTangent = cubic[0] != cubic[1] ? cubic[1]
|
|
|
|
: cubic[0] != cubic[2] ? cubic[2] : cubic[3];
|
|
|
|
fBelow = cubic[3];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-03-01 19:16:31 +00:00
|
|
|
void calcLeft(SkScalar y) {
|
2012-02-28 16:57:05 +00:00
|
|
|
// OPTIMIZE: put a kDone_Verb at the end of the verb list?
|
2012-03-05 22:01:21 +00:00
|
|
|
if (fDone || fBelow.fY > y) {
|
2012-02-28 16:57:05 +00:00
|
|
|
return; // nothing to do; use last
|
2012-03-05 22:01:21 +00:00
|
|
|
}
|
2012-03-01 19:16:31 +00:00
|
|
|
calcLeft();
|
2012-03-22 21:11:17 +00:00
|
|
|
if (fAbove.fY == fBelow.fY) {
|
|
|
|
SkDebugf("%s edge=%d fAbove.fY != fBelow.fY %1.9g\n", __FUNCTION__,
|
|
|
|
ID(), fAbove.fY);
|
|
|
|
}
|
2012-03-01 19:16:31 +00:00
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-03-01 19:16:31 +00:00
|
|
|
void calcLeft() {
|
2012-03-30 18:47:02 +00:00
|
|
|
int add = (fTIndex <= fTs->count() - fExplicitTs) - 1;
|
2012-03-28 16:20:21 +00:00
|
|
|
double tAbove = t(fTIndex + add);
|
|
|
|
double tBelow = t(fTIndex - ~add);
|
2012-04-26 21:01:06 +00:00
|
|
|
// OPTIMIZATION: if fAbove, fBelow have already been computed
|
|
|
|
// for the fTIndex, don't do it again
|
|
|
|
calcAboveBelow(tAbove, tBelow);
|
|
|
|
// For identical x, this lets us know which edge is first.
|
|
|
|
// If both edges have T values < 1, check x at next T (fBelow).
|
2012-03-28 16:20:21 +00:00
|
|
|
SkASSERT(tAbove != tBelow);
|
|
|
|
// FIXME: this can loop forever
|
|
|
|
// need a break if we hit the end
|
2012-03-30 18:47:02 +00:00
|
|
|
// FIXME: in unit test, figure out how explicit Ts work as well
|
2012-03-28 16:20:21 +00:00
|
|
|
while (fAbove.fY == fBelow.fY) {
|
|
|
|
if (add < 0 || fTIndex == fTs->count()) {
|
|
|
|
add -= 1;
|
|
|
|
SkASSERT(fTIndex + add >= 0);
|
|
|
|
tAbove = t(fTIndex + add);
|
|
|
|
} else {
|
|
|
|
add += 1;
|
|
|
|
SkASSERT(fTIndex - ~add <= fTs->count() + 1);
|
|
|
|
tBelow = t(fTIndex - ~add);
|
|
|
|
}
|
2012-04-26 21:01:06 +00:00
|
|
|
calcAboveBelow(tAbove, tBelow);
|
2012-03-28 16:20:21 +00:00
|
|
|
}
|
|
|
|
fTAbove = tAbove;
|
|
|
|
fTBelow = tBelow;
|
2012-02-15 22:01:16 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 21:11:17 +00:00
|
|
|
bool done(SkScalar bottom) const {
|
|
|
|
return fDone || fYBottom >= bottom;
|
2012-03-01 19:16:31 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
void fixBelow() {
|
|
|
|
if (fFixBelow) {
|
2012-04-26 21:01:06 +00:00
|
|
|
fTBelow = nextT();
|
|
|
|
calcAboveBelow(fTAbove, fTBelow);
|
2012-03-20 21:11:59 +00:00
|
|
|
fFixBelow = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
void init(const InEdge* edge) {
|
|
|
|
fWorkEdge.init(edge);
|
2012-04-26 21:01:06 +00:00
|
|
|
fDone = false;
|
2012-02-07 22:10:51 +00:00
|
|
|
initT();
|
2012-03-05 22:01:21 +00:00
|
|
|
fBelow.fY = SK_ScalarMin;
|
2012-02-28 16:57:05 +00:00
|
|
|
fYBottom = SK_ScalarMin;
|
2012-02-07 22:10:51 +00:00
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
void initT() {
|
2012-02-15 22:01:16 +00:00
|
|
|
const Intercepts& intercepts = fWorkEdge.fEdge->fIntercepts.front();
|
|
|
|
SkASSERT(fWorkEdge.verbIndex() <= fWorkEdge.fEdge->fIntercepts.count());
|
|
|
|
const Intercepts* interceptPtr = &intercepts + fWorkEdge.verbIndex();
|
2012-03-30 18:47:02 +00:00
|
|
|
fTs = &interceptPtr->fTs;
|
|
|
|
fExplicitTs = interceptPtr->fExplicit;
|
2012-02-15 22:01:16 +00:00
|
|
|
// the above is conceptually the same as
|
|
|
|
// fTs = &fWorkEdge.fEdge->fIntercepts[fWorkEdge.verbIndex()].fTs;
|
|
|
|
// but templated arrays don't allow returning a pointer to the end() element
|
2012-02-07 22:10:51 +00:00
|
|
|
fTIndex = 0;
|
2012-04-26 21:01:06 +00:00
|
|
|
if (!fDone) {
|
|
|
|
fVerb = fWorkEdge.verb();
|
|
|
|
}
|
|
|
|
SkASSERT(fVerb > SkPath::kMove_Verb);
|
2012-02-07 22:10:51 +00:00
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-03-01 19:16:31 +00:00
|
|
|
// OPTIMIZATION: record if two edges are coincident when the are intersected
|
|
|
|
// It's unclear how to do this -- seems more complicated than recording the
|
|
|
|
// t values, since the same t values could exist intersecting non-coincident
|
|
|
|
// edges.
|
2012-04-17 11:40:34 +00:00
|
|
|
bool isCoincidentWith(const ActiveEdge* edge) const {
|
2012-03-27 13:23:51 +00:00
|
|
|
if (fAbove != edge->fAbove || fBelow != edge->fBelow) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-26 21:01:06 +00:00
|
|
|
if (fVerb != edge->fVerb) {
|
2012-03-01 19:16:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-04-26 21:01:06 +00:00
|
|
|
switch (fVerb) {
|
2012-04-17 11:40:34 +00:00
|
|
|
case SkPath::kLine_Verb:
|
2012-03-05 22:01:21 +00:00
|
|
|
return true;
|
2012-02-28 16:57:05 +00:00
|
|
|
default:
|
2012-04-17 11:40:34 +00:00
|
|
|
// FIXME: add support for quads, cubics
|
2012-02-28 16:57:05 +00:00
|
|
|
SkASSERT(0);
|
2012-04-17 11:40:34 +00:00
|
|
|
return false;
|
2012-02-28 16:57:05 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-04-17 11:40:34 +00:00
|
|
|
bool isUnordered(const ActiveEdge* edge) const {
|
|
|
|
return fAbove == edge->fAbove && fBelow == edge->fBelow;
|
|
|
|
}
|
|
|
|
|
2012-04-26 21:01:06 +00:00
|
|
|
// SkPath::Verb lastVerb() const {
|
|
|
|
// return fDone ? fWorkEdge.lastVerb() : fWorkEdge.verb();
|
|
|
|
// }
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-04-17 11:40:34 +00:00
|
|
|
const SkPoint* lastPoints() const {
|
|
|
|
return fDone ? fWorkEdge.lastPoints() : fWorkEdge.points();
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-04-26 21:01:06 +00:00
|
|
|
bool noIntersect(const ActiveEdge& ) const {
|
|
|
|
// incomplete
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-17 11:40:34 +00:00
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
// The shortest close call edge should be moved into a position where
|
|
|
|
// it contributes if the winding is transitioning to or from zero.
|
|
|
|
bool swapClose(const ActiveEdge* next, int prev, int wind, int mask) const {
|
2012-03-27 13:23:51 +00:00
|
|
|
#if DEBUG_ADJUST_COINCIDENT
|
|
|
|
SkDebugf("%s edge=%d (%g) next=%d (%g) prev=%d wind=%d nextWind=%d\n",
|
|
|
|
__FUNCTION__, ID(), fBelow.fY, next->ID(), next->fBelow.fY,
|
|
|
|
prev, wind, wind + next->fWorkEdge.winding());
|
|
|
|
#endif
|
2012-03-20 21:11:59 +00:00
|
|
|
if ((prev & mask) == 0 || (wind & mask) == 0) {
|
|
|
|
return next->fBelow.fY < fBelow.fY;
|
|
|
|
}
|
|
|
|
int nextWinding = wind + next->fWorkEdge.winding();
|
|
|
|
if ((nextWinding & mask) == 0) {
|
|
|
|
return fBelow.fY < next->fBelow.fY;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-03-01 19:16:31 +00:00
|
|
|
bool swapCoincident(const ActiveEdge* edge, SkScalar bottom) const {
|
|
|
|
if (fBelow.fY >= bottom || fDone || edge->fDone) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ActiveEdge thisWork = *this;
|
|
|
|
ActiveEdge edgeWork = *edge;
|
|
|
|
while ((thisWork.advanceT() || thisWork.advance())
|
|
|
|
&& (edgeWork.advanceT() || edgeWork.advance())) {
|
|
|
|
thisWork.calcLeft();
|
|
|
|
edgeWork.calcLeft();
|
|
|
|
if (thisWork < edgeWork) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (edgeWork < thisWork) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-02-28 16:57:05 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-06-01 17:44:28 +00:00
|
|
|
bool swapUnordered(const ActiveEdge* edge, SkScalar /* bottom */) const {
|
2012-04-26 21:01:06 +00:00
|
|
|
SkASSERT(fVerb != SkPath::kLine_Verb
|
|
|
|
|| edge->fVerb != SkPath::kLine_Verb);
|
2012-04-17 11:40:34 +00:00
|
|
|
if (fDone || edge->fDone) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ActiveEdge thisWork, edgeWork;
|
|
|
|
extractAboveBelow(thisWork);
|
|
|
|
edge->extractAboveBelow(edgeWork);
|
|
|
|
return edgeWork < thisWork;
|
|
|
|
}
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
bool tooCloseToCall(const ActiveEdge* edge) const {
|
|
|
|
int ulps;
|
2012-03-27 13:23:51 +00:00
|
|
|
double t1, t2, b1, b2;
|
2012-04-17 11:40:34 +00:00
|
|
|
// This logic must be kept in sync with operator <
|
2012-03-27 13:23:51 +00:00
|
|
|
if (edge->fAbove.fY < fAbove.fY) {
|
2012-04-26 21:01:06 +00:00
|
|
|
t1 = (edge->fTangent.fY - edge->fAbove.fY) * (fAbove.fX - edge->fAbove.fX);
|
|
|
|
t2 = (fAbove.fY - edge->fAbove.fY) * (edge->fTangent.fX - edge->fAbove.fX);
|
2012-03-27 13:23:51 +00:00
|
|
|
} else if (edge->fAbove.fY > fAbove.fY) {
|
2012-04-26 21:01:06 +00:00
|
|
|
t1 = (fTangent.fY - fAbove.fY) * (fAbove.fX - edge->fAbove.fX);
|
|
|
|
t2 = (fAbove.fY - edge->fAbove.fY) * (fTangent.fX - fAbove.fX);
|
2012-03-27 13:23:51 +00:00
|
|
|
} else {
|
|
|
|
t1 = fAbove.fX;
|
|
|
|
t2 = edge->fAbove.fX;
|
|
|
|
}
|
2012-04-26 21:01:06 +00:00
|
|
|
if (edge->fTangent.fY > fTangent.fY) {
|
|
|
|
b1 = (edge->fTangent.fY - edge->fAbove.fY) * (fTangent.fX - edge->fTangent.fX);
|
|
|
|
b2 = (fTangent.fY - edge->fTangent.fY) * (edge->fTangent.fX - edge->fAbove.fX);
|
|
|
|
} else if (edge->fTangent.fY < fTangent.fY) {
|
|
|
|
b1 = (fTangent.fY - fAbove.fY) * (fTangent.fX - edge->fTangent.fX);
|
|
|
|
b2 = (fTangent.fY - edge->fTangent.fY) * (fTangent.fX - fAbove.fX);
|
2012-03-27 13:23:51 +00:00
|
|
|
} else {
|
2012-04-26 21:01:06 +00:00
|
|
|
b1 = fTangent.fX;
|
|
|
|
b2 = edge->fTangent.fX;
|
2012-03-27 13:23:51 +00:00
|
|
|
}
|
|
|
|
if (fabs(t1 - t2) > fabs(b1 - b2)) {
|
2012-05-18 20:50:33 +00:00
|
|
|
ulps = UlpsDiff((float) t1, (float) t2);
|
2012-03-27 13:23:51 +00:00
|
|
|
} else {
|
2012-05-18 20:50:33 +00:00
|
|
|
ulps = UlpsDiff((float) b1, (float) b2);
|
2012-03-27 13:23:51 +00:00
|
|
|
}
|
|
|
|
#if DEBUG_ADJUST_COINCIDENT
|
|
|
|
SkDebugf("%s this=%d edge=%d ulps=%d\n", __FUNCTION__, ID(), edge->ID(),
|
|
|
|
ulps);
|
|
|
|
#endif
|
2012-04-17 11:40:34 +00:00
|
|
|
if (ulps < 0 || ulps > 32) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-26 21:01:06 +00:00
|
|
|
if (fVerb == SkPath::kLine_Verb && edge->fVerb == SkPath::kLine_Verb) {
|
2012-04-17 11:40:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-04-26 21:01:06 +00:00
|
|
|
if (fVerb != SkPath::kLine_Verb && edge->fVerb != SkPath::kLine_Verb) {
|
2012-04-17 11:40:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
double ts[2];
|
|
|
|
bool isLine = true;
|
|
|
|
bool curveQuad = true;
|
2012-04-26 21:01:06 +00:00
|
|
|
if (fVerb == SkPath::kCubic_Verb) {
|
2012-04-17 11:40:34 +00:00
|
|
|
ts[0] = (fTAbove * 2 + fTBelow) / 3;
|
|
|
|
ts[1] = (fTAbove + fTBelow * 2) / 3;
|
|
|
|
curveQuad = isLine = false;
|
2012-04-26 21:01:06 +00:00
|
|
|
} else if (edge->fVerb == SkPath::kCubic_Verb) {
|
2012-04-17 11:40:34 +00:00
|
|
|
ts[0] = (edge->fTAbove * 2 + edge->fTBelow) / 3;
|
|
|
|
ts[1] = (edge->fTAbove + edge->fTBelow * 2) / 3;
|
|
|
|
curveQuad = false;
|
2012-04-26 21:01:06 +00:00
|
|
|
} else if (fVerb == SkPath::kQuad_Verb) {
|
2012-04-17 11:40:34 +00:00
|
|
|
ts[0] = fTAbove;
|
|
|
|
ts[1] = (fTAbove + fTBelow) / 2;
|
|
|
|
isLine = false;
|
|
|
|
} else {
|
2012-04-26 21:01:06 +00:00
|
|
|
SkASSERT(edge->fVerb == SkPath::kQuad_Verb);
|
2012-04-17 11:40:34 +00:00
|
|
|
ts[0] = edge->fTAbove;
|
|
|
|
ts[1] = (edge->fTAbove + edge->fTBelow) / 2;
|
|
|
|
}
|
|
|
|
const SkPoint* curvePts = isLine ? edge->lastPoints() : lastPoints();
|
|
|
|
const ActiveEdge* lineEdge = isLine ? this : edge;
|
|
|
|
SkPoint curveSample[2];
|
|
|
|
for (int index = 0; index < 2; ++index) {
|
|
|
|
if (curveQuad) {
|
|
|
|
QuadXYAtT(curvePts, ts[index], &curveSample[index]);
|
|
|
|
} else {
|
|
|
|
CubicXYAtT(curvePts, ts[index], &curveSample[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return IsCoincident(curveSample, lineEdge->fAbove, lineEdge->fBelow);
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
double nextT() const {
|
2012-03-30 18:47:02 +00:00
|
|
|
SkASSERT(fTIndex <= fTs->count() - fExplicitTs);
|
2012-02-28 16:57:05 +00:00
|
|
|
return t(fTIndex + 1);
|
|
|
|
}
|
2012-02-03 22:07:47 +00:00
|
|
|
|
2012-02-28 16:57:05 +00:00
|
|
|
double t() const {
|
2012-03-30 18:47:02 +00:00
|
|
|
return t(fTIndex);
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
|
|
|
|
2012-02-28 16:57:05 +00:00
|
|
|
double t(int tIndex) const {
|
2012-03-30 18:47:02 +00:00
|
|
|
if (fExplicitTs) {
|
|
|
|
SkASSERT(tIndex < fTs->count());
|
|
|
|
return (*fTs)[tIndex];
|
2012-08-23 18:14:13 +00:00
|
|
|
}
|
2012-02-28 16:57:05 +00:00
|
|
|
if (tIndex == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (tIndex > fTs->count()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return (*fTs)[tIndex - 1];
|
|
|
|
}
|
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
// FIXME: debugging only
|
2012-03-22 21:11:17 +00:00
|
|
|
int ID() const {
|
2012-03-20 21:11:59 +00:00
|
|
|
return fWorkEdge.fEdge->fID;
|
|
|
|
}
|
|
|
|
|
2012-04-17 11:40:34 +00:00
|
|
|
private:
|
|
|
|
// utility used only by swapUnordered
|
|
|
|
void extractAboveBelow(ActiveEdge& extracted) const {
|
|
|
|
SkPoint curve[4];
|
2012-04-26 21:01:06 +00:00
|
|
|
switch (fVerb) {
|
2012-08-23 18:14:13 +00:00
|
|
|
case SkPath::kLine_Verb:
|
2012-04-17 11:40:34 +00:00
|
|
|
extracted.fAbove = fAbove;
|
2012-04-26 21:01:06 +00:00
|
|
|
extracted.fTangent = fTangent;
|
2012-04-17 11:40:34 +00:00
|
|
|
return;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
QuadSubDivide(lastPoints(), fTAbove, fTBelow, curve);
|
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
CubicSubDivide(lastPoints(), fTAbove, fTBelow, curve);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
|
|
|
extracted.fAbove = curve[0];
|
2012-04-26 21:01:06 +00:00
|
|
|
extracted.fTangent = curve[1];
|
2012-04-17 11:40:34 +00:00
|
|
|
}
|
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
public:
|
2012-02-07 22:10:51 +00:00
|
|
|
WorkEdge fWorkEdge;
|
|
|
|
const SkTDArray<double>* fTs;
|
2012-03-01 19:16:31 +00:00
|
|
|
SkPoint fAbove;
|
2012-04-26 21:01:06 +00:00
|
|
|
SkPoint fTangent;
|
2012-03-01 19:16:31 +00:00
|
|
|
SkPoint fBelow;
|
2012-04-17 11:40:34 +00:00
|
|
|
double fTAbove; // OPTIMIZATION: only required if edge has quads or cubics
|
2012-03-20 21:11:59 +00:00
|
|
|
double fTBelow;
|
2012-02-28 16:57:05 +00:00
|
|
|
SkScalar fYBottom;
|
2012-03-20 21:11:59 +00:00
|
|
|
int fCoincident;
|
2012-02-07 22:10:51 +00:00
|
|
|
int fTIndex;
|
2012-04-26 21:01:06 +00:00
|
|
|
SkPath::Verb fVerb;
|
2012-03-20 21:11:59 +00:00
|
|
|
bool fSkip; // OPTIMIZATION: use bitfields?
|
|
|
|
bool fCloseCall;
|
2012-02-28 16:57:05 +00:00
|
|
|
bool fDone;
|
2012-03-20 21:11:59 +00:00
|
|
|
bool fFixBelow;
|
2012-03-30 18:47:02 +00:00
|
|
|
bool fExplicitTs;
|
2012-02-03 22:07:47 +00:00
|
|
|
};
|
|
|
|
|
2012-02-07 22:10:51 +00:00
|
|
|
static void addToActive(SkTDArray<ActiveEdge>& activeEdges, const InEdge* edge) {
|
|
|
|
size_t count = activeEdges.count();
|
|
|
|
for (size_t index = 0; index < count; ++index) {
|
|
|
|
if (edge == activeEdges[index].fWorkEdge.fEdge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ActiveEdge* active = activeEdges.append();
|
|
|
|
active->init(edge);
|
|
|
|
}
|
|
|
|
|
2012-03-05 22:01:21 +00:00
|
|
|
// Find any intersections in the range of active edges. A pair of edges, on
|
|
|
|
// either side of another edge, may change the winding contribution for part of
|
2012-08-23 18:14:13 +00:00
|
|
|
// the edge.
|
2012-03-20 21:11:59 +00:00
|
|
|
// Keep horizontal edges just for
|
2012-03-05 22:01:21 +00:00
|
|
|
// the purpose of computing when edges change their winding contribution, since
|
2012-08-23 18:14:13 +00:00
|
|
|
// this is essentially computing the horizontal intersection.
|
2012-03-20 21:11:59 +00:00
|
|
|
static void addBottomT(InEdge** currentPtr, InEdge** lastPtr,
|
|
|
|
HorizontalEdge** horizontal) {
|
|
|
|
InEdge** testPtr = currentPtr - 1;
|
|
|
|
HorizontalEdge* horzEdge = *horizontal;
|
|
|
|
SkScalar left = horzEdge->fLeft;
|
|
|
|
SkScalar bottom = horzEdge->fY;
|
|
|
|
while (++testPtr != lastPtr) {
|
|
|
|
InEdge* test = *testPtr;
|
|
|
|
if (test->fBounds.fBottom <= bottom || test->fBounds.fRight <= left) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
WorkEdge wt;
|
|
|
|
wt.init(test);
|
|
|
|
do {
|
|
|
|
HorizontalEdge** sorted = horizontal;
|
|
|
|
horzEdge = *sorted;
|
2012-02-09 22:04:27 +00:00
|
|
|
do {
|
2012-03-30 18:47:02 +00:00
|
|
|
double wtTs[4];
|
|
|
|
int pts;
|
|
|
|
uint8_t verb = wt.verb();
|
|
|
|
switch (verb) {
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
pts = LineIntersect(wt.fPts, horzEdge->fLeft,
|
|
|
|
horzEdge->fRight, horzEdge->fY, wtTs);
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
pts = QuadIntersect(wt.fPts, horzEdge->fLeft,
|
|
|
|
horzEdge->fRight, horzEdge->fY, wtTs);
|
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
pts = CubicIntersect(wt.fPts, horzEdge->fLeft,
|
|
|
|
horzEdge->fRight, horzEdge->fY, wtTs);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pts) {
|
2012-03-20 21:11:59 +00:00
|
|
|
#if DEBUG_ADD_BOTTOM_TS
|
2012-03-30 18:47:02 +00:00
|
|
|
for (int x = 0; x < pts; ++x) {
|
|
|
|
SkDebugf("%s y=%g wtTs[0]=%g (%g,%g", __FUNCTION__,
|
|
|
|
horzEdge->fY, wtTs[x], wt.fPts[0].fX, wt.fPts[0].fY);
|
|
|
|
for (int y = 0; y < verb; ++y) {
|
|
|
|
SkDebugf(" %g,%g", wt.fPts[y + 1].fX, wt.fPts[y + 1].fY));
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
SkDebugf(")\n");
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
if (pts > verb) {
|
|
|
|
SkASSERT(0); // FIXME ? should this work?
|
|
|
|
SkDebugf("%s wtTs[1]=%g\n", __FUNCTION__, wtTs[1]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
test->add(wtTs, pts, wt.verbIndex());
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
horzEdge = *++sorted;
|
|
|
|
} while (horzEdge->fY == bottom
|
|
|
|
&& horzEdge->fLeft <= test->fBounds.fRight);
|
|
|
|
} while (wt.advance());
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:44:28 +00:00
|
|
|
#if DEBUG_ADD_INTERSECTING_TS
|
2012-03-28 16:20:21 +00:00
|
|
|
static void debugShowLineIntersection(int pts, const WorkEdge& wt,
|
|
|
|
const WorkEdge& wn, const double wtTs[2], const double wnTs[2]) {
|
|
|
|
if (!pts) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkPoint wtOutPt, wnOutPt;
|
|
|
|
LineXYAtT(wt.fPts, wtTs[0], &wtOutPt);
|
|
|
|
LineXYAtT(wn.fPts, wnTs[0], &wnOutPt);
|
2012-04-10 18:28:55 +00:00
|
|
|
SkDebugf("%s wtTs[0]=%g (%g,%g, %g,%g) (%g,%g)\n",
|
2012-03-28 16:20:21 +00:00
|
|
|
__FUNCTION__,
|
|
|
|
wtTs[0], wt.fPts[0].fX, wt.fPts[0].fY,
|
2012-04-10 18:28:55 +00:00
|
|
|
wt.fPts[1].fX, wt.fPts[1].fY, wtOutPt.fX, wtOutPt.fY);
|
2012-03-28 16:20:21 +00:00
|
|
|
if (pts == 2) {
|
|
|
|
SkDebugf("%s wtTs[1]=%g\n", __FUNCTION__, wtTs[1]);
|
|
|
|
}
|
2012-04-10 18:28:55 +00:00
|
|
|
SkDebugf("%s wnTs[0]=%g (%g,%g, %g,%g) (%g,%g)\n",
|
2012-03-28 16:20:21 +00:00
|
|
|
__FUNCTION__,
|
|
|
|
wnTs[0], wn.fPts[0].fX, wn.fPts[0].fY,
|
2012-04-10 18:28:55 +00:00
|
|
|
wn.fPts[1].fX, wn.fPts[1].fY, wnOutPt.fX, wnOutPt.fY);
|
2012-03-28 16:20:21 +00:00
|
|
|
if (pts == 2) {
|
|
|
|
SkDebugf("%s wnTs[1]=%g\n", __FUNCTION__, wnTs[1]);
|
|
|
|
}
|
|
|
|
}
|
2012-06-01 17:44:28 +00:00
|
|
|
#else
|
|
|
|
static void debugShowLineIntersection(int , const WorkEdge& ,
|
|
|
|
const WorkEdge& , const double [2], const double [2]) {
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-28 16:20:21 +00:00
|
|
|
|
2012-02-09 22:04:27 +00:00
|
|
|
static void addIntersectingTs(InEdge** currentPtr, InEdge** lastPtr) {
|
2012-02-28 16:57:05 +00:00
|
|
|
InEdge** testPtr = currentPtr - 1;
|
2012-03-22 21:11:17 +00:00
|
|
|
// FIXME: lastPtr should be past the point of interest, so
|
|
|
|
// test below should be lastPtr - 2
|
|
|
|
// that breaks testSimplifyTriangle22, so further investigation is needed
|
2012-02-28 16:57:05 +00:00
|
|
|
while (++testPtr != lastPtr - 1) {
|
|
|
|
InEdge* test = *testPtr;
|
|
|
|
InEdge** nextPtr = testPtr;
|
|
|
|
do {
|
|
|
|
InEdge* next = *++nextPtr;
|
2012-03-30 18:47:02 +00:00
|
|
|
// FIXME: this compares against the sentinel sometimes
|
|
|
|
// OPTIMIZATION: this may never be needed since this gets called
|
|
|
|
// in two passes now. Verify that double hits are appropriate.
|
2012-02-28 16:57:05 +00:00
|
|
|
if (test->cached(next)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!Bounds::Intersects(test->fBounds, next->fBounds)) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-09 22:04:27 +00:00
|
|
|
WorkEdge wt, wn;
|
|
|
|
wt.init(test);
|
|
|
|
wn.init(next);
|
|
|
|
do {
|
2012-03-28 16:20:21 +00:00
|
|
|
int pts;
|
|
|
|
Intersections ts;
|
|
|
|
bool swap = false;
|
|
|
|
switch (wt.verb()) {
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
switch (wn.verb()) {
|
|
|
|
case SkPath::kLine_Verb: {
|
|
|
|
pts = LineIntersect(wt.fPts, wn.fPts, ts);
|
|
|
|
debugShowLineIntersection(pts, wt, wn,
|
|
|
|
ts.fT[0], ts.fT[1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kQuad_Verb: {
|
|
|
|
swap = true;
|
|
|
|
pts = QuadLineIntersect(wn.fPts, wt.fPts, ts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kCubic_Verb: {
|
|
|
|
swap = true;
|
|
|
|
pts = CubicLineIntersect(wn.fPts, wt.fPts, ts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
2012-03-28 16:20:21 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
switch (wn.verb()) {
|
|
|
|
case SkPath::kLine_Verb: {
|
|
|
|
pts = QuadLineIntersect(wt.fPts, wn.fPts, ts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kQuad_Verb: {
|
|
|
|
pts = QuadIntersect(wt.fPts, wn.fPts, ts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kCubic_Verb: {
|
|
|
|
// FIXME: promote quad to cubic
|
|
|
|
pts = CubicIntersect(wt.fPts, wn.fPts, ts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
2012-03-28 16:20:21 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
switch (wn.verb()) {
|
|
|
|
case SkPath::kLine_Verb: {
|
|
|
|
pts = CubicLineIntersect(wt.fPts, wn.fPts, ts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kQuad_Verb: {
|
|
|
|
// FIXME: promote quad to cubic
|
|
|
|
pts = CubicIntersect(wt.fPts, wn.fPts, ts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kCubic_Verb: {
|
|
|
|
pts = CubicIntersect(wt.fPts, wn.fPts, ts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-03-28 16:20:21 +00:00
|
|
|
test->add(ts.fT[swap], pts, wt.verbIndex());
|
|
|
|
next->add(ts.fT[!swap], pts, wn.verbIndex());
|
2012-02-28 16:57:05 +00:00
|
|
|
} while (wt.bottom() <= wn.bottom() ? wt.advance() : wn.advance());
|
|
|
|
} while (nextPtr != lastPtr);
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
static InEdge** advanceEdges(SkTDArray<ActiveEdge>* activeEdges,
|
2012-02-15 22:01:16 +00:00
|
|
|
InEdge** currentPtr, InEdge** lastPtr, SkScalar y) {
|
|
|
|
InEdge** testPtr = currentPtr - 1;
|
|
|
|
while (++testPtr != lastPtr) {
|
|
|
|
if ((*testPtr)->fBounds.fBottom > y) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
if (activeEdges) {
|
|
|
|
InEdge* test = *testPtr;
|
|
|
|
ActiveEdge* activePtr = activeEdges->begin() - 1;
|
|
|
|
ActiveEdge* lastActive = activeEdges->end();
|
|
|
|
while (++activePtr != lastActive) {
|
|
|
|
if (activePtr->fWorkEdge.fEdge == test) {
|
|
|
|
activeEdges->remove(activePtr - activeEdges->begin());
|
|
|
|
break;
|
|
|
|
}
|
2012-02-15 22:01:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (testPtr == currentPtr) {
|
|
|
|
++currentPtr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return currentPtr;
|
|
|
|
}
|
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
// OPTIMIZE: inline?
|
|
|
|
static HorizontalEdge** advanceHorizontal(HorizontalEdge** edge, SkScalar y) {
|
|
|
|
while ((*edge)->fY < y) {
|
|
|
|
++edge;
|
|
|
|
}
|
|
|
|
return edge;
|
|
|
|
}
|
|
|
|
|
2012-02-09 22:04:27 +00:00
|
|
|
// compute bottom taking into account any intersected edges
|
2012-03-20 21:11:59 +00:00
|
|
|
static SkScalar computeInterceptBottom(SkTDArray<ActiveEdge>& activeEdges,
|
|
|
|
SkScalar y, SkScalar bottom) {
|
2012-02-09 22:04:27 +00:00
|
|
|
ActiveEdge* activePtr = activeEdges.begin() - 1;
|
|
|
|
ActiveEdge* lastActive = activeEdges.end();
|
|
|
|
while (++activePtr != lastActive) {
|
|
|
|
const InEdge* test = activePtr->fWorkEdge.fEdge;
|
|
|
|
if (!test->fContainsIntercepts) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
WorkEdge wt;
|
|
|
|
wt.init(test);
|
|
|
|
do {
|
|
|
|
const Intercepts& intercepts = test->fIntercepts[wt.verbIndex()];
|
2012-03-05 22:01:21 +00:00
|
|
|
if (intercepts.fTopIntercepts > 1) {
|
|
|
|
SkScalar yTop = wt.fPts[0].fY;
|
|
|
|
if (yTop > y && bottom > yTop) {
|
|
|
|
bottom = yTop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (intercepts.fBottomIntercepts > 1) {
|
|
|
|
SkScalar yBottom = wt.fPts[wt.verb()].fY;
|
|
|
|
if (yBottom > y && bottom > yBottom) {
|
|
|
|
bottom = yBottom;
|
|
|
|
}
|
|
|
|
}
|
2012-02-09 22:04:27 +00:00
|
|
|
const SkTDArray<double>& fTs = intercepts.fTs;
|
|
|
|
size_t count = fTs.count();
|
|
|
|
for (size_t index = 0; index < count; ++index) {
|
2012-03-28 16:20:21 +00:00
|
|
|
SkScalar yIntercept;
|
|
|
|
switch (wt.verb()) {
|
|
|
|
case SkPath::kLine_Verb: {
|
|
|
|
yIntercept = LineYAtT(wt.fPts, fTs[index]);
|
|
|
|
break;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-03-28 16:20:21 +00:00
|
|
|
case SkPath::kQuad_Verb: {
|
|
|
|
yIntercept = QuadYAtT(wt.fPts, fTs[index]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kCubic_Verb: {
|
|
|
|
yIntercept = CubicYAtT(wt.fPts, fTs[index]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SkASSERT(0); // should never get here
|
|
|
|
}
|
|
|
|
if (yIntercept > y && bottom > yIntercept) {
|
|
|
|
bottom = yIntercept;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-28 16:57:05 +00:00
|
|
|
} while (wt.advance());
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
#if DEBUG_BOTTOM
|
|
|
|
SkDebugf("%s bottom=%1.9g\n", __FUNCTION__, bottom);
|
|
|
|
#endif
|
2012-03-20 21:11:59 +00:00
|
|
|
return bottom;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static SkScalar findBottom(InEdge** currentPtr,
|
2012-03-20 21:11:59 +00:00
|
|
|
InEdge** edgeListEnd, SkTDArray<ActiveEdge>* activeEdges, SkScalar y,
|
2012-06-01 17:44:28 +00:00
|
|
|
bool /*asFill*/, InEdge**& testPtr) {
|
2012-02-09 22:04:27 +00:00
|
|
|
InEdge* current = *currentPtr;
|
|
|
|
SkScalar bottom = current->fBounds.fBottom;
|
2012-03-22 21:11:17 +00:00
|
|
|
|
2012-02-09 22:04:27 +00:00
|
|
|
// find the list of edges that cross y
|
2012-02-15 22:01:16 +00:00
|
|
|
InEdge* test = *testPtr;
|
|
|
|
while (testPtr != edgeListEnd) {
|
|
|
|
SkScalar testTop = test->fBounds.fTop;
|
|
|
|
if (bottom <= testTop) {
|
2012-02-09 22:04:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-02-15 22:01:16 +00:00
|
|
|
SkScalar testBottom = test->fBounds.fBottom;
|
2012-02-09 22:04:27 +00:00
|
|
|
// OPTIMIZATION: Shortening the bottom is only interesting when filling
|
|
|
|
// and when the edge is to the left of a longer edge. If it's a framing
|
|
|
|
// edge, or part of the right, it won't effect the longer edges.
|
2012-02-15 22:01:16 +00:00
|
|
|
if (testTop > y) {
|
|
|
|
bottom = testTop;
|
|
|
|
break;
|
2012-08-23 18:14:13 +00:00
|
|
|
}
|
2012-02-15 22:01:16 +00:00
|
|
|
if (y < testBottom) {
|
|
|
|
if (bottom > testBottom) {
|
|
|
|
bottom = testBottom;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
if (activeEdges) {
|
|
|
|
addToActive(*activeEdges, test);
|
|
|
|
}
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-02-15 22:01:16 +00:00
|
|
|
test = *++testPtr;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-03-30 18:47:02 +00:00
|
|
|
#if DEBUG_BOTTOM
|
|
|
|
SkDebugf("%s %d bottom=%1.9g\n", __FUNCTION__, activeEdges ? 2 : 1, bottom);
|
|
|
|
#endif
|
2012-02-09 22:04:27 +00:00
|
|
|
return bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void makeEdgeList(SkTArray<InEdge>& edges, InEdge& edgeSentinel,
|
|
|
|
SkTDArray<InEdge*>& edgeList) {
|
2012-02-03 22:07:47 +00:00
|
|
|
size_t edgeCount = edges.count();
|
|
|
|
if (edgeCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2012-04-10 18:28:55 +00:00
|
|
|
int id = 0;
|
2012-02-03 22:07:47 +00:00
|
|
|
for (size_t index = 0; index < edgeCount; ++index) {
|
2012-04-10 18:28:55 +00:00
|
|
|
InEdge& edge = edges[index];
|
|
|
|
if (!edge.fWinding) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
edge.fID = ++id;
|
|
|
|
*edgeList.append() = &edge;
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|
|
|
|
*edgeList.append() = &edgeSentinel;
|
2012-03-01 19:16:31 +00:00
|
|
|
QSort<InEdge>(edgeList.begin(), edgeList.end() - 1);
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
|
|
|
|
2012-03-20 21:11:59 +00:00
|
|
|
static void makeHorizontalList(SkTDArray<HorizontalEdge>& edges,
|
|
|
|
HorizontalEdge& edgeSentinel, SkTDArray<HorizontalEdge*>& edgeList) {
|
|
|
|
size_t edgeCount = edges.count();
|
|
|
|
if (edgeCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (size_t index = 0; index < edgeCount; ++index) {
|
|
|
|
*edgeList.append() = &edges[index];
|
|
|
|
}
|
|
|
|
edgeSentinel.fLeft = edgeSentinel.fRight = edgeSentinel.fY = SK_ScalarMax;
|
|
|
|
*edgeList.append() = &edgeSentinel;
|
|
|
|
QSort<HorizontalEdge>(edgeList.begin(), edgeList.end() - 1);
|
|
|
|
}
|
2012-02-16 21:24:41 +00:00
|
|
|
|
|
|
|
static void skipCoincidence(int lastWinding, int winding, int windingMask,
|
|
|
|
ActiveEdge* activePtr, ActiveEdge* firstCoincident) {
|
2012-12-10 12:50:53 +00:00
|
|
|
if (((lastWinding & windingMask) == 0) ^ ((winding & windingMask) != 0)) {
|
2012-02-16 21:24:41 +00:00
|
|
|
return;
|
2012-08-23 18:14:13 +00:00
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
// FIXME: ? shouldn't this be if (lastWinding & windingMask) ?
|
2012-02-16 21:24:41 +00:00
|
|
|
if (lastWinding) {
|
2012-03-22 21:11:17 +00:00
|
|
|
#if DEBUG_ADJUST_COINCIDENT
|
|
|
|
SkDebugf("%s edge=%d 1 set skip=false\n", __FUNCTION__, activePtr->ID());
|
|
|
|
#endif
|
2012-02-16 21:24:41 +00:00
|
|
|
activePtr->fSkip = false;
|
|
|
|
} else {
|
2012-03-22 21:11:17 +00:00
|
|
|
#if DEBUG_ADJUST_COINCIDENT
|
|
|
|
SkDebugf("%s edge=%d 2 set skip=false\n", __FUNCTION__, firstCoincident->ID());
|
|
|
|
#endif
|
2012-02-16 21:24:41 +00:00
|
|
|
firstCoincident->fSkip = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-15 22:01:16 +00:00
|
|
|
static void sortHorizontal(SkTDArray<ActiveEdge>& activeEdges,
|
2012-03-20 21:11:59 +00:00
|
|
|
SkTDArray<ActiveEdge*>& edgeList, SkScalar y) {
|
2012-02-15 22:01:16 +00:00
|
|
|
size_t edgeCount = activeEdges.count();
|
|
|
|
if (edgeCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
#if DEBUG_SORT_HORIZONTAL
|
2012-03-27 13:23:51 +00:00
|
|
|
const int tab = 3; // FIXME: debugging only
|
2012-03-20 21:11:59 +00:00
|
|
|
SkDebugf("%s y=%1.9g\n", __FUNCTION__, y);
|
|
|
|
#endif
|
2012-02-15 22:01:16 +00:00
|
|
|
size_t index;
|
|
|
|
for (index = 0; index < edgeCount; ++index) {
|
|
|
|
ActiveEdge& activeEdge = activeEdges[index];
|
2012-03-20 21:11:59 +00:00
|
|
|
do {
|
|
|
|
activeEdge.calcLeft(y);
|
|
|
|
// skip segments that don't span y
|
|
|
|
if (activeEdge.fAbove != activeEdge.fBelow) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (activeEdge.fDone) {
|
|
|
|
#if DEBUG_SORT_HORIZONTAL
|
|
|
|
SkDebugf("%*s edge=%d done\n", tab, "", activeEdge.ID());
|
|
|
|
#endif
|
|
|
|
goto nextEdge;
|
|
|
|
}
|
|
|
|
#if DEBUG_SORT_HORIZONTAL
|
|
|
|
SkDebugf("%*s edge=%d above==below\n", tab, "", activeEdge.ID());
|
|
|
|
#endif
|
|
|
|
} while (activeEdge.advanceT() || activeEdge.advance());
|
|
|
|
#if DEBUG_SORT_HORIZONTAL
|
|
|
|
SkDebugf("%*s edge=%d above=(%1.9g,%1.9g) (%1.9g) below=(%1.9g,%1.9g)"
|
|
|
|
" (%1.9g)\n", tab, "", activeEdge.ID(),
|
|
|
|
activeEdge.fAbove.fX, activeEdge.fAbove.fY, activeEdge.fTAbove,
|
|
|
|
activeEdge.fBelow.fX, activeEdge.fBelow.fY, activeEdge.fTBelow);
|
|
|
|
#endif
|
|
|
|
activeEdge.fSkip = activeEdge.fCloseCall = activeEdge.fFixBelow = false;
|
2012-02-15 22:01:16 +00:00
|
|
|
*edgeList.append() = &activeEdge;
|
2012-03-20 21:11:59 +00:00
|
|
|
nextEdge:
|
|
|
|
;
|
2012-02-15 22:01:16 +00:00
|
|
|
}
|
2012-03-01 19:16:31 +00:00
|
|
|
QSort<ActiveEdge>(edgeList.begin(), edgeList.end() - 1);
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove coincident edges
|
|
|
|
// OPTIMIZE: remove edges? This is tricky because the current logic expects
|
|
|
|
// the winding count to be maintained while skipping coincident edges. In
|
|
|
|
// addition to removing the coincident edges, the remaining edges would need
|
|
|
|
// to have a different winding value, possibly different per intercept span.
|
|
|
|
static SkScalar adjustCoincident(SkTDArray<ActiveEdge*>& edgeList,
|
|
|
|
int windingMask, SkScalar y, SkScalar bottom, OutEdgeBuilder& outBuilder)
|
|
|
|
{
|
|
|
|
#if DEBUG_ADJUST_COINCIDENT
|
|
|
|
SkDebugf("%s y=%1.9g bottom=%1.9g\n", __FUNCTION__, y, bottom);
|
|
|
|
#endif
|
|
|
|
size_t edgeCount = edgeList.count();
|
|
|
|
if (edgeCount == 0) {
|
|
|
|
return bottom;
|
|
|
|
}
|
2012-04-17 11:40:34 +00:00
|
|
|
ActiveEdge* activePtr, * nextPtr = edgeList[0];
|
2012-03-20 21:11:59 +00:00
|
|
|
size_t index;
|
|
|
|
bool foundCoincident = false;
|
2012-06-01 18:20:10 +00:00
|
|
|
size_t firstIndex = 0;
|
2012-03-20 21:11:59 +00:00
|
|
|
for (index = 1; index < edgeCount; ++index) {
|
2012-04-17 11:40:34 +00:00
|
|
|
activePtr = nextPtr;
|
|
|
|
nextPtr = edgeList[index];
|
2012-04-26 21:01:06 +00:00
|
|
|
if (firstIndex != index - 1 && activePtr->fVerb > SkPath::kLine_Verb
|
|
|
|
&& nextPtr->fVerb == SkPath::kLine_Verb
|
|
|
|
&& activePtr->isUnordered(nextPtr)) {
|
|
|
|
// swap the line with the curve
|
|
|
|
// back up to the previous edge and retest
|
|
|
|
SkTSwap<ActiveEdge*>(edgeList[index - 1], edgeList[index]);
|
|
|
|
SkASSERT(index > 1);
|
|
|
|
index -= 2;
|
|
|
|
nextPtr = edgeList[index];
|
|
|
|
continue;
|
2012-04-17 11:40:34 +00:00
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
bool closeCall = false;
|
|
|
|
activePtr->fCoincident = firstIndex;
|
2012-04-17 11:40:34 +00:00
|
|
|
if (activePtr->isCoincidentWith(nextPtr)
|
2012-03-20 21:11:59 +00:00
|
|
|
|| (closeCall = activePtr->tooCloseToCall(nextPtr))) {
|
|
|
|
activePtr->fSkip = nextPtr->fSkip = foundCoincident = true;
|
|
|
|
activePtr->fCloseCall = nextPtr->fCloseCall = closeCall;
|
2012-04-17 11:40:34 +00:00
|
|
|
} else if (activePtr->isUnordered(nextPtr)) {
|
|
|
|
foundCoincident = true;
|
2012-03-20 21:11:59 +00:00
|
|
|
} else {
|
|
|
|
firstIndex = index;
|
|
|
|
}
|
|
|
|
}
|
2012-04-17 11:40:34 +00:00
|
|
|
nextPtr->fCoincident = firstIndex;
|
2012-03-20 21:11:59 +00:00
|
|
|
if (!foundCoincident) {
|
|
|
|
return bottom;
|
|
|
|
}
|
2012-02-16 21:24:41 +00:00
|
|
|
int winding = 0;
|
2012-04-17 11:40:34 +00:00
|
|
|
nextPtr = edgeList[0];
|
2012-02-15 22:01:16 +00:00
|
|
|
for (index = 1; index < edgeCount; ++index) {
|
2012-03-20 21:11:59 +00:00
|
|
|
int priorWinding = winding;
|
2012-02-16 21:24:41 +00:00
|
|
|
winding += activePtr->fWorkEdge.winding();
|
2012-04-17 11:40:34 +00:00
|
|
|
activePtr = nextPtr;
|
|
|
|
nextPtr = edgeList[index];
|
|
|
|
SkASSERT(activePtr == edgeList[index - 1]);
|
|
|
|
SkASSERT(nextPtr == edgeList[index]);
|
|
|
|
if (activePtr->fCoincident != nextPtr->fCoincident) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// the coincident edges may not have been sorted above -- advance
|
|
|
|
// the edges and resort if needed
|
|
|
|
// OPTIMIZE: if sorting is done incrementally as new edges are added
|
|
|
|
// and not all at once as is done here, fold this test into the
|
|
|
|
// current less than test.
|
|
|
|
while ((!activePtr->fSkip || !nextPtr->fSkip)
|
|
|
|
&& activePtr->fCoincident == nextPtr->fCoincident) {
|
|
|
|
if (activePtr->swapUnordered(nextPtr, bottom)) {
|
|
|
|
winding -= activePtr->fWorkEdge.winding();
|
|
|
|
SkASSERT(activePtr == edgeList[index - 1]);
|
|
|
|
SkASSERT(nextPtr == edgeList[index]);
|
|
|
|
SkTSwap<ActiveEdge*>(edgeList[index - 1], edgeList[index]);
|
|
|
|
if (--index == 0) {
|
|
|
|
winding += activePtr->fWorkEdge.winding();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// back up one
|
|
|
|
activePtr = edgeList[index - 1];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SkASSERT(activePtr == edgeList[index - 1]);
|
|
|
|
SkASSERT(nextPtr == edgeList[index]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (activePtr->fSkip && nextPtr->fSkip) {
|
2012-03-20 21:11:59 +00:00
|
|
|
if (activePtr->fCloseCall ? activePtr->swapClose(nextPtr,
|
|
|
|
priorWinding, winding, windingMask)
|
|
|
|
: activePtr->swapCoincident(nextPtr, bottom)) {
|
2012-03-05 22:01:21 +00:00
|
|
|
winding -= activePtr->fWorkEdge.winding();
|
2012-04-17 11:40:34 +00:00
|
|
|
SkASSERT(activePtr == edgeList[index - 1]);
|
|
|
|
SkASSERT(nextPtr == edgeList[index]);
|
2012-03-01 19:16:31 +00:00
|
|
|
SkTSwap<ActiveEdge*>(edgeList[index - 1], edgeList[index]);
|
|
|
|
SkTSwap<ActiveEdge*>(activePtr, nextPtr);
|
2012-03-05 22:01:21 +00:00
|
|
|
winding += activePtr->fWorkEdge.winding();
|
2012-04-17 11:40:34 +00:00
|
|
|
SkASSERT(activePtr == edgeList[index - 1]);
|
|
|
|
SkASSERT(nextPtr == edgeList[index]);
|
2012-03-01 19:16:31 +00:00
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
int firstCoincidentWinding = 0;
|
|
|
|
ActiveEdge* firstCoincident = NULL;
|
|
|
|
winding = 0;
|
|
|
|
activePtr = edgeList[0];
|
|
|
|
for (index = 1; index < edgeCount; ++index) {
|
|
|
|
int priorWinding = winding;
|
|
|
|
winding += activePtr->fWorkEdge.winding();
|
2012-04-17 11:40:34 +00:00
|
|
|
nextPtr = edgeList[index];
|
2012-08-23 18:14:13 +00:00
|
|
|
if (activePtr->fSkip && nextPtr->fSkip
|
2012-04-17 11:40:34 +00:00
|
|
|
&& activePtr->fCoincident == nextPtr->fCoincident) {
|
2012-02-16 21:24:41 +00:00
|
|
|
if (!firstCoincident) {
|
|
|
|
firstCoincident = activePtr;
|
2012-03-20 21:11:59 +00:00
|
|
|
firstCoincidentWinding = priorWinding;
|
|
|
|
}
|
|
|
|
if (activePtr->fCloseCall) {
|
|
|
|
// If one of the edges has already been added to out as a non
|
|
|
|
// coincident edge, trim it back to the top of this span
|
|
|
|
if (outBuilder.trimLine(y, activePtr->ID())) {
|
|
|
|
activePtr->addTatYAbove(y);
|
2012-03-22 21:11:17 +00:00
|
|
|
#if DEBUG_ADJUST_COINCIDENT
|
|
|
|
SkDebugf("%s 1 edge=%d y=%1.9g (was fYBottom=%1.9g)\n",
|
|
|
|
__FUNCTION__, activePtr->ID(), y, activePtr->fYBottom);
|
|
|
|
#endif
|
2012-03-20 21:11:59 +00:00
|
|
|
activePtr->fYBottom = y;
|
|
|
|
}
|
|
|
|
if (outBuilder.trimLine(y, nextPtr->ID())) {
|
|
|
|
nextPtr->addTatYAbove(y);
|
2012-03-22 21:11:17 +00:00
|
|
|
#if DEBUG_ADJUST_COINCIDENT
|
|
|
|
SkDebugf("%s 2 edge=%d y=%1.9g (was fYBottom=%1.9g)\n",
|
|
|
|
__FUNCTION__, nextPtr->ID(), y, nextPtr->fYBottom);
|
|
|
|
#endif
|
2012-03-20 21:11:59 +00:00
|
|
|
nextPtr->fYBottom = y;
|
|
|
|
}
|
|
|
|
// add missing t values so edges can be the same length
|
|
|
|
SkScalar testY = activePtr->fBelow.fY;
|
|
|
|
nextPtr->addTatYBelow(testY);
|
|
|
|
if (bottom > testY && testY > y) {
|
2012-03-22 21:11:17 +00:00
|
|
|
#if DEBUG_ADJUST_COINCIDENT
|
|
|
|
SkDebugf("%s 3 edge=%d bottom=%1.9g (was bottom=%1.9g)\n",
|
|
|
|
__FUNCTION__, activePtr->ID(), testY, bottom);
|
|
|
|
#endif
|
2012-03-20 21:11:59 +00:00
|
|
|
bottom = testY;
|
|
|
|
}
|
|
|
|
testY = nextPtr->fBelow.fY;
|
|
|
|
activePtr->addTatYBelow(testY);
|
|
|
|
if (bottom > testY && testY > y) {
|
2012-03-22 21:11:17 +00:00
|
|
|
#if DEBUG_ADJUST_COINCIDENT
|
|
|
|
SkDebugf("%s 4 edge=%d bottom=%1.9g (was bottom=%1.9g)\n",
|
|
|
|
__FUNCTION__, nextPtr->ID(), testY, bottom);
|
|
|
|
#endif
|
2012-03-20 21:11:59 +00:00
|
|
|
bottom = testY;
|
|
|
|
}
|
2012-02-16 21:24:41 +00:00
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
} else if (firstCoincident) {
|
|
|
|
skipCoincidence(firstCoincidentWinding, winding, windingMask,
|
|
|
|
activePtr, firstCoincident);
|
2012-02-16 21:24:41 +00:00
|
|
|
firstCoincident = NULL;
|
|
|
|
}
|
2012-02-15 22:01:16 +00:00
|
|
|
activePtr = nextPtr;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
if (firstCoincident) {
|
2012-02-16 21:24:41 +00:00
|
|
|
winding += activePtr->fWorkEdge.winding();
|
2012-03-20 21:11:59 +00:00
|
|
|
skipCoincidence(firstCoincidentWinding, winding, windingMask, activePtr,
|
2012-02-16 21:24:41 +00:00
|
|
|
firstCoincident);
|
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
// fix up the bottom for close call edges. OPTIMIZATION: maybe this could
|
|
|
|
// be in the loop above, but moved here since loop above reads fBelow and
|
|
|
|
// it felt unsafe to write it in that loop
|
|
|
|
for (index = 0; index < edgeCount; ++index) {
|
|
|
|
(edgeList[index])->fixBelow();
|
|
|
|
}
|
|
|
|
return bottom;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
2012-02-07 22:10:51 +00:00
|
|
|
|
2012-02-09 22:04:27 +00:00
|
|
|
// stitch edge and t range that satisfies operation
|
2012-08-23 18:14:13 +00:00
|
|
|
static void stitchEdge(SkTDArray<ActiveEdge*>& edgeList, SkScalar
|
2012-06-01 17:44:28 +00:00
|
|
|
#if DEBUG_STITCH_EDGE
|
|
|
|
y
|
|
|
|
#endif
|
|
|
|
,
|
2012-03-22 21:11:17 +00:00
|
|
|
SkScalar bottom, int windingMask, bool fill, OutEdgeBuilder& outBuilder) {
|
2012-02-09 22:04:27 +00:00
|
|
|
int winding = 0;
|
2012-02-15 22:01:16 +00:00
|
|
|
ActiveEdge** activeHandle = edgeList.begin() - 1;
|
|
|
|
ActiveEdge** lastActive = edgeList.end();
|
2012-04-17 11:40:34 +00:00
|
|
|
#if DEBUG_STITCH_EDGE
|
2012-06-01 17:44:28 +00:00
|
|
|
const int tab = 7; // FIXME: debugging only
|
2012-04-17 11:40:34 +00:00
|
|
|
SkDebugf("%s y=%1.9g bottom=%1.9g\n", __FUNCTION__, y, bottom);
|
|
|
|
#endif
|
2012-02-15 22:01:16 +00:00
|
|
|
while (++activeHandle != lastActive) {
|
|
|
|
ActiveEdge* activePtr = *activeHandle;
|
2012-02-09 22:04:27 +00:00
|
|
|
const WorkEdge& wt = activePtr->fWorkEdge;
|
|
|
|
int lastWinding = winding;
|
|
|
|
winding += wt.winding();
|
2012-04-17 11:40:34 +00:00
|
|
|
#if DEBUG_STITCH_EDGE
|
|
|
|
SkDebugf("%*s edge=%d lastWinding=%d winding=%d skip=%d close=%d"
|
|
|
|
" above=%1.9g below=%1.9g\n",
|
|
|
|
tab-4, "", activePtr->ID(), lastWinding,
|
|
|
|
winding, activePtr->fSkip, activePtr->fCloseCall,
|
|
|
|
activePtr->fTAbove, activePtr->fTBelow);
|
2012-03-20 21:11:59 +00:00
|
|
|
#endif
|
2012-03-22 21:11:17 +00:00
|
|
|
if (activePtr->done(bottom)) {
|
2012-04-17 11:40:34 +00:00
|
|
|
#if DEBUG_STITCH_EDGE
|
|
|
|
SkDebugf("%*s fDone=%d || fYBottom=%1.9g >= bottom\n", tab, "",
|
|
|
|
activePtr->fDone, activePtr->fYBottom);
|
|
|
|
#endif
|
2012-03-22 21:11:17 +00:00
|
|
|
continue;
|
2012-02-28 16:57:05 +00:00
|
|
|
}
|
2012-02-20 21:33:22 +00:00
|
|
|
int opener = (lastWinding & windingMask) == 0;
|
|
|
|
bool closer = (winding & windingMask) == 0;
|
|
|
|
SkASSERT(!opener | !closer);
|
|
|
|
bool inWinding = opener | closer;
|
2012-03-28 16:20:21 +00:00
|
|
|
SkPoint clippedPts[4];
|
2012-03-05 22:01:21 +00:00
|
|
|
const SkPoint* clipped = NULL;
|
2012-02-28 16:57:05 +00:00
|
|
|
bool moreToDo, aboveBottom;
|
2012-02-09 22:04:27 +00:00
|
|
|
do {
|
|
|
|
double currentT = activePtr->t();
|
|
|
|
const SkPoint* points = wt.fPts;
|
2012-02-28 16:57:05 +00:00
|
|
|
double nextT;
|
2012-04-26 21:01:06 +00:00
|
|
|
SkPath::Verb verb = activePtr->fVerb;
|
2012-02-07 22:10:51 +00:00
|
|
|
do {
|
2012-02-28 16:57:05 +00:00
|
|
|
nextT = activePtr->nextT();
|
2012-08-23 18:14:13 +00:00
|
|
|
// FIXME: obtuse: want efficient way to say
|
2012-03-28 16:20:21 +00:00
|
|
|
// !currentT && currentT != 1 || !nextT && nextT != 1
|
|
|
|
if (currentT * nextT != 0 || currentT + nextT != 1) {
|
2012-08-23 18:14:13 +00:00
|
|
|
// OPTIMIZATION: if !inWinding, we only need
|
2012-03-28 16:20:21 +00:00
|
|
|
// clipped[1].fY
|
|
|
|
switch (verb) {
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
LineSubDivide(points, currentT, nextT, clippedPts);
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
QuadSubDivide(points, currentT, nextT, clippedPts);
|
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
CubicSubDivide(points, currentT, nextT, clippedPts);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
break;
|
2012-02-07 22:10:51 +00:00
|
|
|
}
|
2012-03-28 16:20:21 +00:00
|
|
|
clipped = clippedPts;
|
|
|
|
} else {
|
|
|
|
clipped = points;
|
|
|
|
}
|
|
|
|
if (inWinding && !activePtr->fSkip && (fill ? clipped[0].fY
|
|
|
|
!= clipped[verb].fY : clipped[0] != clipped[verb])) {
|
2012-04-10 18:28:55 +00:00
|
|
|
#if DEBUG_STITCH_EDGE
|
|
|
|
SkDebugf("%*s add%s %1.9g,%1.9g %1.9g,%1.9g edge=%d"
|
|
|
|
" v=%d t=(%1.9g,%1.9g)\n", tab, "",
|
|
|
|
kUVerbStr[verb], clipped[0].fX, clipped[0].fY,
|
|
|
|
clipped[verb].fX, clipped[verb].fY,
|
|
|
|
activePtr->ID(),
|
|
|
|
activePtr->fWorkEdge.fVerb
|
|
|
|
- activePtr->fWorkEdge.fEdge->fVerbs.begin(),
|
|
|
|
currentT, nextT);
|
|
|
|
#endif
|
2012-03-28 16:20:21 +00:00
|
|
|
outBuilder.addCurve(clipped, (SkPath::Verb) verb,
|
|
|
|
activePtr->fWorkEdge.fEdge->fID,
|
|
|
|
activePtr->fCloseCall);
|
2012-02-28 16:57:05 +00:00
|
|
|
} else {
|
2012-04-10 18:28:55 +00:00
|
|
|
#if DEBUG_STITCH_EDGE
|
|
|
|
SkDebugf("%*s skip%s %1.9g,%1.9g %1.9g,%1.9g"
|
|
|
|
" edge=%d v=%d t=(%1.9g,%1.9g)\n", tab, "",
|
|
|
|
kUVerbStr[verb], clipped[0].fX, clipped[0].fY,
|
|
|
|
clipped[verb].fX, clipped[verb].fY,
|
|
|
|
activePtr->ID(),
|
|
|
|
activePtr->fWorkEdge.fVerb
|
|
|
|
- activePtr->fWorkEdge.fEdge->fVerbs.begin(),
|
|
|
|
currentT, nextT);
|
|
|
|
#endif
|
2012-03-28 16:20:21 +00:00
|
|
|
}
|
|
|
|
// by advancing fAbove/fBelow, the next call to sortHorizontal
|
|
|
|
// will use these values if they're still valid instead of
|
|
|
|
// recomputing
|
2012-04-17 11:40:34 +00:00
|
|
|
if (clipped[verb].fY > activePtr->fBelow.fY
|
2012-04-26 21:01:06 +00:00
|
|
|
&& bottom >= activePtr->fBelow.fY
|
|
|
|
&& verb == SkPath::kLine_Verb) {
|
2012-03-28 16:20:21 +00:00
|
|
|
activePtr->fAbove = activePtr->fBelow;
|
2012-04-26 21:01:06 +00:00
|
|
|
activePtr->fBelow = activePtr->fTangent = clipped[verb];
|
2012-04-17 11:40:34 +00:00
|
|
|
activePtr->fTAbove = activePtr->fTBelow < 1
|
|
|
|
? activePtr->fTBelow : 0;
|
2012-03-28 16:20:21 +00:00
|
|
|
activePtr->fTBelow = nextT;
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
|
|
|
currentT = nextT;
|
2012-02-28 16:57:05 +00:00
|
|
|
moreToDo = activePtr->advanceT();
|
2012-08-23 18:14:13 +00:00
|
|
|
activePtr->fYBottom = clipped[verb].fY; // was activePtr->fCloseCall ? bottom :
|
2012-03-20 21:11:59 +00:00
|
|
|
|
|
|
|
// clearing the fSkip/fCloseCall bit here means that trailing edges
|
|
|
|
// fall out of sync, if one edge is long and another is a series of short pieces
|
|
|
|
// if fSkip/fCloseCall is set, need to recompute coincidence/too-close-to-call
|
|
|
|
// after advancing
|
|
|
|
// another approach would be to restrict bottom to smaller part of close call
|
|
|
|
// maybe this is already happening with coincidence when intersection is computed,
|
|
|
|
// and needs to be added to the close call computation as well
|
|
|
|
// this is hard to do because that the bottom is important is not known when
|
|
|
|
// the lines are intersected; only when the computation for edge sorting is done
|
|
|
|
// does the need for new bottoms become apparent.
|
|
|
|
// maybe this is good incentive to scrap the current sort and do an insertion
|
|
|
|
// sort that can take this into consideration when the x value is computed
|
|
|
|
|
|
|
|
// FIXME: initialized in sortHorizontal, cleared here as well so
|
|
|
|
// that next edge is not skipped -- but should skipped edges ever
|
|
|
|
// continue? (probably not)
|
2012-03-22 21:11:17 +00:00
|
|
|
aboveBottom = clipped[verb].fY < bottom;
|
|
|
|
if (clipped[0].fY != clipped[verb].fY) {
|
|
|
|
activePtr->fSkip = false;
|
|
|
|
activePtr->fCloseCall = false;
|
|
|
|
aboveBottom &= !activePtr->fCloseCall;
|
2012-04-17 11:40:34 +00:00
|
|
|
}
|
|
|
|
#if DEBUG_STITCH_EDGE
|
|
|
|
else {
|
2012-03-22 21:11:17 +00:00
|
|
|
if (activePtr->fSkip || activePtr->fCloseCall) {
|
2012-04-17 11:40:34 +00:00
|
|
|
SkDebugf("%s skip or close == %1.9g\n", __FUNCTION__,
|
|
|
|
clippedPts[0].fY);
|
2012-03-22 21:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-17 11:40:34 +00:00
|
|
|
#endif
|
2012-02-28 16:57:05 +00:00
|
|
|
} while (moreToDo & aboveBottom);
|
|
|
|
} while ((moreToDo || activePtr->advance()) & aboveBottom);
|
2012-02-09 22:04:27 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 22:10:51 +00:00
|
|
|
|
2012-06-01 17:44:28 +00:00
|
|
|
#if DEBUG_DUMP
|
2012-03-30 18:47:02 +00:00
|
|
|
static void dumpEdgeList(const SkTDArray<InEdge*>& edgeList,
|
|
|
|
const InEdge& edgeSentinel) {
|
|
|
|
InEdge** debugPtr = edgeList.begin();
|
|
|
|
do {
|
|
|
|
(*debugPtr++)->dump();
|
|
|
|
} while (*debugPtr != &edgeSentinel);
|
|
|
|
}
|
2012-06-01 17:44:28 +00:00
|
|
|
#else
|
|
|
|
static void dumpEdgeList(const SkTDArray<InEdge*>& ,
|
|
|
|
const InEdge& ) {
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-30 18:47:02 +00:00
|
|
|
|
2012-02-09 22:04:27 +00:00
|
|
|
void simplify(const SkPath& path, bool asFill, SkPath& simple) {
|
|
|
|
// returns 1 for evenodd, -1 for winding, regardless of inverse-ness
|
|
|
|
int windingMask = (path.getFillType() & 1) ? 1 : -1;
|
|
|
|
simple.reset();
|
|
|
|
simple.setFillType(SkPath::kEvenOdd_FillType);
|
|
|
|
// turn path into list of edges increasing in y
|
2012-02-28 16:57:05 +00:00
|
|
|
// if an edge is a quad or a cubic with a y extrema, note it, but leave it
|
|
|
|
// unbroken. Once we have a list, sort it, then walk the list (walk edges
|
|
|
|
// twice that have y extrema's on top) and detect crossings -- look for raw
|
|
|
|
// bounds that cross over, then tight bounds that cross
|
2012-02-09 22:04:27 +00:00
|
|
|
SkTArray<InEdge> edges;
|
2012-03-20 21:11:59 +00:00
|
|
|
SkTDArray<HorizontalEdge> horizontalEdges;
|
|
|
|
InEdgeBuilder builder(path, asFill, edges, horizontalEdges);
|
2012-02-09 22:04:27 +00:00
|
|
|
SkTDArray<InEdge*> edgeList;
|
|
|
|
InEdge edgeSentinel;
|
2012-04-10 18:28:55 +00:00
|
|
|
edgeSentinel.reset();
|
2012-02-09 22:04:27 +00:00
|
|
|
makeEdgeList(edges, edgeSentinel, edgeList);
|
2012-03-20 21:11:59 +00:00
|
|
|
SkTDArray<HorizontalEdge*> horizontalList;
|
|
|
|
HorizontalEdge horizontalSentinel;
|
|
|
|
makeHorizontalList(horizontalEdges, horizontalSentinel, horizontalList);
|
2012-02-09 22:04:27 +00:00
|
|
|
InEdge** currentPtr = edgeList.begin();
|
2012-03-05 22:01:21 +00:00
|
|
|
if (!currentPtr) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-20 21:11:59 +00:00
|
|
|
// find all intersections between edges
|
|
|
|
// beyond looking for horizontal intercepts, we need to know if any active edges
|
|
|
|
// intersect edges below 'bottom', but above the active edge segment.
|
|
|
|
// maybe it makes more sense to compute all intercepts before doing anything
|
|
|
|
// else, since the intercept list is long-lived, at least in the current design.
|
|
|
|
SkScalar y = (*currentPtr)->fBounds.fTop;
|
|
|
|
HorizontalEdge** currentHorizontal = horizontalList.begin();
|
|
|
|
do {
|
|
|
|
InEdge** lastPtr = currentPtr; // find the edge below the bottom of the first set
|
|
|
|
SkScalar bottom = findBottom(currentPtr, edgeList.end(),
|
|
|
|
NULL, y, asFill, lastPtr);
|
|
|
|
if (lastPtr > currentPtr) {
|
|
|
|
if (currentHorizontal) {
|
|
|
|
if ((*currentHorizontal)->fY < SK_ScalarMax) {
|
|
|
|
addBottomT(currentPtr, lastPtr, currentHorizontal);
|
|
|
|
}
|
|
|
|
currentHorizontal = advanceHorizontal(currentHorizontal, bottom);
|
|
|
|
}
|
|
|
|
addIntersectingTs(currentPtr, lastPtr);
|
|
|
|
}
|
|
|
|
y = bottom;
|
|
|
|
currentPtr = advanceEdges(NULL, currentPtr, lastPtr, y);
|
|
|
|
} while (*currentPtr != &edgeSentinel);
|
2012-03-30 18:47:02 +00:00
|
|
|
// if a quadratic or cubic now has an intermediate T value, see if the Ts
|
|
|
|
// on either side cause the Y values to monotonically increase. If not, split
|
|
|
|
// the curve at the new T.
|
2012-04-26 21:01:06 +00:00
|
|
|
|
|
|
|
// try an alternate approach which does not split curves or stitch edges
|
|
|
|
// (may still need adjustCoincident, though)
|
|
|
|
// the idea is to output non-intersecting contours, then figure out their
|
|
|
|
// respective winding contribution
|
|
|
|
// each contour will need to know whether it is CW or CCW, and then whether
|
|
|
|
// a ray from that contour hits any a contour that contains it. The ray can
|
|
|
|
// move to the left and then arbitrarily move up or down (as long as it never
|
2012-08-23 18:14:13 +00:00
|
|
|
// moves to the right) to find a reference sibling contour or containing
|
2012-04-26 21:01:06 +00:00
|
|
|
// contour. If the contour is part of an intersection, the companion contour
|
|
|
|
// that is part of the intersection can determine the containership.
|
2012-03-30 18:47:02 +00:00
|
|
|
if (builder.containsCurves()) {
|
|
|
|
currentPtr = edgeList.begin();
|
|
|
|
SkTArray<InEdge> splits;
|
|
|
|
do {
|
2012-04-10 18:28:55 +00:00
|
|
|
(*currentPtr)->splitInflectionPts(splits);
|
2012-03-30 18:47:02 +00:00
|
|
|
} while (*++currentPtr != &edgeSentinel);
|
|
|
|
if (splits.count()) {
|
|
|
|
for (int index = 0; index < splits.count(); ++index) {
|
|
|
|
edges.push_back(splits[index]);
|
|
|
|
}
|
2012-04-10 18:28:55 +00:00
|
|
|
edgeList.reset();
|
2012-03-30 18:47:02 +00:00
|
|
|
makeEdgeList(edges, edgeSentinel, edgeList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dumpEdgeList(edgeList, edgeSentinel);
|
2012-02-09 22:04:27 +00:00
|
|
|
// walk the sorted edges from top to bottom, computing accumulated winding
|
|
|
|
SkTDArray<ActiveEdge> activeEdges;
|
|
|
|
OutEdgeBuilder outBuilder(asFill);
|
2012-03-20 21:11:59 +00:00
|
|
|
currentPtr = edgeList.begin();
|
|
|
|
y = (*currentPtr)->fBounds.fTop;
|
2012-02-09 22:04:27 +00:00
|
|
|
do {
|
|
|
|
InEdge** lastPtr = currentPtr; // find the edge below the bottom of the first set
|
|
|
|
SkScalar bottom = findBottom(currentPtr, edgeList.end(),
|
2012-03-20 21:11:59 +00:00
|
|
|
&activeEdges, y, asFill, lastPtr);
|
2012-02-20 21:33:22 +00:00
|
|
|
if (lastPtr > currentPtr) {
|
2012-03-20 21:11:59 +00:00
|
|
|
bottom = computeInterceptBottom(activeEdges, y, bottom);
|
2012-02-20 21:33:22 +00:00
|
|
|
SkTDArray<ActiveEdge*> activeEdgeList;
|
2012-03-20 21:11:59 +00:00
|
|
|
sortHorizontal(activeEdges, activeEdgeList, y);
|
|
|
|
bottom = adjustCoincident(activeEdgeList, windingMask, y, bottom,
|
|
|
|
outBuilder);
|
2012-03-22 21:11:17 +00:00
|
|
|
stitchEdge(activeEdgeList, y, bottom, windingMask, asFill, outBuilder);
|
2012-02-20 21:33:22 +00:00
|
|
|
}
|
2012-02-03 22:07:47 +00:00
|
|
|
y = bottom;
|
2012-03-20 21:11:59 +00:00
|
|
|
// OPTIMIZATION: as edges expire, InEdge allocations could be released
|
|
|
|
currentPtr = advanceEdges(&activeEdges, currentPtr, lastPtr, y);
|
2012-02-03 22:07:47 +00:00
|
|
|
} while (*currentPtr != &edgeSentinel);
|
|
|
|
// assemble output path from string of pts, verbs
|
2012-02-09 22:04:27 +00:00
|
|
|
outBuilder.bridge();
|
|
|
|
outBuilder.assemble(simple);
|
2012-02-03 22:07:47 +00:00
|
|
|
}
|