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

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

Issue 915103002: interpret conic tolerance correctly -- big rebaseline (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 10 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 | « no previous file | 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 "SkGeometry.h" 8 #include "SkGeometry.h"
9 #include "SkMatrix.h" 9 #include "SkMatrix.h"
10 10
(...skipping 1421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 void SkConic::computeAsQuadError(SkVector* err) const { 1432 void SkConic::computeAsQuadError(SkVector* err) const {
1433 AS_QUAD_ERROR_SETUP 1433 AS_QUAD_ERROR_SETUP
1434 err->set(x, y); 1434 err->set(x, y);
1435 } 1435 }
1436 1436
1437 bool SkConic::asQuadTol(SkScalar tol) const { 1437 bool SkConic::asQuadTol(SkScalar tol) const {
1438 AS_QUAD_ERROR_SETUP 1438 AS_QUAD_ERROR_SETUP
1439 return (x * x + y * y) <= tol * tol; 1439 return (x * x + y * y) <= tol * tol;
1440 } 1440 }
1441 1441
1442 // Limit the number of suggested quads to approximate a conic
1443 #define kMaxConicToQuadPOW2 5
1444
1442 int SkConic::computeQuadPOW2(SkScalar tol) const { 1445 int SkConic::computeQuadPOW2(SkScalar tol) const {
1446 if (tol < 0 || !SkScalarIsFinite(tol)) {
1447 return 0;
1448 }
1449
1443 AS_QUAD_ERROR_SETUP 1450 AS_QUAD_ERROR_SETUP
1451
1452 #ifdef SK_SUPPORT_LEGACY_CONIC_COMPUTE_QUAD_POW2
1444 SkScalar error = SkScalarSqrt(x * x + y * y) - tol; 1453 SkScalar error = SkScalarSqrt(x * x + y * y) - tol;
1445 1454
1446 if (error <= 0) { 1455 if (error <= 0) {
1447 return 0; 1456 return 0;
1448 } 1457 }
1449 uint32_t ierr = (uint32_t)error; 1458 uint32_t ierr = (uint32_t)error;
1450 return (34 - SkCLZ(ierr)) >> 1; 1459 return (34 - SkCLZ(ierr)) >> 1;
1460 #else
1461 SkScalar error = SkScalarSqrt(x * x + y * y);
1462 int pow2;
1463 for (pow2 = 0; pow2 < kMaxConicToQuadPOW2; ++pow2) {
1464 if (error <= tol) {
1465 break;
1466 }
1467 error *= 0.25f;
1468 }
1469 // float version -- using ceil gives the same results as the above.
1470 if (false) {
1471 SkScalar err = SkScalarSqrt(x * x + y * y);
1472 if (err <= tol) {
1473 return 0;
1474 }
1475 SkScalar tol2 = tol * tol;
1476 if (tol2 == 0) {
1477 return kMaxConicToQuadPOW2;
1478 }
1479 SkScalar fpow2 = SkScalarLog2((x * x + y * y) / tol2) * 0.25f;
1480 int altPow2 = SkScalarCeilToInt(fpow2);
1481 if (altPow2 != pow2) {
1482 SkDebugf("pow2 %d altPow2 %d fbits %g err %g tol %g\n", pow2, altPow 2, fpow2, err, tol);
1483 }
1484 pow2 = altPow2;
1485 }
1486 return pow2;
1487 #endif
1451 } 1488 }
1452 1489
1453 static SkPoint* subdivide(const SkConic& src, SkPoint pts[], int level) { 1490 static SkPoint* subdivide(const SkConic& src, SkPoint pts[], int level) {
1454 SkASSERT(level >= 0); 1491 SkASSERT(level >= 0);
1455 1492
1456 if (0 == level) { 1493 if (0 == level) {
1457 memcpy(pts, &src.fPts[1], 2 * sizeof(SkPoint)); 1494 memcpy(pts, &src.fPts[1], 2 * sizeof(SkPoint));
1458 return pts + 2; 1495 return pts + 2;
1459 } else { 1496 } else {
1460 SkConic dst[2]; 1497 SkConic dst[2];
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 matrix.preScale(SK_Scalar1, -SK_Scalar1); 1671 matrix.preScale(SK_Scalar1, -SK_Scalar1);
1635 } 1672 }
1636 if (userMatrix) { 1673 if (userMatrix) {
1637 matrix.postConcat(*userMatrix); 1674 matrix.postConcat(*userMatrix);
1638 } 1675 }
1639 for (int i = 0; i < conicCount; ++i) { 1676 for (int i = 0; i < conicCount; ++i) {
1640 matrix.mapPoints(dst[i].fPts, 3); 1677 matrix.mapPoints(dst[i].fPts, 3);
1641 } 1678 }
1642 return conicCount; 1679 return conicCount;
1643 } 1680 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698