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

Side by Side Diff: src/core/SkPath.cpp

Issue 1612543003: replace arcto quads with a conic (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « src/core/SkGeometry.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBuffer.h" 8 #include "SkBuffer.h"
9 #include "SkCubicClipper.h" 9 #include "SkCubicClipper.h"
10 #include "SkErrorInternals.h" 10 #include "SkErrorInternals.h"
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 } 1286 }
1287 1287
1288 SkScalar cosh = SkPoint::DotProduct(before, after); 1288 SkScalar cosh = SkPoint::DotProduct(before, after);
1289 SkScalar sinh = SkPoint::CrossProduct(before, after); 1289 SkScalar sinh = SkPoint::CrossProduct(before, after);
1290 1290
1291 if (SkScalarNearlyZero(sinh)) { // angle is too tight 1291 if (SkScalarNearlyZero(sinh)) { // angle is too tight
1292 this->lineTo(x1, y1); 1292 this->lineTo(x1, y1);
1293 return; 1293 return;
1294 } 1294 }
1295 1295
1296 SkScalar dist = SkScalarMulDiv(radius, SK_Scalar1 - cosh, sinh); 1296 SkScalar dist = SkScalarAbs(SkScalarMulDiv(radius, SK_Scalar1 - cosh, sinh)) ;
1297 if (dist < 0) {
1298 dist = -dist;
1299 }
1300 1297
1301 SkScalar xx = x1 - SkScalarMul(dist, before.fX); 1298 SkScalar xx = x1 - SkScalarMul(dist, before.fX);
1302 SkScalar yy = y1 - SkScalarMul(dist, before.fY); 1299 SkScalar yy = y1 - SkScalarMul(dist, before.fY);
1300 #ifndef SK_SUPPORT_LEGACY_ARCTO
1301 after.setLength(dist);
1302 this->lineTo(xx, yy);
1303 SkScalar weight = SkScalarSqrt(SK_ScalarHalf + cosh * SK_ScalarHalf);
1304 this->conicTo(x1, y1, x1 + after.fX, y1 + after.fY, weight);
1305 #else
1303 SkRotationDirection arcDir; 1306 SkRotationDirection arcDir;
1304 1307
1305 // now turn before/after into normals 1308 // now turn before/after into normals
1306 if (sinh > 0) { 1309 if (sinh > 0) {
1307 before.rotateCCW(); 1310 before.rotateCCW();
1308 after.rotateCCW(); 1311 after.rotateCCW();
1309 arcDir = kCW_SkRotationDirection; 1312 arcDir = kCW_SkRotationDirection;
1310 } else { 1313 } else {
1311 before.rotateCW(); 1314 before.rotateCW();
1312 after.rotateCW(); 1315 after.rotateCW();
1313 arcDir = kCCW_SkRotationDirection; 1316 arcDir = kCCW_SkRotationDirection;
1314 } 1317 }
1315 1318
1316 SkMatrix matrix; 1319 SkMatrix matrix;
1317 SkPoint pts[kSkBuildQuadArcStorage]; 1320 SkPoint pts[kSkBuildQuadArcStorage];
1318 1321
1319 matrix.setScale(radius, radius); 1322 matrix.setScale(radius, radius);
1320 matrix.postTranslate(xx - SkScalarMul(radius, before.fX), 1323 matrix.postTranslate(xx - SkScalarMul(radius, before.fX),
1321 yy - SkScalarMul(radius, before.fY)); 1324 yy - SkScalarMul(radius, before.fY));
1322 1325
1323 int count = SkBuildQuadArc(before, after, arcDir, &matrix, pts); 1326 int count = SkBuildQuadArc(before, after, arcDir, &matrix, pts);
1324 1327
1325 this->incReserve(count); 1328 this->incReserve(count);
1326 // [xx,yy] == pts[0] 1329 // [xx,yy] == pts[0]
1327 this->lineTo(xx, yy); 1330 this->lineTo(xx, yy);
1328 for (int i = 1; i < count; i += 2) { 1331 for (int i = 1; i < count; i += 2) {
1329 this->quadTo(pts[i], pts[i+1]); 1332 this->quadTo(pts[i], pts[i+1]);
1330 } 1333 }
1334 #endif
1331 } 1335 }
1332 1336
1333 /////////////////////////////////////////////////////////////////////////////// 1337 ///////////////////////////////////////////////////////////////////////////////
1334 1338
1335 void SkPath::addPath(const SkPath& path, SkScalar dx, SkScalar dy, AddPathMode m ode) { 1339 void SkPath::addPath(const SkPath& path, SkScalar dx, SkScalar dy, AddPathMode m ode) {
1336 SkMatrix matrix; 1340 SkMatrix matrix;
1337 1341
1338 matrix.setTranslate(dx, dy); 1342 matrix.setTranslate(dx, dy);
1339 this->addPath(path, matrix, mode); 1343 this->addPath(path, matrix, mode);
1340 } 1344 }
(...skipping 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after
3084 } 3088 }
3085 } while (!done); 3089 } while (!done);
3086 return SkToBool(tangents.count()) ^ isInverse; 3090 return SkToBool(tangents.count()) ^ isInverse;
3087 } 3091 }
3088 3092
3089 int SkPath::ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPo int& p2, 3093 int SkPath::ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPo int& p2,
3090 SkScalar w, SkPoint pts[], int pow2) { 3094 SkScalar w, SkPoint pts[], int pow2) {
3091 const SkConic conic(p0, p1, p2, w); 3095 const SkConic conic(p0, p1, p2, w);
3092 return conic.chopIntoQuadsPOW2(pts, pow2); 3096 return conic.chopIntoQuadsPOW2(pts, pow2);
3093 } 3097 }
OLDNEW
« no previous file with comments | « src/core/SkGeometry.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698