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

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

Issue 910213002: Use conics for round joins and caps (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove dup cubic code 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 | « src/core/SkGeometry.h ('k') | src/core/SkStrokerPriv.cpp » ('j') | 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 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 1605
1606 int conicCount = quadrant; 1606 int conicCount = quadrant;
1607 for (int i = 0; i < conicCount; ++i) { 1607 for (int i = 0; i < conicCount; ++i) {
1608 dst[i].set(&quadrantPts[i * 2], quadrantWeight); 1608 dst[i].set(&quadrantPts[i * 2], quadrantWeight);
1609 } 1609 }
1610 1610
1611 // Now compute any remaing (sub-90-degree) arc for the last conic 1611 // Now compute any remaing (sub-90-degree) arc for the last conic
1612 const SkPoint finalP = { x, y }; 1612 const SkPoint finalP = { x, y };
1613 const SkPoint& lastQ = quadrantPts[quadrant * 2]; // will already be a unit -vector 1613 const SkPoint& lastQ = quadrantPts[quadrant * 2]; // will already be a unit -vector
1614 const SkScalar dot = SkVector::DotProduct(lastQ, finalP); 1614 const SkScalar dot = SkVector::DotProduct(lastQ, finalP);
1615 SkASSERT(0 <= dot && dot <= SK_Scalar1); 1615 SkASSERT(0 <= dot && dot <= SK_Scalar1 + SK_ScalarNearlyZero);
1616 1616
1617 if (dot < 1 - SK_ScalarNearlyZero) { 1617 if (dot < 1 - SK_ScalarNearlyZero) {
1618 SkVector offCurve = { lastQ.x() + x, lastQ.y() + y }; 1618 SkVector offCurve = { lastQ.x() + x, lastQ.y() + y };
1619 // compute the bisector vector, and then rescale to be the off-curve poi nt. 1619 // compute the bisector vector, and then rescale to be the off-curve poi nt.
1620 // we compute its length from cos(theta/2) = length / 1, using half-angl e identity we get 1620 // we compute its length from cos(theta/2) = length / 1, using half-angl e identity we get
1621 // length = sqrt(2 / (1 + cos(theta)). We already have cos() when to com puted the dot. 1621 // length = sqrt(2 / (1 + cos(theta)). We already have cos() when to com puted the dot.
1622 // This is nice, since our computed weight is cos(theta/2) as well! 1622 // This is nice, since our computed weight is cos(theta/2) as well!
1623 // 1623 //
1624 const SkScalar cosThetaOver2 = SkScalarSqrt((1 + dot) / 2); 1624 const SkScalar cosThetaOver2 = SkScalarSqrt((1 + dot) / 2);
1625 offCurve.setLength(SkScalarInvert(cosThetaOver2)); 1625 offCurve.setLength(SkScalarInvert(cosThetaOver2));
1626 dst[conicCount].set(lastQ, offCurve, finalP, cosThetaOver2); 1626 dst[conicCount].set(lastQ, offCurve, finalP, cosThetaOver2);
1627 conicCount += 1; 1627 conicCount += 1;
1628 } 1628 }
1629 1629
1630 // now handle counter-clockwise and the initial unitStart rotation 1630 // now handle counter-clockwise and the initial unitStart rotation
1631 SkMatrix matrix; 1631 SkMatrix matrix;
1632 matrix.setSinCos(uStart.fY, uStart.fX); 1632 matrix.setSinCos(uStart.fY, uStart.fX);
1633 if (dir == kCCW_SkRotationDirection) { 1633 if (dir == kCCW_SkRotationDirection) {
1634 matrix.preScale(SK_Scalar1, -SK_Scalar1); 1634 matrix.preScale(SK_Scalar1, -SK_Scalar1);
1635 } 1635 }
1636 if (userMatrix) { 1636 if (userMatrix) {
1637 matrix.postConcat(*userMatrix); 1637 matrix.postConcat(*userMatrix);
1638 } 1638 }
1639 for (int i = 0; i < conicCount; ++i) { 1639 for (int i = 0; i < conicCount; ++i) {
1640 matrix.mapPoints(dst[i].fPts, 3); 1640 matrix.mapPoints(dst[i].fPts, 3);
1641 } 1641 }
1642 return conicCount; 1642 return conicCount;
1643 } 1643 }
OLDNEW
« no previous file with comments | « src/core/SkGeometry.h ('k') | src/core/SkStrokerPriv.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698