check in direct quad length measure
Add code so that it at minimum won't bit-rot. Next: add tests to see if it works. R=reed@google.com BUG=skia:1036 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1541523002 Review URL: https://codereview.chromium.org/1541523002
This commit is contained in:
parent
dd180e795f
commit
17bc0851d3
@ -90,6 +90,28 @@ static bool cubic_too_curvy(const SkPoint pts[4]) {
|
||||
SkScalarInterp(pts[0].fY, pts[3].fY, SK_Scalar1*2/3));
|
||||
}
|
||||
|
||||
/* from http://www.malczak.linuxpl.com/blog/quadratic-bezier-curve-length/ */
|
||||
static SkScalar compute_quad_len(const SkPoint pts[3]) {
|
||||
SkPoint a,b;
|
||||
a.fX = pts[0].fX - 2 * pts[1].fX + pts[2].fX;
|
||||
a.fY = pts[0].fY - 2 * pts[1].fY + pts[2].fY;
|
||||
b.fX = 2 * (pts[1].fX - pts[0].fX);
|
||||
b.fY = 2 * (pts[1].fY - pts[0].fY);
|
||||
SkScalar A = 4 * (a.fX * a.fX + a.fY * a.fY);
|
||||
SkScalar B = 4 * (a.fX * b.fX + a.fY * b.fY);
|
||||
SkScalar C = b.fX * b.fX + b.fY * b.fY;
|
||||
|
||||
SkScalar Sabc = 2 * SkScalarSqrt(A + B + C);
|
||||
SkScalar A_2 = SkScalarSqrt(A);
|
||||
SkScalar A_32 = 2 * A * A_2;
|
||||
SkScalar C_2 = 2 * SkScalarSqrt(C);
|
||||
SkScalar BA = B / A_2;
|
||||
|
||||
return (A_32 * Sabc + A_2 * B * (Sabc - C_2) +
|
||||
(4 * C * A - B * B) * SkScalarLog((2 * A_2 + BA + Sabc) / (BA + C_2))) / (4 * A_32);
|
||||
}
|
||||
|
||||
|
||||
SkScalar SkPathMeasure::compute_quad_segs(const SkPoint pts[3],
|
||||
SkScalar distance, int mint, int maxt, int ptIndex) {
|
||||
if (tspan_big_enough(maxt - mint) && quad_too_curvy(pts)) {
|
||||
@ -209,7 +231,19 @@ void SkPathMeasure::buildSegments() {
|
||||
|
||||
case SkPath::kQuad_Verb: {
|
||||
SkScalar prevD = distance;
|
||||
distance = this->compute_quad_segs(pts, distance, 0, kMaxTValue, ptIndex);
|
||||
if (false) {
|
||||
SkScalar length = compute_quad_len(pts);
|
||||
if (length) {
|
||||
distance += length;
|
||||
Segment* seg = fSegments.append();
|
||||
seg->fDistance = distance;
|
||||
seg->fPtIndex = ptIndex;
|
||||
seg->fType = kQuad_SegType;
|
||||
seg->fTValue = kMaxTValue;
|
||||
}
|
||||
} else {
|
||||
distance = this->compute_quad_segs(pts, distance, 0, kMaxTValue, ptIndex);
|
||||
}
|
||||
if (distance > prevD) {
|
||||
fPts.append(2, pts + 1);
|
||||
ptIndex += 2;
|
||||
|
Loading…
Reference in New Issue
Block a user