use pathops utils to improve precision of cubic chopping in scan converter
BUG=skia: Review URL: https://codereview.chromium.org/1113963002
This commit is contained in:
parent
30297c53bd
commit
dc3088570f
@ -225,6 +225,7 @@ bool SkEdgeClipper::clipQuad(const SkPoint srcPts[3], const SkRect& clip) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_CUBIC_CHOPPER
|
||||
static SkScalar eval_cubic_coeff(SkScalar A, SkScalar B, SkScalar C,
|
||||
SkScalar D, SkScalar t) {
|
||||
return SkScalarMulAdd(SkScalarMulAdd(SkScalarMulAdd(A, t, B), t, C), t, D);
|
||||
@ -274,23 +275,29 @@ static bool chopMonoCubicAtY(SkPoint pts[4], SkScalar y, SkScalar* t) {
|
||||
static bool chopMonoCubicAtX(SkPoint pts[4], SkScalar x, SkScalar* t) {
|
||||
return chopMonoCubicAt(pts[0].fX, pts[1].fX, pts[2].fX, pts[3].fX, x, t);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Modify pts[] in place so that it is clipped in Y to the clip rect
|
||||
static void chop_cubic_in_Y(SkPoint pts[4], const SkRect& clip) {
|
||||
|
||||
// are we partially above
|
||||
if (pts[0].fY < clip.fTop) {
|
||||
SkPoint tmp[7];
|
||||
#ifdef SK_SUPPORT_LEGACY_CUBIC_CHOPPER
|
||||
SkScalar t;
|
||||
if (chopMonoCubicAtY(pts, clip.fTop, &t)) {
|
||||
SkPoint tmp[7];
|
||||
SkChopCubicAt(pts, tmp, t);
|
||||
|
||||
// tmp[3, 4, 5].fY should all be to the below clip.fTop.
|
||||
#else
|
||||
if (SkChopMonoCubicAtY(pts, clip.fTop, tmp)) {
|
||||
#endif
|
||||
// tmp[3, 4].fY should all be to the below clip.fTop.
|
||||
// Since we can't trust the numerics of
|
||||
// the chopper, we force those conditions now
|
||||
tmp[3].fY = clip.fTop;
|
||||
clamp_ge(tmp[4].fY, clip.fTop);
|
||||
#ifdef SK_SUPPORT_LEGACY_CUBIC_CHOPPER
|
||||
clamp_ge(tmp[5].fY, clip.fTop);
|
||||
#endif
|
||||
|
||||
pts[0] = tmp[3];
|
||||
pts[1] = tmp[4];
|
||||
@ -306,10 +313,14 @@ static void chop_cubic_in_Y(SkPoint pts[4], const SkRect& clip) {
|
||||
|
||||
// are we partially below
|
||||
if (pts[3].fY > clip.fBottom) {
|
||||
SkPoint tmp[7];
|
||||
#ifdef SK_SUPPORT_LEGACY_CUBIC_CHOPPER
|
||||
SkScalar t;
|
||||
if (chopMonoCubicAtY(pts, clip.fBottom, &t)) {
|
||||
SkPoint tmp[7];
|
||||
SkChopCubicAt(pts, tmp, t);
|
||||
#else
|
||||
if (SkChopMonoCubicAtY(pts, clip.fBottom, tmp)) {
|
||||
#endif
|
||||
tmp[3].fY = clip.fBottom;
|
||||
clamp_le(tmp[2].fY, clip.fBottom);
|
||||
|
||||
@ -360,18 +371,24 @@ void SkEdgeClipper::clipMonoCubic(const SkPoint src[4], const SkRect& clip) {
|
||||
|
||||
// are we partially to the left
|
||||
if (pts[0].fX < clip.fLeft) {
|
||||
SkPoint tmp[7];
|
||||
#ifdef SK_SUPPORT_LEGACY_CUBIC_CHOPPER
|
||||
SkScalar t;
|
||||
if (chopMonoCubicAtX(pts, clip.fLeft, &t)) {
|
||||
SkPoint tmp[7];
|
||||
SkChopCubicAt(pts, tmp, t);
|
||||
#else
|
||||
if (SkChopMonoCubicAtX(pts, clip.fLeft, tmp)) {
|
||||
#endif
|
||||
this->appendVLine(clip.fLeft, tmp[0].fY, tmp[3].fY, reverse);
|
||||
|
||||
// tmp[3, 4, 5].fX should all be to the right of clip.fLeft.
|
||||
// tmp[3, 4].fX should all be to the right of clip.fLeft.
|
||||
// Since we can't trust the numerics of
|
||||
// the chopper, we force those conditions now
|
||||
tmp[3].fX = clip.fLeft;
|
||||
clamp_ge(tmp[4].fX, clip.fLeft);
|
||||
#ifdef SK_SUPPORT_LEGACY_CUBIC_CHOPPER
|
||||
clamp_ge(tmp[5].fX, clip.fLeft);
|
||||
#endif
|
||||
|
||||
pts[0] = tmp[3];
|
||||
pts[1] = tmp[4];
|
||||
@ -386,13 +403,19 @@ void SkEdgeClipper::clipMonoCubic(const SkPoint src[4], const SkRect& clip) {
|
||||
|
||||
// are we partially to the right
|
||||
if (pts[3].fX > clip.fRight) {
|
||||
SkPoint tmp[7];
|
||||
#ifdef SK_SUPPORT_LEGACY_CUBIC_CHOPPER
|
||||
SkScalar t;
|
||||
if (chopMonoCubicAtX(pts, clip.fRight, &t)) {
|
||||
SkPoint tmp[7];
|
||||
SkChopCubicAt(pts, tmp, t);
|
||||
#else
|
||||
if (SkChopMonoCubicAtX(pts, clip.fRight, tmp)) {
|
||||
#endif
|
||||
tmp[3].fX = clip.fRight;
|
||||
clamp_le(tmp[2].fX, clip.fRight);
|
||||
#ifdef SK_SUPPORT_LEGACY_CUBIC_CHOPPER
|
||||
clamp_le(tmp[1].fX, clip.fRight);
|
||||
#endif
|
||||
|
||||
this->appendCubic(tmp, reverse);
|
||||
this->appendVLine(clip.fRight, tmp[3].fY, tmp[6].fY, reverse);
|
||||
|
@ -916,6 +916,33 @@ int SkChopCubicAtMaxCurvature(const SkPoint src[4], SkPoint dst[13],
|
||||
return count + 1;
|
||||
}
|
||||
|
||||
#include "../pathops/SkPathOpsCubic.h"
|
||||
|
||||
typedef int (SkDCubic::*InterceptProc)(double intercept, double roots[3]) const;
|
||||
|
||||
static bool cubic_dchop_at_intercept(const SkPoint src[4], SkScalar intercept, SkPoint dst[7],
|
||||
InterceptProc method) {
|
||||
SkDCubic cubic;
|
||||
double roots[3];
|
||||
int count = (cubic.set(src).*method)(intercept, roots);
|
||||
if (count > 0) {
|
||||
SkDCubicPair pair = cubic.chopAt(roots[0]);
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
dst[i] = pair.pts[i].asSkPoint();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkChopMonoCubicAtY(SkPoint src[4], SkScalar y, SkPoint dst[7]) {
|
||||
return cubic_dchop_at_intercept(src, y, dst, &SkDCubic::horizontalIntersect);
|
||||
}
|
||||
|
||||
bool SkChopMonoCubicAtX(SkPoint src[4], SkScalar x, SkPoint dst[7]) {
|
||||
return cubic_dchop_at_intercept(src, x, dst, &SkDCubic::verticalIntersect);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Find t value for quadratic [a, b, c] = d.
|
||||
|
@ -166,6 +166,9 @@ int SkFindCubicMaxCurvature(const SkPoint src[4], SkScalar tValues[3]);
|
||||
int SkChopCubicAtMaxCurvature(const SkPoint src[4], SkPoint dst[13],
|
||||
SkScalar tValues[3] = NULL);
|
||||
|
||||
bool SkChopMonoCubicAtX(SkPoint src[4], SkScalar y, SkPoint dst[7]);
|
||||
bool SkChopMonoCubicAtY(SkPoint src[4], SkScalar x, SkPoint dst[7]);
|
||||
|
||||
enum SkCubicType {
|
||||
kSerpentine_SkCubicType,
|
||||
kCusp_SkCubicType,
|
||||
|
@ -425,3 +425,13 @@ int SkIntersections::intersectRay(const SkDCubic& cubic, const SkDLine& line) {
|
||||
}
|
||||
return fUsed;
|
||||
}
|
||||
|
||||
// SkDCubic accessors to Intersection utilities
|
||||
|
||||
int SkDCubic::horizontalIntersect(double yIntercept, double roots[3]) const {
|
||||
return LineCubicIntersections::HorizontalIntersect(*this, yIntercept, roots);
|
||||
}
|
||||
|
||||
int SkDCubic::verticalIntersect(double xIntercept, double roots[3]) const {
|
||||
return LineCubicIntersections::VerticalIntersect(*this, xIntercept, roots);
|
||||
}
|
||||
|
@ -97,6 +97,17 @@ struct SkDCubic {
|
||||
int searchRoots(double extremes[6], int extrema, double axisIntercept,
|
||||
SearchAxis xAxis, double* validRoots) const;
|
||||
|
||||
/**
|
||||
* Return the number of valid roots (0 < root < 1) for this cubic intersecting the
|
||||
* specified horizontal line.
|
||||
*/
|
||||
int horizontalIntersect(double yIntercept, double roots[3]) const;
|
||||
/**
|
||||
* Return the number of valid roots (0 < root < 1) for this cubic intersecting the
|
||||
* specified vertical line.
|
||||
*/
|
||||
int verticalIntersect(double xIntercept, double roots[3]) const;
|
||||
|
||||
const SkDCubic& set(const SkPoint pts[kPointCount]) {
|
||||
fPts[0] = pts[0];
|
||||
fPts[1] = pts[1];
|
||||
|
Loading…
Reference in New Issue
Block a user