diff options
author | Cary Clark <caryclark@skia.org> | 2017-11-08 11:44:31 -0500 |
---|---|---|
committer | Ravi Mistry <rmistry@google.com> | 2017-11-08 18:25:17 +0000 |
commit | df429f3beac1c191289ba1e3bd918bf84df57bf5 (patch) | |
tree | 65f7f049b218ef8984d054524c05dd3fcea392a3 /src/utils/SkInsetConvexPolygon.cpp | |
parent | 21ad53fd8839af82bcb11da6ab3e256ee7752f2b (diff) |
move parts of SkPoint to SkPointPriv
Move specialized SkPoint methods to SkPointPriv.
Use constexpr and inline initialization where possible.
R=reed@google.com,bsalomon@google.com
Bug: skia: 6898
Change-Id: I01ec5186f010f2dc80c068c70d9cc352f3221338
Reviewed-on: https://skia-review.googlesource.com/68700
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Ravi Mistry <rmistry@google.com>
Diffstat (limited to 'src/utils/SkInsetConvexPolygon.cpp')
-rwxr-xr-x | src/utils/SkInsetConvexPolygon.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/utils/SkInsetConvexPolygon.cpp b/src/utils/SkInsetConvexPolygon.cpp index fc40c8ea9f..8a55b13390 100755 --- a/src/utils/SkInsetConvexPolygon.cpp +++ b/src/utils/SkInsetConvexPolygon.cpp @@ -7,6 +7,7 @@ #include "SkInsetConvexPolygon.h" +#include "SkPointPriv.h" #include "SkTemplates.h" struct InsetSegment { @@ -67,7 +68,7 @@ bool SkOffsetSegment(const SkPoint& p0, const SkPoint& p1, SkScalar d0, SkScalar } SkScalar dD = d0 - d1; // if one circle is inside another, we can't compute an offset - if (dD*dD >= p0.distanceToSqd(p1)) { + if (dD*dD >= SkPointPriv::DistanceToSqd(p0, p1)) { return false; } SkPoint outerTangentIntersect = SkPoint::Make((p1.fX*d0 - p0.fX*d1) / dD, @@ -75,14 +76,14 @@ bool SkOffsetSegment(const SkPoint& p0, const SkPoint& p1, SkScalar d0, SkScalar SkScalar d0sq = d0*d0; SkVector dP = outerTangentIntersect - p0; - SkScalar dPlenSq = dP.lengthSqd(); + SkScalar dPlenSq = SkPointPriv::LengthSqd(dP); SkScalar discrim = SkScalarSqrt(dPlenSq - d0sq); offset0->fX = p0.fX + (d0sq*dP.fX - side*d0*dP.fY*discrim) / dPlenSq; offset0->fY = p0.fY + (d0sq*dP.fY + side*d0*dP.fX*discrim) / dPlenSq; SkScalar d1sq = d1*d1; dP = outerTangentIntersect - p1; - dPlenSq = dP.lengthSqd(); + dPlenSq = SkPointPriv::LengthSqd(dP); discrim = SkScalarSqrt(dPlenSq - d1sq); offset1->fX = p1.fX + (d1sq*dP.fX - side*d1*dP.fY*discrim) / dPlenSq; offset1->fY = p1.fY + (d1sq*dP.fY + side*d1*dP.fX*discrim) / dPlenSq; @@ -103,13 +104,13 @@ static bool compute_intersection(const InsetSegment& s0, const InsetSegment& s1, if (SkScalarNearlyZero(perpDot)) { // segments are parallel // check if endpoints are touching - if (s0.fP1.equalsWithinTolerance(s1.fP0)) { + if (SkPointPriv::EqualsWithinTolerance(s0.fP1, s1.fP0)) { *p = s0.fP1; *s = SK_Scalar1; *t = 0; return true; } - if (s1.fP1.equalsWithinTolerance(s0.fP0)) { + if (SkPointPriv::EqualsWithinTolerance(s1.fP1, s0.fP0)) { *p = s1.fP1; *s = 0; *t = SK_Scalar1; @@ -233,7 +234,8 @@ bool SkInsetConvexPolygon(const SkPoint* inputPolygonVerts, int inputPolygonSize prevIndex = (prevIndex + inputPolygonSize - 1) % inputPolygonSize; // we've already considered this intersection, we're done } else if (edgeData[currIndex].fTValue > SK_ScalarMin && - intersection.equalsWithinTolerance(edgeData[currIndex].fIntersection, + SkPointPriv::EqualsWithinTolerance(intersection, + edgeData[currIndex].fIntersection, 1.0e-6f)) { break; } else { @@ -276,16 +278,17 @@ bool SkInsetConvexPolygon(const SkPoint* inputPolygonVerts, int inputPolygonSize currIndex = -1; for (int i = 0; i < inputPolygonSize; ++i) { if (edgeData[i].fValid && (currIndex == -1 || - !edgeData[i].fIntersection.equalsWithinTolerance((*insetPolygon)[currIndex], - kCleanupTolerance))) { + !SkPointPriv::EqualsWithinTolerance(edgeData[i].fIntersection, + (*insetPolygon)[currIndex], + kCleanupTolerance))) { *insetPolygon->push() = edgeData[i].fIntersection; currIndex++; } } // make sure the first and last points aren't coincident if (currIndex >= 1 && - (*insetPolygon)[0].equalsWithinTolerance((*insetPolygon)[currIndex], - kCleanupTolerance)) { + SkPointPriv::EqualsWithinTolerance((*insetPolygon)[0], (*insetPolygon)[currIndex], + kCleanupTolerance)) { insetPolygon->pop(); } |