Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1384)

Unified Diff: src/utils/SkCurveMeasure.cpp

Issue 2243313002: Implement Conics in SkCurveMeasure (Closed) Base URL: https://skia.googlesource.com/skia.git@cubic_fix
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/utils/SkCurveMeasure.h ('K') | « src/utils/SkCurveMeasure.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkCurveMeasure.cpp
diff --git a/src/utils/SkCurveMeasure.cpp b/src/utils/SkCurveMeasure.cpp
index a38a4fd1f0b99b79fe5544ac11905dbfb12232ed..425b6f35efb18cf7dc27306926083cf3fa6d2d1e 100644
--- a/src/utils/SkCurveMeasure.cpp
+++ b/src/utils/SkCurveMeasure.cpp
@@ -69,6 +69,7 @@ static inline SkVector evaluateDerivative(const SkPoint pts[4],
static inline Sk8f evaluateDerivativeLength(const Sk8f& ts,
const Sk8f (&xCoeff)[3],
const Sk8f (&yCoeff)[3],
+ const SkScalar w,
const SkSegType segType) {
Sk8f x;
Sk8f y;
@@ -81,8 +82,16 @@ static inline Sk8f evaluateDerivativeLength(const Sk8f& ts,
x = (xCoeff[0]*ts + xCoeff[1])*ts + xCoeff[2];
y = (yCoeff[0]*ts + yCoeff[1])*ts + yCoeff[2];
break;
- case kConic_SegType:
- UNIMPLEMENTED;
+ case kConic_SegType: {
+ Sk8f xnum = (xCoeff[0]*ts + xCoeff[1])*ts + xCoeff[2];
+ Sk8f ynum = (yCoeff[0]*ts + yCoeff[1])*ts + yCoeff[2];
+
+ Sk8f denom = ts*(-4 + 4*w + ts*(8 - 12*w + 4*w*w + ts*(-8 + 16*w -
+ 8*w*w + ts*(4 - 8*w + 4*w*w)))) + 1;
caryclark 2016/08/15 19:13:04 Where did this come from? That is, please document
Harry Stern 2016/08/15 20:55:16 I took out those terms. I honestly didn't notice t
Harry Stern 2016/08/17 02:48:46 Also, I have added the mathematica commands used t
+
+ x = xnum / denom;
+ y = ynum / denom;
caryclark 2016/08/15 19:13:04 Is there a unit test for this?
Harry Stern 2016/08/15 20:55:16 It's on my todo by tomorrow.
+ }
break;
default:
UNIMPLEMENTED;
@@ -134,8 +143,27 @@ ArcLengthIntegrator::ArcLengthIntegrator(const SkPoint* pts, SkSegType segType)
yCoeff[2] = Sk8f(3.0f*(-Ay + By));
}
break;
- case kConic_SegType:
- UNIMPLEMENTED;
+ case kConic_SegType: {
+ float Ax = pts[0].x();
+ float Bx = pts[1].x();
+ float Cx = pts[2].x();
+ float Ay = pts[0].y();
+ float By = pts[1].y();
+ float Cy = pts[2].y();
+
+ fConicW = pts[3].x();
Harry Stern 2016/08/15 18:01:21 fConicW gets set here
+
+ SkScalar w = fConicW;
+
+ // precompute coefficients for derivative
+ xCoeff[0] = Sk8f(2*(Ax - Cx - Ax*w + Cx*w));
+ xCoeff[1] = Sk8f(-2*(Ax + Cx + 2*(Ax*w - Bx*w)));
+ xCoeff[2] = Sk8f(-2*(Ax*w + Bx*w));
+
+ yCoeff[0] = Sk8f(2*(Ay - Cy - Ay*w + Cy*w));
+ yCoeff[1] = Sk8f(-2*(Ay + Cy + 2*(Ay*w - By*w)));
+ yCoeff[2] = Sk8f(-2*(Ay*w + By*w));
+ }
break;
default:
UNIMPLEMENTED;
@@ -148,7 +176,7 @@ ArcLengthIntegrator::ArcLengthIntegrator(const SkPoint* pts, SkSegType segType)
SkScalar ArcLengthIntegrator::computeLength(SkScalar t) {
SkScalar length = 0.0f;
- Sk8f lengths = evaluateDerivativeLength(absc*t, xCoeff, yCoeff, fSegType);
+ Sk8f lengths = evaluateDerivativeLength(absc*t, xCoeff, yCoeff, fConicW, fSegType);
lengths = weights*lengths;
// is it faster or more accurate to sum and then multiply or vice versa?
lengths = lengths*(t*0.5f);
« src/utils/SkCurveMeasure.h ('K') | « src/utils/SkCurveMeasure.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698