Index: src/core/SkPathMeasure.cpp |
diff --git a/src/core/SkPathMeasure.cpp b/src/core/SkPathMeasure.cpp |
index d959f45f4f8718c4ee4ab539e8136852654ad939..eb80cf3b831acd3f4493610f8bc0ab2da87daf7d 100644 |
--- a/src/core/SkPathMeasure.cpp |
+++ b/src/core/SkPathMeasure.cpp |
@@ -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; |