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>
diff --git a/src/utils/SkInsetConvexPolygon.cpp b/src/utils/SkInsetConvexPolygon.cpp
index fc40c8e..8a55b13 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 @@
}
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 @@
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 @@
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 @@
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 @@
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();
}