aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/OverStroke.cpp3
-rw-r--r--include/core/SkPath.h15
-rw-r--r--include/core/SkPoint.h242
-rw-r--r--include/core/SkRRect.h8
-rw-r--r--samplecode/SampleAAGeometry.cpp3
-rw-r--r--samplecode/SampleFatBits.cpp3
-rw-r--r--samplecode/SampleHT.cpp3
-rw-r--r--samplecode/SampleQuadStroker.cpp13
-rw-r--r--src/core/SkBitmap.cpp4
-rw-r--r--src/core/SkDevice.cpp2
-rw-r--r--src/core/SkDistanceFieldGen.cpp4
-rw-r--r--src/core/SkGeometry.cpp11
-rw-r--r--src/core/SkPath.cpp29
-rw-r--r--src/core/SkPoint.cpp64
-rw-r--r--src/core/SkPointPriv.h95
-rw-r--r--src/core/SkStroke.cpp19
-rw-r--r--src/core/SkStrokerPriv.cpp5
-rw-r--r--src/effects/SkDiscretePathEffect.cpp3
-rw-r--r--src/effects/SkMergeImageFilter.cpp2
-rw-r--r--src/effects/SkOffsetImageFilter.cpp3
-rw-r--r--src/gpu/GrDistanceFieldGenFromVector.cpp6
-rw-r--r--src/gpu/GrPathUtils.cpp43
-rw-r--r--src/gpu/GrRenderTargetContext.cpp4
-rw-r--r--src/gpu/GrTessellator.cpp7
-rw-r--r--src/gpu/ops/GrAAConvexPathRenderer.cpp20
-rw-r--r--src/gpu/ops/GrAAConvexTessellator.cpp28
-rw-r--r--src/gpu/ops/GrAAConvexTessellator.h8
-rw-r--r--src/gpu/ops/GrAAHairLinePathRenderer.cpp15
-rw-r--r--src/gpu/ops/GrDashOp.cpp3
-rw-r--r--src/gpu/text/GrStencilAndCoverTextContext.cpp3
-rw-r--r--src/pathops/SkOpSegment.cpp8
-rw-r--r--src/utils/SkDashPath.cpp3
-rwxr-xr-xsrc/utils/SkInsetConvexPolygon.cpp23
-rwxr-xr-xsrc/utils/SkShadowTessellator.cpp22
-rw-r--r--tests/GeometryTest.cpp5
-rw-r--r--tests/PathCoverageTest.cpp4
-rw-r--r--tests/PointTest.cpp6
-rw-r--r--tests/RoundRectTest.cpp4
-rw-r--r--tests/StrokerTest.cpp19
39 files changed, 338 insertions, 424 deletions
diff --git a/gm/OverStroke.cpp b/gm/OverStroke.cpp
index f7134cd26c..68278905cd 100644
--- a/gm/OverStroke.cpp
+++ b/gm/OverStroke.cpp
@@ -27,6 +27,7 @@
#include "SkPaint.h"
#include "SkPath.h"
#include "SkPathMeasure.h"
+#include "SkPointPriv.h"
const SkScalar OVERSTROKE_WIDTH = 500.0f;
const SkScalar NORMALSTROKE_WIDTH = 3.0f;
@@ -96,7 +97,7 @@ SkPath ribs_path(SkPath path, SkScalar radius) {
while (accum < length) {
if (meas.getPosTan(accum, &pos, &tan)) {
tan.scale(radius);
- tan.rotateCCW();
+ SkPointPriv::RotateCCW(&tan);
ribs.moveTo(pos.x() + tan.x(), pos.y() + tan.y());
ribs.lineTo(pos.x() - tan.x(), pos.y() - tan.y());
diff --git a/include/core/SkPath.h b/include/core/SkPath.h
index d39d4efcd3..25aa7fcc1d 100644
--- a/include/core/SkPath.h
+++ b/include/core/SkPath.h
@@ -421,9 +421,7 @@ public:
@param exact if false, allow nearly equals
@return true if line is degenerate; its length is effectively zero
*/
- static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2, bool exact) {
- return exact ? p1 == p2 : p1.equalsWithinTolerance(p2);
- }
+ static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2, bool exact);
/** Test if quad is degenerate.
Quad with no length or that moves a very short distance is degenerate; it is
@@ -437,10 +435,7 @@ public:
@return true if quad is degenerate; its length is effectively zero
*/
static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2,
- const SkPoint& p3, bool exact) {
- return exact ? p1 == p2 && p2 == p3 : p1.equalsWithinTolerance(p2) &&
- p2.equalsWithinTolerance(p3);
- }
+ const SkPoint& p3, bool exact);
/** Test if cubic is degenerate.
Cubic with no length or that moves a very short distance is degenerate; it is
@@ -455,11 +450,7 @@ public:
@return true if cubic is degenerate; its length is effectively zero
*/
static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2,
- const SkPoint& p3, const SkPoint& p4, bool exact) {
- return exact ? p1 == p2 && p2 == p3 && p3 == p4 : p1.equalsWithinTolerance(p2) &&
- p2.equalsWithinTolerance(p3) &&
- p3.equalsWithinTolerance(p4);
- }
+ const SkPoint& p3, const SkPoint& p4, bool exact);
/** Returns true if SkPath contains only one line;
SkPath::Verb array has two entries: kMove_Verb, kLine_Verb.
diff --git a/include/core/SkPoint.h b/include/core/SkPoint.h
index f9527bf53e..744abb77f5 100644
--- a/include/core/SkPoint.h
+++ b/include/core/SkPoint.h
@@ -19,10 +19,8 @@ struct SkIPoint16 {
int16_t fX;
int16_t fY;
- static SkIPoint16 Make(int x, int y) {
- SkIPoint16 pt;
- pt.set(x, y);
- return pt;
+ static constexpr SkIPoint16 Make(int x, int y) {
+ return {SkToS16(x), SkToS16(y)};
}
int16_t x() const { return fX; }
@@ -42,62 +40,29 @@ struct SkIPoint {
int32_t fX;
int32_t fY;
- static SkIPoint Make(int32_t x, int32_t y) {
- SkIPoint pt;
- pt.set(x, y);
- return pt;
+ static constexpr SkIPoint Make(int32_t x, int32_t y) {
+ return {x, y};
}
int32_t x() const { return fX; }
int32_t y() const { return fY; }
- void setX(int32_t x) { fX = x; }
- void setY(int32_t y) { fY = y; }
/**
* Returns true iff fX and fY are both zero.
*/
bool isZero() const { return (fX | fY) == 0; }
- /**
- * Set both fX and fY to zero. Same as set(0, 0)
- */
- void setZero() { fX = fY = 0; }
-
/** Set the x and y values of the point. */
- void set(int32_t x, int32_t y) { fX = x; fY = y; }
-
- /** Rotate the point clockwise, writing the new point into dst
- It is legal for dst == this
- */
- void rotateCW(SkIPoint* dst) const;
-
- /** Rotate the point clockwise, writing the new point back into the point
- */
-
- void rotateCW() { this->rotateCW(this); }
-
- /** Rotate the point counter-clockwise, writing the new point into dst.
- It is legal for dst == this
- */
- void rotateCCW(SkIPoint* dst) const;
-
- /** Rotate the point counter-clockwise, writing the new point back into
- the point
- */
- void rotateCCW() { this->rotateCCW(this); }
-
- /** Negate the X and Y coordinates of the point.
- */
- void negate() { fX = -fX; fY = -fY; }
+ void set(int32_t x, int32_t y) {
+ fX = x;
+ fY = y;
+ }
/** Return a new point whose X and Y coordinates are the negative of the
original point's
*/
SkIPoint operator-() const {
- SkIPoint neg;
- neg.fX = -fX;
- neg.fY = -fY;
- return neg;
+ return {-fX, -fY};
}
/** Add v's coordinates to this point's */
@@ -129,29 +94,13 @@ struct SkIPoint {
a and b (i.e. a - b)
*/
friend SkIPoint operator-(const SkIPoint& a, const SkIPoint& b) {
- SkIPoint v;
- v.set(a.fX - b.fX, a.fY - b.fY);
- return v;
+ return {a.fX - b.fX, a.fY - b.fY};
}
/** Returns a new point whose coordinates are the sum of a and b (a + b)
*/
friend SkIPoint operator+(const SkIPoint& a, const SkIPoint& b) {
- SkIPoint v;
- v.set(a.fX + b.fX, a.fY + b.fY);
- return v;
- }
-
- /** Returns the dot product of a and b, treating them as 2D vectors
- */
- static int32_t DotProduct(const SkIPoint& a, const SkIPoint& b) {
- return a.fX * b.fX + a.fY * b.fY;
- }
-
- /** Returns the cross product of a and b, treating them as 2D vectors
- */
- static int32_t CrossProduct(const SkIPoint& a, const SkIPoint& b) {
- return a.fX * b.fY - a.fY * b.fX;
+ return {a.fX + b.fX, a.fY + b.fY};
}
};
@@ -159,10 +108,8 @@ struct SK_API SkPoint {
SkScalar fX;
SkScalar fY;
- static SkPoint Make(SkScalar x, SkScalar y) {
- SkPoint pt;
- pt.set(x, y);
- return pt;
+ static constexpr SkPoint Make(SkScalar x, SkScalar y) {
+ return {x, y};
}
SkScalar x() const { return fX; }
@@ -174,7 +121,10 @@ struct SK_API SkPoint {
bool isZero() const { return (0 == fX) & (0 == fY); }
/** Set the point's X and Y coordinates */
- void set(SkScalar x, SkScalar y) { fX = x; fY = y; }
+ void set(SkScalar x, SkScalar y) {
+ fX = x;
+ fY = y;
+ }
/** Set the point's X and Y coordinates by automatically promoting (x,y) to
SkScalar values.
@@ -217,19 +167,6 @@ struct SK_API SkPoint {
SkScalar length() const { return SkPoint::Length(fX, fY); }
SkScalar distanceToOrigin() const { return this->length(); }
- /**
- * Return true if the computed length of the vector is >= the internal
- * tolerance (used to avoid dividing by tiny values).
- */
- static bool CanNormalize(SkScalar dx, SkScalar dy) {
- // Simple enough (and performance critical sometimes) so we inline it.
- return (dx*dx + dy*dy) > (SK_ScalarNearlyZero * SK_ScalarNearlyZero);
- }
-
- bool canNormalize() const {
- return CanNormalize(fX, fY);
- }
-
/** Set the point (vector) to be unit-length in the same direction as it
already points. If the point has a degenerate length (i.e. nearly 0)
then set it to (0,0) and return false; otherwise return true.
@@ -254,14 +191,6 @@ struct SK_API SkPoint {
*/
bool setLength(SkScalar x, SkScalar y, SkScalar length);
- /** Same as setLength, but favoring speed over accuracy.
- */
- bool setLengthFast(SkScalar length);
-
- /** Same as setLength, but favoring speed over accuracy.
- */
- bool setLengthFast(SkScalar x, SkScalar y, SkScalar length);
-
/** Scale the point's coordinates by scale, writing the answer into dst.
It is legal for dst == this.
*/
@@ -272,26 +201,6 @@ struct SK_API SkPoint {
*/
void scale(SkScalar value) { this->scale(value, this); }
- /** Rotate the point clockwise by 90 degrees, writing the answer into dst.
- It is legal for dst == this.
- */
- void rotateCW(SkPoint* dst) const;
-
- /** Rotate the point clockwise by 90 degrees, writing the answer back into
- the point.
- */
- void rotateCW() { this->rotateCW(this); }
-
- /** Rotate the point counter-clockwise by 90 degrees, writing the answer
- into dst. It is legal for dst == this.
- */
- void rotateCCW(SkPoint* dst) const;
-
- /** Rotate the point counter-clockwise by 90 degrees, writing the answer
- back into the point.
- */
- void rotateCCW() { this->rotateCCW(this); }
-
/** Negate the point's coordinates
*/
void negate() {
@@ -302,10 +211,7 @@ struct SK_API SkPoint {
/** Returns a new point whose coordinates are the negative of the point's
*/
SkPoint operator-() const {
- SkPoint neg;
- neg.fX = -fX;
- neg.fY = -fY;
- return neg;
+ return {-fX, -fY};
}
/** Add v's coordinates to the point's
@@ -323,7 +229,7 @@ struct SK_API SkPoint {
}
SkPoint operator*(SkScalar scale) const {
- return Make(fX * scale, fY * scale);
+ return {fX * scale, fY * scale};
}
SkPoint& operator*=(SkScalar scale) {
@@ -363,43 +269,17 @@ struct SK_API SkPoint {
return a.fX != b.fX || a.fY != b.fY;
}
- /** Return true if this point and the given point are far enough apart
- such that a vector between them would be non-degenerate.
-
- WARNING: Unlike the explicit tolerance version,
- this method does not use componentwise comparison. Instead, it
- uses a comparison designed to match judgments elsewhere regarding
- degeneracy ("points A and B are so close that the vector between them
- is essentially zero").
- */
- bool equalsWithinTolerance(const SkPoint& p) const {
- return !CanNormalize(fX - p.fX, fY - p.fY);
- }
-
- /** WARNING: There is no guarantee that the result will reflect judgments
- elsewhere regarding degeneracy ("points A and B are so close that the
- vector between them is essentially zero").
- */
- bool equalsWithinTolerance(const SkPoint& p, SkScalar tol) const {
- return SkScalarNearlyZero(fX - p.fX, tol)
- && SkScalarNearlyZero(fY - p.fY, tol);
- }
-
/** Returns a new point whose coordinates are the difference between
a's and b's (a - b)
*/
friend SkPoint operator-(const SkPoint& a, const SkPoint& b) {
- SkPoint v;
- v.set(a.fX - b.fX, a.fY - b.fY);
- return v;
+ return {a.fX - b.fX, a.fY - b.fY};
}
/** Returns a new point whose coordinates are the sum of a's and b's (a + b)
*/
friend SkPoint operator+(const SkPoint& a, const SkPoint& b) {
- SkPoint v;
- v.set(a.fX + b.fX, a.fY + b.fY);
- return v;
+ return {a.fX + b.fX, a.fY + b.fY};
}
/** Returns the euclidian distance from (0,0) to (x,y)
@@ -443,88 +323,8 @@ struct SK_API SkPoint {
return DotProduct(*this, vec);
}
- SkScalar lengthSqd() const {
- return DotProduct(*this, *this);
- }
-
- SkScalar distanceToSqd(const SkPoint& pt) const {
- SkScalar dx = fX - pt.fX;
- SkScalar dy = fY - pt.fY;
- return dx * dx + dy * dy;
- }
-
- /**
- * The side of a point relative to a line. If the line is from a to b then
- * the values are consistent with the sign of (b-a) cross (pt-a)
- */
- enum Side {
- kLeft_Side = -1,
- kOn_Side = 0,
- kRight_Side = 1,
- };
-
- /**
- * Returns the squared distance to the infinite line between two pts. Also
- * optionally returns the side of the line that the pt falls on (looking
- * along line from a to b)
- */
- SkScalar distanceToLineBetweenSqd(const SkPoint& a,
- const SkPoint& b,
- Side* side = nullptr) const;
-
- /**
- * Returns the distance to the infinite line between two pts. Also
- * optionally returns the side of the line that the pt falls on (looking
- * along the line from a to b)
- */
- SkScalar distanceToLineBetween(const SkPoint& a,
- const SkPoint& b,
- Side* side = nullptr) const {
- return SkScalarSqrt(this->distanceToLineBetweenSqd(a, b, side));
- }
-
- /**
- * Returns the squared distance to the line segment between pts a and b
- */
- SkScalar distanceToLineSegmentBetweenSqd(const SkPoint& a,
- const SkPoint& b) const;
-
- /**
- * Returns the distance to the line segment between pts a and b.
- */
- SkScalar distanceToLineSegmentBetween(const SkPoint& a,
- const SkPoint& b) const {
- return SkScalarSqrt(this->distanceToLineSegmentBetweenSqd(a, b));
- }
-
- /**
- * Make this vector be orthogonal to vec. Looking down vec the
- * new vector will point in direction indicated by side (which
- * must be kLeft_Side or kRight_Side).
- */
- void setOrthog(const SkPoint& vec, Side side = kLeft_Side) {
- // vec could be this
- SkScalar tmp = vec.fX;
- if (kRight_Side == side) {
- fX = -vec.fY;
- fY = tmp;
- } else {
- SkASSERT(kLeft_Side == side);
- fX = vec.fY;
- fY = -tmp;
- }
- }
-
- /**
- * cast-safe way to treat the point as an array of (2) SkScalars.
- */
- const SkScalar* asScalars() const { return &fX; }
};
typedef SkPoint SkVector;
-static inline bool SkPointsAreFinite(const SkPoint array[], int count) {
- return SkScalarsAreFinite(&array[0].fX, count << 1);
-}
-
#endif
diff --git a/include/core/SkRRect.h b/include/core/SkRRect.h
index 28b3fc441e..06edab9245 100644
--- a/include/core/SkRRect.h
+++ b/include/core/SkRRect.h
@@ -234,15 +234,11 @@ public:
}
friend bool operator==(const SkRRect& a, const SkRRect& b) {
- return a.fRect == b.fRect &&
- SkScalarsEqual(a.fRadii[0].asScalars(),
- b.fRadii[0].asScalars(), 8);
+ return a.fRect == b.fRect && SkScalarsEqual(&a.fRadii[0].fX, &b.fRadii[0].fX, 8);
}
friend bool operator!=(const SkRRect& a, const SkRRect& b) {
- return a.fRect != b.fRect ||
- !SkScalarsEqual(a.fRadii[0].asScalars(),
- b.fRadii[0].asScalars(), 8);
+ return a.fRect != b.fRect || !SkScalarsEqual(&a.fRadii[0].fX, &b.fRadii[0].fX, 8);
}
/**
diff --git a/samplecode/SampleAAGeometry.cpp b/samplecode/SampleAAGeometry.cpp
index da96a0b0ef..55aebda621 100644
--- a/samplecode/SampleAAGeometry.cpp
+++ b/samplecode/SampleAAGeometry.cpp
@@ -13,6 +13,7 @@
#include "SkOpEdgeBuilder.h"
// #include "SkPathOpsSimplifyAA.h"
// #include "SkPathStroker.h"
+#include "SkPointPriv.h"
#include "SkView.h"
#if 0
@@ -1299,7 +1300,7 @@ public:
SkScalar pt_to_line(SkPoint s, SkPoint e, int x, int y) {
SkScalar radius = fWidthControl.fValLo;
SkVector adjOpp = e - s;
- SkScalar lenSq = adjOpp.lengthSqd();
+ SkScalar lenSq = SkPointPriv::LengthSqd(adjOpp);
SkPoint rotated = {
(y - s.fY) * adjOpp.fY + (x - s.fX) * adjOpp.fX,
(y - s.fY) * adjOpp.fX - (x - s.fX) * adjOpp.fY,
diff --git a/samplecode/SampleFatBits.cpp b/samplecode/SampleFatBits.cpp
index 80f656e47c..723dca8605 100644
--- a/samplecode/SampleFatBits.cpp
+++ b/samplecode/SampleFatBits.cpp
@@ -10,6 +10,7 @@
#include "SkView.h"
#include "SkCanvas.h"
#include "SkPath.h"
+#include "SkPointPriv.h"
#include "SkRegion.h"
#include "SkShader.h"
#include "SkUtils.h"
@@ -483,7 +484,7 @@ protected:
SkScalar tol = 12;
for (int i = 0; i < count; ++i) {
- if (fPts[i].equalsWithinTolerance(pt, tol)) {
+ if (SkPointPriv::EqualsWithinTolerance(fPts[i], pt, tol)) {
index = i;
break;
}
diff --git a/samplecode/SampleHT.cpp b/samplecode/SampleHT.cpp
index 50ea2875ec..e1483bef2c 100644
--- a/samplecode/SampleHT.cpp
+++ b/samplecode/SampleHT.cpp
@@ -12,6 +12,7 @@
#include "SkDrawable.h"
#include "SkInterpolator.h"
#include "SkPictureRecorder.h"
+#include "SkPointPriv.h"
#include "SkRandom.h"
const SkRect gUnitSquare = { -1, -1, 1, 1 };
@@ -35,7 +36,7 @@ static bool oval_contains(const SkRect& r, SkScalar x, SkScalar y) {
m.setRectToRect(r, gUnitSquare, SkMatrix::kFill_ScaleToFit);
SkPoint pt;
m.mapXY(x, y, &pt);
- return pt.lengthSqd() <= 1;
+ return SkPointPriv::LengthSqd(pt) <= 1;
}
static SkColor rand_opaque_color(uint32_t seed) {
diff --git a/samplecode/SampleQuadStroker.cpp b/samplecode/SampleQuadStroker.cpp
index ea5f97fa2a..fa45d6eb0d 100644
--- a/samplecode/SampleQuadStroker.cpp
+++ b/samplecode/SampleQuadStroker.cpp
@@ -11,6 +11,7 @@
#include "SkCanvas.h"
#include "SkGeometry.h"
#include "SkPathMeasure.h"
+#include "SkPointPriv.h"
#include "SkRandom.h"
#include "SkRRect.h"
#include "SkColorPriv.h"
@@ -313,7 +314,7 @@ protected:
for (SkScalar dist = 0; dist <= total; dist += delta) {
if (meas.getPosTan(dist, &pos, &tan)) {
tan.scale(radius);
- tan.rotateCCW();
+ SkPointPriv::RotateCCW(&tan);
canvas->drawLine(pos.x() + tan.x(), pos.y() + tan.y(),
pos.x() - tan.x(), pos.y() - tan.y(), paint);
if (0 == index % 10) {
@@ -375,7 +376,7 @@ protected:
return;
}
tan.setLength(radius);
- tan.rotateCCW();
+ SkPointPriv::RotateCCW(&tan);
canvas->drawLine(pos.x() + tan.x(), pos.y() + tan.y(),
pos.x() - tan.x(), pos.y() - tan.y(), paint);
if (0 == index % 10) {
@@ -556,8 +557,8 @@ protected:
before.setLength(fRadius);
after.setLength(fRadius);
SkVector beforeCCW, afterCCW;
- before.rotateCCW(&beforeCCW);
- after.rotateCCW(&afterCCW);
+ SkPointPriv::RotateCCW(before, &beforeCCW);
+ SkPointPriv::RotateCCW(after, &afterCCW);
beforeCCW += pts[0];
afterCCW += pts[2];
*center = beforeCCW;
@@ -566,8 +567,8 @@ protected:
return true;
}
SkVector beforeCW, afterCW;
- before.rotateCW(&beforeCW);
- after.rotateCW(&afterCW);
+ SkPointPriv::RotateCW(before, &beforeCW);
+ SkPointPriv::RotateCW(after, &afterCW);
beforeCW += pts[0];
afterCW += pts[2];
*center = beforeCW;
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 4c4f76ae95..2b505fd80d 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -202,7 +202,7 @@ void SkBitmap::setPixelRef(sk_sp<SkPixelRef> pr, int dx, int dy) {
this->updatePixelsFromRef();
} else {
// ignore dx,dy if there is no pixelref
- fPixelRefOrigin.setZero();
+ fPixelRefOrigin = {0, 0};
fPixels = nullptr;
}
@@ -337,7 +337,7 @@ bool SkBitmap::installMaskPixels(const SkMask& mask) {
void SkBitmap::freePixels() {
fPixelRef = nullptr;
- fPixelRefOrigin.setZero();
+ fPixelRefOrigin = {0, 0};
fPixels = nullptr;
}
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index b36a73aeb2..5d5c9dae73 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -32,7 +32,7 @@ SkBaseDevice::SkBaseDevice(const SkImageInfo& info, const SkSurfaceProps& surfac
: fInfo(info)
, fSurfaceProps(surfaceProps)
{
- fOrigin.setZero();
+ fOrigin = {0, 0};
fCTM.reset();
}
diff --git a/src/core/SkDistanceFieldGen.cpp b/src/core/SkDistanceFieldGen.cpp
index f227d6a30d..9038178d06 100644
--- a/src/core/SkDistanceFieldGen.cpp
+++ b/src/core/SkDistanceFieldGen.cpp
@@ -7,7 +7,7 @@
#include "SkAutoMalloc.h"
#include "SkDistanceFieldGen.h"
-#include "SkPoint.h"
+#include "SkPointPriv.h"
#include "SkTemplates.h"
struct DFData {
@@ -171,7 +171,7 @@ static void init_distances(DFData* data, unsigned char* edges, int width, int he
+ SK_ScalarSqrt2*nextData->fAlpha
- SK_ScalarSqrt2*prevData->fAlpha
+ (nextData+1)->fAlpha - (prevData+1)->fAlpha;
- currGrad.setLengthFast(1.0f);
+ SkPointPriv::SetLengthFast(&currGrad, 1.0f);
// init squared distance to edge and distance vector
float dist = edge_distance(currGrad, currData->fAlpha);
diff --git a/src/core/SkGeometry.cpp b/src/core/SkGeometry.cpp
index 83208aa717..09f304bc31 100644
--- a/src/core/SkGeometry.cpp
+++ b/src/core/SkGeometry.cpp
@@ -9,6 +9,7 @@
#include "SkMatrix.h"
#include "SkNx.h"
#include "SkPoint3.h"
+#include "SkPointPriv.h"
static SkVector to_vector(const Sk2s& x) {
SkVector vector;
@@ -1151,7 +1152,7 @@ bool SkConic::asQuadTol(SkScalar tol) const {
#define kMaxConicToQuadPOW2 5
int SkConic::computeQuadPOW2(SkScalar tol) const {
- if (tol < 0 || !SkScalarIsFinite(tol) || !SkPointsAreFinite(fPts, 3)) {
+ if (tol < 0 || !SkScalarIsFinite(tol) || !SkPointPriv::AreFinite(fPts, 3)) {
return 0;
}
@@ -1240,8 +1241,8 @@ int SkConic::chopIntoQuadsPOW2(SkPoint pts[], int pow2) const {
SkConic dst[2];
this->chop(dst);
// check to see if the first chop generates a pair of lines
- if (dst[0].fPts[1].equalsWithinTolerance(dst[0].fPts[2])
- && dst[1].fPts[0].equalsWithinTolerance(dst[1].fPts[1])) {
+ if (SkPointPriv::EqualsWithinTolerance(dst[0].fPts[1], dst[0].fPts[2]) &&
+ SkPointPriv::EqualsWithinTolerance(dst[1].fPts[0], dst[1].fPts[1])) {
pts[1] = pts[2] = pts[3] = dst[0].fPts[1]; // set ctrl == end to make lines
pts[4] = dst[1].fPts[2];
pow2 = 1;
@@ -1254,7 +1255,7 @@ commonFinitePtCheck:
const int quadCount = 1 << pow2;
const int ptCount = 2 * quadCount + 1;
SkASSERT(endPts - pts == ptCount);
- if (!SkPointsAreFinite(pts, ptCount)) {
+ if (!SkPointPriv::AreFinite(pts, ptCount)) {
// if we generated a non-finite, pin ourselves to the middle of the hull,
// as our first and last are already on the first/last pts of the hull.
for (int i = 1; i < ptCount - 1; ++i) {
@@ -1422,7 +1423,7 @@ int SkConic::BuildUnitArc(const SkVector& uStart, const SkVector& uStop, SkRotat
//
const SkScalar cosThetaOver2 = SkScalarSqrt((1 + dot) / 2);
offCurve.setLength(SkScalarInvert(cosThetaOver2));
- if (!lastQ.equalsWithinTolerance(offCurve)) {
+ if (!SkPointPriv::EqualsWithinTolerance(lastQ, offCurve)) {
dst[conicCount].set(lastQ, offCurve, finalP, cosThetaOver2);
conicCount += 1;
}
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index a053c767dc..1b443b2f46 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -14,6 +14,7 @@
#include "SkMatrixPriv.h"
#include "SkPathPriv.h"
#include "SkPathRef.h"
+#include "SkPointPriv.h"
#include "SkRRect.h"
static float poly_eval(float A, float B, float C, float t) {
@@ -2408,7 +2409,7 @@ struct Convexicator {
++fPtCount;
} else {
SkVector vec = pt - fCurrPt;
- SkScalar lengthSqd = vec.lengthSqd();
+ SkScalar lengthSqd = SkPointPriv::LengthSqd(vec);
if (!SkScalarIsFinite(lengthSqd)) {
fIsFinite = false;
} else if (lengthSqd) {
@@ -2470,8 +2471,10 @@ struct Convexicator {
}
}
- if (!SkScalarNearlyZero(fLastVec.lengthSqd(), SK_ScalarNearlyZero*SK_ScalarNearlyZero) &&
- !SkScalarNearlyZero(curVec.lengthSqd(), SK_ScalarNearlyZero*SK_ScalarNearlyZero) &&
+ if (!SkScalarNearlyZero(SkPointPriv::LengthSqd(fLastVec),
+ SK_ScalarNearlyZero*SK_ScalarNearlyZero) &&
+ !SkScalarNearlyZero(SkPointPriv::LengthSqd(curVec),
+ SK_ScalarNearlyZero*SK_ScalarNearlyZero) &&
fLastVec.dot(curVec) < 0.0f) {
return kBackwards_DirChange;
}
@@ -3352,7 +3355,7 @@ bool SkPath::contains(SkScalar x, SkScalar y) const {
if (tangents.count() > oldCount) {
int last = tangents.count() - 1;
const SkVector& tangent = tangents[last];
- if (SkScalarNearlyZero(tangent.lengthSqd())) {
+ if (SkScalarNearlyZero(SkPointPriv::LengthSqd(tangent))) {
tangents.remove(last);
} else {
for (int index = 0; index < last; ++index) {
@@ -3601,3 +3604,21 @@ DONE:
max.store((SkPoint*)&bounds.fRight);
return bounds;
}
+
+bool SkPath::IsLineDegenerate(const SkPoint& p1, const SkPoint& p2, bool exact) {
+ return exact ? p1 == p2 : SkPointPriv::EqualsWithinTolerance(p1, p2);
+}
+
+bool SkPath::IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2,
+ const SkPoint& p3, bool exact) {
+ return exact ? p1 == p2 && p2 == p3 : SkPointPriv::EqualsWithinTolerance(p1, p2) &&
+ SkPointPriv::EqualsWithinTolerance(p2, p3);
+}
+
+bool SkPath::IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2,
+ const SkPoint& p3, const SkPoint& p4, bool exact) {
+ return exact ? p1 == p2 && p2 == p3 && p3 == p4 :
+ SkPointPriv::EqualsWithinTolerance(p1, p2) &&
+ SkPointPriv::EqualsWithinTolerance(p2, p3) &&
+ SkPointPriv::EqualsWithinTolerance(p3, p4);
+}
diff --git a/src/core/SkPoint.cpp b/src/core/SkPoint.cpp
index 4c66b44bac..8992a58b1b 100644
--- a/src/core/SkPoint.cpp
+++ b/src/core/SkPoint.cpp
@@ -7,8 +7,9 @@
#include "SkMathPriv.h"
-#include "SkPoint.h"
+#include "SkPointPriv.h"
+#if 0
void SkIPoint::rotateCW(SkIPoint* dst) const {
SkASSERT(dst);
@@ -26,27 +27,10 @@ void SkIPoint::rotateCCW(SkIPoint* dst) const {
dst->fX = fY;
dst->fY = -tmp;
}
+#endif
///////////////////////////////////////////////////////////////////////////////
-void SkPoint::rotateCW(SkPoint* dst) const {
- SkASSERT(dst);
-
- // use a tmp in case this == dst
- SkScalar tmp = fX;
- dst->fX = -fY;
- dst->fY = tmp;
-}
-
-void SkPoint::rotateCCW(SkPoint* dst) const {
- SkASSERT(dst);
-
- // use a tmp in case this == dst
- SkScalar tmp = fX;
- dst->fX = fY;
- dst->fY = -tmp;
-}
-
void SkPoint::scale(SkScalar scale, SkPoint* dst) const {
SkASSERT(dst);
dst->set(fX * scale, fY * scale);
@@ -164,14 +148,10 @@ bool SkPoint::setLength(float x, float y, float length) {
return true;
}
-bool SkPoint::setLengthFast(float length) {
- return this->setLengthFast(fX, fY, length);
-}
-
-bool SkPoint::setLengthFast(float x, float y, float length) {
+bool SkPointPriv::SetLengthFast(SkPoint* pt, float length) {
float mag2;
- if (is_length_nearly_zero(x, y, &mag2)) {
- this->set(0, 0);
+ if (is_length_nearly_zero(pt->fX, pt->fY, &mag2)) {
+ pt->set(0, 0);
return false;
}
@@ -182,30 +162,30 @@ bool SkPoint::setLengthFast(float x, float y, float length) {
// our mag2 step overflowed to infinity, so use doubles instead.
// much slower, but needed when x or y are very large, other wise we
// divide by inf. and return (0,0) vector.
- double xx = x;
- double yy = y;
+ double xx = pt->fX;
+ double yy = pt->fY;
scale = (float)(length / sqrt(xx * xx + yy * yy));
}
- fX = x * scale;
- fY = y * scale;
+ pt->fX *= scale;
+ pt->fY *= scale;
return true;
}
///////////////////////////////////////////////////////////////////////////////
-SkScalar SkPoint::distanceToLineBetweenSqd(const SkPoint& a,
+SkScalar SkPointPriv::DistanceToLineBetweenSqd(const SkPoint& pt, const SkPoint& a,
const SkPoint& b,
- Side* side) const {
+ Side* side) {
SkVector u = b - a;
- SkVector v = *this - a;
+ SkVector v = pt - a;
- SkScalar uLengthSqd = u.lengthSqd();
+ SkScalar uLengthSqd = LengthSqd(u);
SkScalar det = u.cross(v);
if (side) {
- SkASSERT(-1 == SkPoint::kLeft_Side &&
- 0 == SkPoint::kOn_Side &&
+ SkASSERT(-1 == kLeft_Side &&
+ 0 == kOn_Side &&
1 == kRight_Side);
*side = (Side) SkScalarSignAsInt(det);
}
@@ -214,8 +194,8 @@ SkScalar SkPoint::distanceToLineBetweenSqd(const SkPoint& a,
return temp;
}
-SkScalar SkPoint::distanceToLineSegmentBetweenSqd(const SkPoint& a,
- const SkPoint& b) const {
+SkScalar SkPointPriv::DistanceToLineSegmentBetweenSqd(const SkPoint& pt, const SkPoint& a,
+ const SkPoint& b) {
// See comments to distanceToLineBetweenSqd. If the projection of c onto
// u is between a and b then this returns the same result as that
// function. Otherwise, it returns the distance to the closer of a and
@@ -233,15 +213,15 @@ SkScalar SkPoint::distanceToLineSegmentBetweenSqd(const SkPoint& a,
// avoid a sqrt to compute |u|.
SkVector u = b - a;
- SkVector v = *this - a;
+ SkVector v = pt - a;
- SkScalar uLengthSqd = u.lengthSqd();
+ SkScalar uLengthSqd = LengthSqd(u);
SkScalar uDotV = SkPoint::DotProduct(u, v);
if (uDotV <= 0) {
- return v.lengthSqd();
+ return LengthSqd(v);
} else if (uDotV > uLengthSqd) {
- return b.distanceToSqd(*this);
+ return DistanceToSqd(b, pt);
} else {
SkScalar det = u.cross(v);
SkScalar temp = det / uLengthSqd;
diff --git a/src/core/SkPointPriv.h b/src/core/SkPointPriv.h
index 6685b15176..6c8fd480a7 100644
--- a/src/core/SkPointPriv.h
+++ b/src/core/SkPointPriv.h
@@ -12,6 +12,100 @@
class SkPointPriv {
public:
+ enum Side {
+ kLeft_Side = -1,
+ kOn_Side = 0,
+ kRight_Side = 1,
+ };
+
+ static bool AreFinite(const SkPoint array[], int count) {
+ return SkScalarsAreFinite(&array[0].fX, count << 1);
+ }
+
+ static const SkScalar* AsScalars(const SkPoint& pt) { return &pt.fX; }
+
+ static bool CanNormalize(SkScalar dx, SkScalar dy) {
+ // Simple enough (and performance critical sometimes) so we inline it.
+ return (dx*dx + dy*dy) > (SK_ScalarNearlyZero * SK_ScalarNearlyZero);
+ }
+
+ static SkScalar DistanceToLineBetweenSqd(const SkPoint& pt, const SkPoint& a,
+ const SkPoint& b, Side* side = nullptr);
+
+ static SkScalar DistanceToLineBetween(const SkPoint& pt, const SkPoint& a,
+ const SkPoint& b, Side* side = nullptr) {
+ return SkScalarSqrt(DistanceToLineBetweenSqd(pt, a, b, side));
+ }
+
+ static SkScalar DistanceToLineSegmentBetweenSqd(const SkPoint& pt, const SkPoint& a,
+ const SkPoint& b);
+
+ static SkScalar DistanceToLineSegmentBetween(const SkPoint& pt, const SkPoint& a,
+ const SkPoint& b) {
+ return SkScalarSqrt(DistanceToLineSegmentBetweenSqd(pt, a, b));
+ }
+
+ static SkScalar DistanceToSqd(const SkPoint& pt, const SkPoint& a) {
+ SkScalar dx = pt.fX - a.fX;
+ SkScalar dy = pt.fY - a.fY;
+ return dx * dx + dy * dy;
+ }
+
+ static bool EqualsWithinTolerance(const SkPoint& p1, const SkPoint& p2) {
+ return !CanNormalize(p1.fX - p2.fX, p1.fY - p2.fY);
+ }
+
+ static bool EqualsWithinTolerance(const SkPoint& pt, const SkPoint& p, SkScalar tol) {
+ return SkScalarNearlyZero(pt.fX - p.fX, tol)
+ && SkScalarNearlyZero(pt.fY - p.fY, tol);
+ }
+
+ static SkScalar LengthSqd(const SkPoint& pt) {
+ return SkPoint::DotProduct(pt, pt);
+ }
+
+ static void Negate(SkIPoint& pt) {
+ pt.fX = -pt.fX;
+ pt.fY = -pt.fY;
+ }
+
+ static void RotateCCW(const SkPoint& src, SkPoint* dst) {
+ // use a tmp in case src == dst
+ SkScalar tmp = src.fX;
+ dst->fX = src.fY;
+ dst->fY = -tmp;
+ }
+
+ static void RotateCCW(SkPoint* pt) {
+ RotateCCW(*pt, pt);
+ }
+
+ static void RotateCW(const SkPoint& src, SkPoint* dst) {
+ // use a tmp in case src == dst
+ SkScalar tmp = src.fX;
+ dst->fX = -src.fY;
+ dst->fY = tmp;
+ }
+
+ static void RotateCW(SkPoint* pt) {
+ RotateCW(*pt, pt);
+ }
+
+ static bool SetLengthFast(SkPoint* pt, float length);
+
+ static void SetOrthog(SkPoint* pt, const SkPoint& vec, Side side = kLeft_Side) {
+ // vec could be this
+ SkScalar tmp = vec.fX;
+ if (kRight_Side == side) {
+ pt->fX = -vec.fY;
+ pt->fY = tmp;
+ } else {
+ SkASSERT(kLeft_Side == side);
+ pt->fX = vec.fY;
+ pt->fY = -tmp;
+ }
+ }
+
// counter-clockwise fan
static void SetRectFan(SkPoint v[], SkScalar l, SkScalar t, SkScalar r, SkScalar b,
size_t stride) {
@@ -33,6 +127,7 @@ public:
((SkPoint*)((intptr_t)v + 2 * stride))->set(r, t);
((SkPoint*)((intptr_t)v + 3 * stride))->set(r, b);
}
+
};
#endif
diff --git a/src/core/SkStroke.cpp b/src/core/SkStroke.cpp
index 0852f56bd2..ab8df833c1 100644
--- a/src/core/SkStroke.cpp
+++ b/src/core/SkStroke.cpp
@@ -8,6 +8,7 @@
#include "SkStrokerPriv.h"
#include "SkGeometry.h"
#include "SkPathPriv.h"
+#include "SkPointPriv.h"
enum {
kTangent_RecursiveLimit,
@@ -48,7 +49,7 @@ static_assert(SK_ARRAY_COUNT(kRecursiveLimits) == kQuad_RecursiveLimit + 1,
#endif
static inline bool degenerate_vector(const SkVector& v) {
- return !SkPoint::CanNormalize(v.fX, v.fY);
+ return !SkPointPriv::CanNormalize(v.fX, v.fY);
}
static bool set_normal_unitnormal(const SkPoint& before, const SkPoint& after, SkScalar scale,
@@ -58,7 +59,7 @@ static bool set_normal_unitnormal(const SkPoint& before, const SkPoint& after, S
(after.fY - before.fY) * scale)) {
return false;
}
- unitNormal->rotateCCW();
+ SkPointPriv::RotateCCW(unitNormal);
unitNormal->scale(radius, normal);
return true;
}
@@ -69,7 +70,7 @@ static bool set_normal_unitnormal(const SkVector& vec,
if (!unitNormal->setNormalize(vec.fX, vec.fY)) {
return false;
}
- unitNormal->rotateCCW();
+ SkPointPriv::RotateCCW(unitNormal);
unitNormal->scale(radius, normal);
return true;
}
@@ -420,7 +421,7 @@ static bool has_valid_tangent(const SkPath::Iter* iter) {
}
void SkPathStroker::lineTo(const SkPoint& currPt, const SkPath::Iter* iter) {
- bool teenyLine = fPrevPt.equalsWithinTolerance(currPt, SK_ScalarNearlyZero * fInvResScale);
+ bool teenyLine = SkPointPriv::EqualsWithinTolerance(fPrevPt, currPt, SK_ScalarNearlyZero * fInvResScale);
if (SkStrokerPriv::CapFactory(SkPaint::kButt_Cap) == fCapper && teenyLine) {
return;
}
@@ -489,7 +490,7 @@ void SkPathStroker::init(StrokeType strokeType, SkQuadConstruct* quadPts, SkScal
static SkScalar pt_to_line(const SkPoint& pt, const SkPoint& lineStart, const SkPoint& lineEnd) {
SkVector dxy = lineEnd - lineStart;
if (degenerate_vector(dxy)) {
- return pt.distanceToSqd(lineStart);
+ return SkPointPriv::DistanceToSqd(pt, lineStart);
}
SkVector ab0 = pt - lineStart;
SkScalar numer = dxy.dot(ab0);
@@ -498,7 +499,7 @@ static SkScalar pt_to_line(const SkPoint& pt, const SkPoint& lineStart, const Sk
SkPoint hit;
hit.fX = lineStart.fX * (1 - t) + lineEnd.fX * t;
hit.fY = lineStart.fY * (1 - t) + lineEnd.fY * t;
- return hit.distanceToSqd(pt);
+ return SkPointPriv::DistanceToSqd(hit, pt);
}
/* Given a cubic, determine if all four points are in a line.
@@ -969,14 +970,14 @@ bool SkPathStroker::ptInQuadBounds(const SkPoint quad[3], const SkPoint& pt) con
}
static bool points_within_dist(const SkPoint& nearPt, const SkPoint& farPt, SkScalar limit) {
- return nearPt.distanceToSqd(farPt) <= limit * limit;
+ return SkPointPriv::DistanceToSqd(nearPt, farPt) <= limit * limit;
}
static bool sharp_angle(const SkPoint quad[3]) {
SkVector smaller = quad[1] - quad[0];
SkVector larger = quad[1] - quad[2];
- SkScalar smallerLen = smaller.lengthSqd();
- SkScalar largerLen = larger.lengthSqd();
+ SkScalar smallerLen = SkPointPriv::LengthSqd(smaller);
+ SkScalar largerLen = SkPointPriv::LengthSqd(larger);
if (smallerLen > largerLen) {
SkTSwap(smaller, larger);
largerLen = smallerLen;
diff --git a/src/core/SkStrokerPriv.cpp b/src/core/SkStrokerPriv.cpp
index 52144cdc5f..be7b1f5eb4 100644
--- a/src/core/SkStrokerPriv.cpp
+++ b/src/core/SkStrokerPriv.cpp
@@ -8,6 +8,7 @@
#include "SkStrokerPriv.h"
#include "SkGeometry.h"
#include "SkPath.h"
+#include "SkPointPriv.h"
static void ButtCapper(SkPath* path, const SkPoint& pivot, const SkVector& normal,
const SkPoint& stop, SkPath*) {
@@ -17,7 +18,7 @@ static void ButtCapper(SkPath* path, const SkPoint& pivot, const SkVector& norma
static void RoundCapper(SkPath* path, const SkPoint& pivot, const SkVector& normal,
const SkPoint& stop, SkPath*) {
SkVector parallel;
- normal.rotateCW(&parallel);
+ SkPointPriv::RotateCW(normal, &parallel);
SkPoint projectedCenter = pivot + parallel;
@@ -28,7 +29,7 @@ static void RoundCapper(SkPath* path, const SkPoint& pivot, const SkVector& norm
static void SquareCapper(SkPath* path, const SkPoint& pivot, const SkVector& normal,
const SkPoint& stop, SkPath* otherPath) {
SkVector parallel;
- normal.rotateCW(&parallel);
+ SkPointPriv::RotateCW(normal, &parallel);
if (otherPath) {
path->setLastPt(pivot.fX + normal.fX + parallel.fX, pivot.fY + normal.fY + parallel.fY);
diff --git a/src/effects/SkDiscretePathEffect.cpp b/src/effects/SkDiscretePathEffect.cpp
index b9d76f5b13..f188bfa818 100644
--- a/src/effects/SkDiscretePathEffect.cpp
+++ b/src/effects/SkDiscretePathEffect.cpp
@@ -9,6 +9,7 @@
#include "SkDiscretePathEffect.h"
#include "SkFixed.h"
#include "SkPathMeasure.h"
+#include "SkPointPriv.h"
#include "SkReadBuffer.h"
#include "SkStrokeRec.h"
#include "SkWriteBuffer.h"
@@ -26,7 +27,7 @@ sk_sp<SkPathEffect> SkDiscretePathEffect::Make(SkScalar segLength, SkScalar devi
static void Perterb(SkPoint* p, const SkVector& tangent, SkScalar scale) {
SkVector normal = tangent;
- normal.rotateCCW();
+ SkPointPriv::RotateCCW(&normal);
normal.setLength(scale);
*p += normal;
}
diff --git a/src/effects/SkMergeImageFilter.cpp b/src/effects/SkMergeImageFilter.cpp
index c84fed7571..1d425ed04e 100644
--- a/src/effects/SkMergeImageFilter.cpp
+++ b/src/effects/SkMergeImageFilter.cpp
@@ -43,7 +43,7 @@ sk_sp<SkSpecialImage> SkMergeImageFilter::onFilterImage(SkSpecialImage* source,
// Filter all of the inputs.
for (int i = 0; i < inputCount; ++i) {
- offsets[i].setZero();
+ offsets[i] = { 0, 0 };
inputs[i] = this->filterInput(i, source, ctx, &offsets[i]);
if (!inputs[i]) {
continue;
diff --git a/src/effects/SkOffsetImageFilter.cpp b/src/effects/SkOffsetImageFilter.cpp
index 3852523c11..a833987185 100644
--- a/src/effects/SkOffsetImageFilter.cpp
+++ b/src/effects/SkOffsetImageFilter.cpp
@@ -11,6 +11,7 @@
#include "SkImageFilterPriv.h"
#include "SkMatrix.h"
#include "SkPaint.h"
+#include "SkPointPriv.h"
#include "SkReadBuffer.h"
#include "SkSpecialImage.h"
#include "SkSpecialSurface.h"
@@ -99,7 +100,7 @@ SkIRect SkOffsetImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMatr
MapDirection direction) const {
SkIPoint vec = map_offset_vector(ctm, fOffset);
if (kReverse_MapDirection == direction) {
- vec.negate();
+ SkPointPriv::Negate(vec);
}
return src.makeOffset(vec.fX, vec.fY);
diff --git a/src/gpu/GrDistanceFieldGenFromVector.cpp b/src/gpu/GrDistanceFieldGenFromVector.cpp
index 8867ab1ab6..fdaeaf2964 100644
--- a/src/gpu/GrDistanceFieldGenFromVector.cpp
+++ b/src/gpu/GrDistanceFieldGenFromVector.cpp
@@ -14,7 +14,7 @@
#include "SkGeometry.h"
#include "SkMatrix.h"
#include "SkPathOps.h"
-#include "SkPoint.h"
+#include "SkPointPriv.h"
/**
* If a scanline (a row of texel) cross from the kRight_SegSide
@@ -370,8 +370,8 @@ static inline void add_line_to_segment(const SkPoint pts[2],
static inline void add_quad_segment(const SkPoint pts[3],
PathSegmentArray* segments) {
- if (pts[0].distanceToSqd(pts[1]) < kCloseSqd ||
- pts[1].distanceToSqd(pts[2]) < kCloseSqd ||
+ if (SkPointPriv::DistanceToSqd(pts[0], pts[1]) < kCloseSqd ||
+ SkPointPriv::DistanceToSqd(pts[1], pts[2]) < kCloseSqd ||
is_colinear(pts)) {
if (pts[0] != pts[2]) {
SkPoint line_pts[2];
diff --git a/src/gpu/GrPathUtils.cpp b/src/gpu/GrPathUtils.cpp
index f64affb396..e36c67cc88 100644
--- a/src/gpu/GrPathUtils.cpp
+++ b/src/gpu/GrPathUtils.cpp
@@ -9,6 +9,7 @@
#include "GrTypes.h"
#include "SkMathPriv.h"
+#include "SkPointPriv.h"
static const SkScalar gMinCurveTol = 0.0001f;
@@ -41,7 +42,7 @@ uint32_t GrPathUtils::quadraticPointCount(const SkPoint points[], SkScalar tol)
// You should have called scaleToleranceToSrc, which guarantees this
SkASSERT(tol >= gMinCurveTol);
- SkScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]);
+ SkScalar d = SkPointPriv::DistanceToLineSegmentBetween(points[1], points[0], points[2]);
if (!SkScalarIsFinite(d)) {
return kMaxPointsPerCurve;
} else if (d <= tol) {
@@ -75,7 +76,7 @@ uint32_t GrPathUtils::generateQuadraticPoints(const SkPoint& p0,
SkPoint** points,
uint32_t pointsLeft) {
if (pointsLeft < 2 ||
- (p1.distanceToLineSegmentBetweenSqd(p0, p2)) < tolSqd) {
+ (SkPointPriv::DistanceToLineSegmentBetweenSqd(p1, p0, p2)) < tolSqd) {
(*points)[0] = p2;
*points += 1;
return 1;
@@ -99,8 +100,8 @@ uint32_t GrPathUtils::cubicPointCount(const SkPoint points[],
SkASSERT(tol >= gMinCurveTol);
SkScalar d = SkTMax(
- points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]),
- points[2].distanceToLineSegmentBetweenSqd(points[0], points[3]));
+ SkPointPriv::DistanceToLineSegmentBetweenSqd(points[1], points[0], points[3]),
+ SkPointPriv::DistanceToLineSegmentBetweenSqd(points[2], points[0], points[3]));
d = SkScalarSqrt(d);
if (!SkScalarIsFinite(d)) {
return kMaxPointsPerCurve;
@@ -132,8 +133,8 @@ uint32_t GrPathUtils::generateCubicPoints(const SkPoint& p0,
SkPoint** points,
uint32_t pointsLeft) {
if (pointsLeft < 2 ||
- (p1.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd &&
- p2.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd)) {
+ (SkPointPriv::DistanceToLineSegmentBetweenSqd(p1, p0, p3) < tolSqd &&
+ SkPointPriv::DistanceToLineSegmentBetweenSqd(p2, p0, p3) < tolSqd)) {
(*points)[0] = p3;
*points += 1;
return 1;
@@ -226,14 +227,14 @@ void GrPathUtils::QuadUVMatrix::set(const SkPoint qPts[3]) {
|| SkScalarNearlyZero((float)det, SK_ScalarNearlyZero * SK_ScalarNearlyZero)) {
// The quad is degenerate. Hopefully this is rare. Find the pts that are
// farthest apart to compute a line (unless it is really a pt).
- SkScalar maxD = qPts[0].distanceToSqd(qPts[1]);
+ SkScalar maxD = SkPointPriv::DistanceToSqd(qPts[0], qPts[1]);
int maxEdge = 0;
- SkScalar d = qPts[1].distanceToSqd(qPts[2]);
+ SkScalar d = SkPointPriv::DistanceToSqd(qPts[1], qPts[2]);
if (d > maxD) {
maxD = d;
maxEdge = 1;
}
- d = qPts[2].distanceToSqd(qPts[0]);
+ d = SkPointPriv::DistanceToSqd(qPts[2], qPts[0]);
if (d > maxD) {
maxD = d;
maxEdge = 2;
@@ -245,7 +246,7 @@ void GrPathUtils::QuadUVMatrix::set(const SkPoint qPts[3]) {
// when looking from the point 0 down the line we want positive
// distances to be to the left. This matches the non-degenerate
// case.
- lineVec.setOrthog(lineVec, SkPoint::kLeft_Side);
+ SkPointPriv::SetOrthog(&lineVec, lineVec, SkPointPriv::kLeft_Side);
// first row
fM[0] = 0;
fM[1] = 0;
@@ -400,8 +401,8 @@ void convert_noninflect_cubic_to_quads(const SkPoint p[4],
SkVector ab = p[1] - p[0];
SkVector dc = p[2] - p[3];
- if (ab.lengthSqd() < SK_ScalarNearlyZero) {
- if (dc.lengthSqd() < SK_ScalarNearlyZero) {
+ if (SkPointPriv::LengthSqd(ab) < SK_ScalarNearlyZero) {
+ if (SkPointPriv::LengthSqd(dc) < SK_ScalarNearlyZero) {
SkPoint* degQuad = quads->push_back_n(3);
degQuad[0] = p[0];
degQuad[1] = p[0];
@@ -410,7 +411,7 @@ void convert_noninflect_cubic_to_quads(const SkPoint p[4],
}
ab = p[2] - p[0];
}
- if (dc.lengthSqd() < SK_ScalarNearlyZero) {
+ if (SkPointPriv::LengthSqd(dc) < SK_ScalarNearlyZero) {
dc = p[1] - p[3];
}
@@ -423,10 +424,10 @@ void convert_noninflect_cubic_to_quads(const SkPoint p[4],
if (constrainWithinTangents) {
SkVector da = p[0] - p[3];
- bool doQuads = dc.lengthSqd() < SK_ScalarNearlyZero ||
- ab.lengthSqd() < SK_ScalarNearlyZero;
+ bool doQuads = SkPointPriv::LengthSqd(dc) < SK_ScalarNearlyZero ||
+ SkPointPriv::LengthSqd(ab) < SK_ScalarNearlyZero;
if (!doQuads) {
- SkScalar invDALengthSqd = da.lengthSqd();
+ SkScalar invDALengthSqd = SkPointPriv::LengthSqd(da);
if (invDALengthSqd > SK_ScalarNearlyZero) {
invDALengthSqd = SkScalarInvert(invDALengthSqd);
// cross(ab, da)^2/length(da)^2 == sqd distance from b to line from d to a.
@@ -479,7 +480,7 @@ void convert_noninflect_cubic_to_quads(const SkPoint p[4],
SkVector c1 = p[3];
c1 += dc;
- SkScalar dSqd = sublevel > kMaxSubdivs ? 0 : c0.distanceToSqd(c1);
+ SkScalar dSqd = sublevel > kMaxSubdivs ? 0 : SkPointPriv::DistanceToSqd(c0, c1);
if (dSqd < toleranceSqd) {
SkPoint cAvg = c0;
cAvg += c1;
@@ -490,9 +491,9 @@ void convert_noninflect_cubic_to_quads(const SkPoint p[4],
if (constrainWithinTangents &&
!is_point_within_cubic_tangents(p[0], ab, dc, p[3], dir, cAvg)) {
// choose a new cAvg that is the intersection of the two tangent lines.
- ab.setOrthog(ab);
+ SkPointPriv::SetOrthog(&ab, ab);
SkScalar z0 = -ab.dot(p[0]);
- dc.setOrthog(dc);
+ SkPointPriv::SetOrthog(&dc, dc);
SkScalar z1 = -dc.dot(p[3]);
cAvg.fX = ab.fY * z1 - z0 * dc.fY;
cAvg.fY = z0 * dc.fX - ab.fX * z1;
@@ -501,8 +502,8 @@ void convert_noninflect_cubic_to_quads(const SkPoint p[4],
cAvg.fX *= z;
cAvg.fY *= z;
if (sublevel <= kMaxSubdivs) {
- SkScalar d0Sqd = c0.distanceToSqd(cAvg);
- SkScalar d1Sqd = c1.distanceToSqd(cAvg);
+ SkScalar d0Sqd = SkPointPriv::DistanceToSqd(c0, cAvg);
+ SkScalar d1Sqd = SkPointPriv::DistanceToSqd(c1, cAvg);
// We need to subdivide if d0 + d1 > tolerance but we have the sqd values. We know
// the distances and tolerance can't be negative.
// (d0 + d1)^2 > toleranceSqd
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index b259d7831f..53df4bed0e 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -1161,8 +1161,8 @@ bool GrRenderTargetContext::drawFastShadow(const GrClip& clip,
rrect.rect().fRight - dr,
spotShadowRRect.rect().fBottom -
rrect.rect().fBottom - dr);
- maxOffset = SkScalarSqrt(SkTMax(upperLeftOffset.lengthSqd(),
- lowerRightOffset.lengthSqd())) + dr;
+ maxOffset = SkScalarSqrt(SkTMax(SkPointPriv::LengthSqd(upperLeftOffset),
+ SkPointPriv::LengthSqd(lowerRightOffset))) + dr;
}
insetWidth += maxOffset;
}
diff --git a/src/gpu/GrTessellator.cpp b/src/gpu/GrTessellator.cpp
index a1ea284bab..a183439634 100644
--- a/src/gpu/GrTessellator.cpp
+++ b/src/gpu/GrTessellator.cpp
@@ -13,6 +13,7 @@
#include "SkArenaAlloc.h"
#include "SkGeometry.h"
#include "SkPath.h"
+#include "SkPointPriv.h"
#include <stdio.h>
@@ -635,7 +636,7 @@ SkScalar quad_error_at(const SkPoint pts[3], SkScalar t, SkScalar u) {
if (!p0.isFinite() || !mid.isFinite() || !p1.isFinite()) {
return 0;
}
- return mid.distanceToLineSegmentBetweenSqd(p0, p1);
+ return SkPointPriv::DistanceToLineSegmentBetweenSqd(mid, p0, p1);
}
void append_quadratic_to_contour(const SkPoint pts[3], SkScalar toleranceSqd, VertexList* contour,
@@ -669,8 +670,8 @@ void generate_cubic_points(const SkPoint& p0,
VertexList* contour,
int pointsLeft,
SkArenaAlloc& alloc) {
- SkScalar d1 = p1.distanceToLineSegmentBetweenSqd(p0, p3);
- SkScalar d2 = p2.distanceToLineSegmentBetweenSqd(p0, p3);
+ SkScalar d1 = SkPointPriv::DistanceToLineSegmentBetweenSqd(p1, p0, p3);
+ SkScalar d2 = SkPointPriv::DistanceToLineSegmentBetweenSqd(p2, p0, p3);
if (pointsLeft < 2 || (d1 < tolSqd && d2 < tolSqd) ||
!SkScalarIsFinite(d1) || !SkScalarIsFinite(d2)) {
append_point_to_contour(p3, contour, alloc);
diff --git a/src/gpu/ops/GrAAConvexPathRenderer.cpp b/src/gpu/ops/GrAAConvexPathRenderer.cpp
index 0e37238389..3c84b32df7 100644
--- a/src/gpu/ops/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAAConvexPathRenderer.cpp
@@ -19,6 +19,7 @@
#include "GrSimpleMeshDrawOpHelper.h"
#include "SkGeometry.h"
#include "SkPathPriv.h"
+#include "SkPointPriv.h"
#include "SkString.h"
#include "SkTraceEvent.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
@@ -122,11 +123,11 @@ static void compute_vectors(SegmentArray* segments,
int count = segments->count();
// Make the normals point towards the outside
- SkPoint::Side normSide;
+ SkPointPriv::Side normSide;
if (dir == SkPathPriv::kCCW_FirstDirection) {
- normSide = SkPoint::kRight_Side;
+ normSide = SkPointPriv::kRight_Side;
} else {
- normSide = SkPoint::kLeft_Side;
+ normSide = SkPointPriv::kLeft_Side;
}
*vCount = 0;
@@ -142,7 +143,7 @@ static void compute_vectors(SegmentArray* segments,
for (int p = 0; p < n; ++p) {
segb.fNorms[p] = segb.fPts[p] - *prevPt;
segb.fNorms[p].normalize();
- segb.fNorms[p].setOrthog(segb.fNorms[p], normSide);
+ SkPointPriv::SetOrthog(&segb.fNorms[p], segb.fNorms[p], normSide);
prevPt = &segb.fPts[p];
}
if (Segment::kLine == segb.fType) {
@@ -192,10 +193,10 @@ static void update_degenerate_test(DegenerateTestData* data, const SkPoint& pt)
data->fStage = DegenerateTestData::kPoint;
break;
case DegenerateTestData::kPoint:
- if (pt.distanceToSqd(data->fFirstPoint) > kCloseSqd) {
+ if (SkPointPriv::DistanceToSqd(pt, data->fFirstPoint) > kCloseSqd) {
data->fLineNormal = pt - data->fFirstPoint;
data->fLineNormal.normalize();
- data->fLineNormal.setOrthog(data->fLineNormal);
+ SkPointPriv::SetOrthog(&data->fLineNormal, data->fLineNormal);
data->fLineC = -data->fLineNormal.dot(data->fFirstPoint);
data->fStage = DegenerateTestData::kLine;
}
@@ -235,7 +236,8 @@ static inline void add_line_to_segment(const SkPoint& pt,
static inline void add_quad_segment(const SkPoint pts[3],
SegmentArray* segments) {
- if (pts[0].distanceToSqd(pts[1]) < kCloseSqd || pts[1].distanceToSqd(pts[2]) < kCloseSqd) {
+ if (SkPointPriv::DistanceToSqd(pts[0], pts[1]) < kCloseSqd ||
+ SkPointPriv::DistanceToSqd(pts[1], pts[2]) < kCloseSqd) {
if (pts[0] != pts[2]) {
add_line_to_segment(pts[2], segments);
}
@@ -425,8 +427,8 @@ static void create_vertices(const SegmentArray& segments,
// we draw the line edge as a degenerate quad (u is 0, v is the
// signed distance to the edge)
- SkScalar dist = fanPt.distanceToLineBetween(verts[*v + 1].fPos,
- verts[*v + 2].fPos);
+ SkScalar dist = SkPointPriv::DistanceToLineBetween(fanPt, verts[*v + 1].fPos,
+ verts[*v + 2].fPos);
verts[*v + 0].fUV.set(0, dist);
verts[*v + 1].fUV.set(0, 0);
verts[*v + 2].fUV.set(0, 0);
diff --git a/src/gpu/ops/GrAAConvexTessellator.cpp b/src/gpu/ops/GrAAConvexTessellator.cpp
index 6c0125a576..9927d98b11 100644
--- a/src/gpu/ops/GrAAConvexTessellator.cpp
+++ b/src/gpu/ops/GrAAConvexTessellator.cpp
@@ -55,7 +55,7 @@ static SkScalar perp_intersect(const SkPoint& p0, const SkPoint& n0,
}
static bool duplicate_pt(const SkPoint& p0, const SkPoint& p1) {
- SkScalar distSq = p0.distanceToSqd(p1);
+ SkScalar distSq = SkPointPriv::DistanceToSqd(p0, p1);
return distSq < kCloseSqd;
}
@@ -149,10 +149,10 @@ void GrAAConvexTessellator::computeBisectors() {
for (int cur = 0; cur < fBisectors.count(); prev = cur, ++cur) {
fBisectors[cur] = fNorms[cur] + fNorms[prev];
if (!fBisectors[cur].normalize()) {
- SkASSERT(SkPoint::kLeft_Side == fSide || SkPoint::kRight_Side == fSide);
- fBisectors[cur].setOrthog(fNorms[cur], (SkPoint::Side)-fSide);
+ SkASSERT(SkPointPriv::kLeft_Side == fSide || SkPointPriv::kRight_Side == fSide);
+ SkPointPriv::SetOrthog(&fBisectors[cur], fNorms[cur], (SkPointPriv::Side)-fSide);
SkVector other;
- other.setOrthog(fNorms[prev], fSide);
+ SkPointPriv::SetOrthog(&other, fNorms[prev], fSide);
fBisectors[cur] += other;
SkAssertResult(fBisectors[cur].normalize());
} else {
@@ -424,14 +424,14 @@ bool GrAAConvexTessellator::extractFromPath(const SkMatrix& m, const SkPath& pat
// Check the cross product of the final trio
SkScalar cross = SkPoint::CrossProduct(fNorms[0], fNorms.top());
if (cross > 0.0f) {
- fSide = SkPoint::kRight_Side;
+ fSide = SkPointPriv::kRight_Side;
} else {
- fSide = SkPoint::kLeft_Side;
+ fSide = SkPointPriv::kLeft_Side;
}
// Make all the normals face outwards rather than along the edge
for (int cur = 0; cur < fNorms.count(); ++cur) {
- fNorms[cur].setOrthog(fNorms[cur], fSide);
+ SkPointPriv::SetOrthog(&fNorms[cur], fNorms[cur], fSide);
SkASSERT(SkScalarNearlyEqual(1.0f, fNorms[cur].length()));
}
@@ -443,11 +443,11 @@ bool GrAAConvexTessellator::extractFromPath(const SkMatrix& m, const SkPath& pat
return false;
}
// For stroking, we still need to process the degenerate path, so fix it up
- fSide = SkPoint::kLeft_Side;
+ fSide = SkPointPriv::kLeft_Side;
// Make all the normals face outwards rather than along the edge
for (int cur = 0; cur < fNorms.count(); ++cur) {
- fNorms[cur].setOrthog(fNorms[cur], fSide);
+ SkPointPriv::SetOrthog(&fNorms[cur], fNorms[cur], fSide);
SkASSERT(SkScalarNearlyEqual(1.0f, fNorms[cur].length()));
}
@@ -839,7 +839,7 @@ void GrAAConvexTessellator::Ring::computeNormals(const GrAAConvexTessellator& te
fPts[cur].fNorm = tess.point(fPts[next].fIndex) - tess.point(fPts[cur].fIndex);
SkPoint::Normalize(&fPts[cur].fNorm);
- fPts[cur].fNorm.setOrthog(fPts[cur].fNorm, tess.side());
+ SkPointPriv::SetOrthog(&fPts[cur].fNorm, fPts[cur].fNorm, tess.side());
}
}
@@ -848,10 +848,12 @@ void GrAAConvexTessellator::Ring::computeBisectors(const GrAAConvexTessellator&
for (int cur = 0; cur < fPts.count(); prev = cur, ++cur) {
fPts[cur].fBisector = fPts[cur].fNorm + fPts[prev].fNorm;
if (!fPts[cur].fBisector.normalize()) {
- SkASSERT(SkPoint::kLeft_Side == tess.side() || SkPoint::kRight_Side == tess.side());
- fPts[cur].fBisector.setOrthog(fPts[cur].fNorm, (SkPoint::Side)-tess.side());
+ SkASSERT(SkPointPriv::kLeft_Side == tess.side() ||
+ SkPointPriv::kRight_Side == tess.side());
+ SkPointPriv::SetOrthog(&fPts[cur].fBisector, fPts[cur].fNorm,
+ (SkPointPriv::Side)-tess.side());
SkVector other;
- other.setOrthog(fPts[prev].fNorm, tess.side());
+ SkPointPriv::SetOrthog(&other, fPts[prev].fNorm, tess.side());
fPts[cur].fBisector += other;
SkAssertResult(fPts[cur].fBisector.normalize());
} else {
diff --git a/src/gpu/ops/GrAAConvexTessellator.h b/src/gpu/ops/GrAAConvexTessellator.h
index ee91128bfb..caf4905939 100644
--- a/src/gpu/ops/GrAAConvexTessellator.h
+++ b/src/gpu/ops/GrAAConvexTessellator.h
@@ -10,7 +10,7 @@
#include "SkColor.h"
#include "SkPaint.h"
-#include "SkPoint.h"
+#include "SkPointPriv.h"
#include "SkScalar.h"
#include "SkStrokeRec.h"
#include "SkTDArray.h"
@@ -36,14 +36,14 @@ public:
SkScalar strokeWidth = -1.0f,
SkPaint::Join join = SkPaint::Join::kBevel_Join,
SkScalar miterLimit = 0.0f)
- : fSide(SkPoint::kOn_Side)
+ : fSide(SkPointPriv::kOn_Side)
, fStrokeWidth(strokeWidth)
, fStyle(style)
, fJoin(join)
, fMiterLimit(miterLimit) {
}
- SkPoint::Side side() const { return fSide; }
+ SkPointPriv::Side side() const { return fSide; }
bool tessellate(const SkMatrix& m, const SkPath& path);
@@ -262,7 +262,7 @@ private:
// needed for exterior ring creation and then handed off to the initial ring.
SkTDArray<SkVector> fBisectors;
- SkPoint::Side fSide; // winding of the original polygon
+ SkPointPriv::Side fSide; // winding of the original polygon
// The triangulation of the points
SkTDArray<int> fIndices;
diff --git a/src/gpu/ops/GrAAHairLinePathRenderer.cpp b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
index 6dd5dc08c1..efab0d708d 100644
--- a/src/gpu/ops/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
@@ -19,6 +19,7 @@
#include "GrSimpleMeshDrawOpHelper.h"
#include "SkGeometry.h"
#include "SkPoint3.h"
+#include "SkPointPriv.h"
#include "SkStroke.h"
#include "SkTemplates.h"
#include "effects/GrBezierEffect.h"
@@ -176,17 +177,17 @@ static int is_degen_quad_or_conic(const SkPoint p[3], SkScalar* dsqd) {
static const SkScalar gDegenerateToLineTolSqd =
gDegenerateToLineTol * gDegenerateToLineTol;
- if (p[0].distanceToSqd(p[1]) < gDegenerateToLineTolSqd ||
- p[1].distanceToSqd(p[2]) < gDegenerateToLineTolSqd) {
+ if (SkPointPriv::DistanceToSqd(p[0], p[1]) < gDegenerateToLineTolSqd ||
+ SkPointPriv::DistanceToSqd(p[1], p[2]) < gDegenerateToLineTolSqd) {
return 1;
}
- *dsqd = p[1].distanceToLineBetweenSqd(p[0], p[2]);
+ *dsqd = SkPointPriv::DistanceToLineBetweenSqd(p[1], p[0], p[2]);
if (*dsqd < gDegenerateToLineTolSqd) {
return 1;
}
- if (p[2].distanceToLineBetweenSqd(p[1], p[0]) < gDegenerateToLineTolSqd) {
+ if (SkPointPriv::DistanceToLineBetweenSqd(p[2], p[1], p[0]) < gDegenerateToLineTolSqd) {
return 1;
}
return 0;
@@ -555,14 +556,14 @@ static void bloat_quad(const SkPoint qpts[3], const SkMatrix* toDevice,
ab.normalize();
SkVector abN;
- abN.setOrthog(ab, SkVector::kLeft_Side);
+ SkPointPriv::SetOrthog(&abN, ab, SkPointPriv::kLeft_Side);
if (abN.dot(ac) > 0) {
abN.negate();
}
cb.normalize();
SkVector cbN;
- cbN.setOrthog(cb, SkVector::kLeft_Side);
+ SkPointPriv::SetOrthog(&cbN, cb, SkPointPriv::kLeft_Side);
if (cbN.dot(ac) < 0) {
cbN.negate();
}
@@ -641,7 +642,7 @@ static void add_line(const SkPoint p[2],
SkVector ortho, vec = b;
vec -= a;
- SkScalar lengthSqd = vec.lengthSqd();
+ SkScalar lengthSqd = SkPointPriv::LengthSqd(vec);
if (vec.setLength(SK_ScalarHalf)) {
// Create a vector orthogonal to 'vec' and of unit length
diff --git a/src/gpu/ops/GrDashOp.cpp b/src/gpu/ops/GrDashOp.cpp
index 82b2012587..e87a335af0 100644
--- a/src/gpu/ops/GrDashOp.cpp
+++ b/src/gpu/ops/GrDashOp.cpp
@@ -17,6 +17,7 @@
#include "GrProcessor.h"
#include "GrStyle.h"
#include "SkGr.h"
+#include "SkPointPriv.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLGeometryProcessor.h"
#include "glsl/GrGLSLProgramDataManager.h"
@@ -92,7 +93,7 @@ static void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale,
vecSrc.scale(invSrc);
SkVector vecSrcPerp;
- vecSrc.rotateCW(&vecSrcPerp);
+ SkPointPriv::RotateCW(vecSrc, &vecSrcPerp);
viewMatrix.mapVectors(&vecSrc, 1);
viewMatrix.mapVectors(&vecSrcPerp, 1);
diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp
index b072702105..86e5732eb9 100644
--- a/src/gpu/text/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp
@@ -20,6 +20,7 @@
#include "SkGlyphCache.h"
#include "SkGr.h"
#include "SkPath.h"
+#include "SkPointPriv.h"
#include "SkTextBlobRunIterator.h"
#include "SkTextFormatParams.h"
#include "SkTextMapStateProc.h"
@@ -671,7 +672,7 @@ void GrStencilAndCoverTextContext::FallbackBlobBuilder::flush() {
// This will automatically merge with previous runs since we use the same font.
const SkTextBlobBuilder::RunBuffer& buff = fBuilder->allocRunPos(fFont, fBuffIdx);
memcpy(buff.glyphs, fGlyphIds, fBuffIdx * sizeof(uint16_t));
- memcpy(buff.pos, fPositions[0].asScalars(), fBuffIdx * 2 * sizeof(SkScalar));
+ memcpy(buff.pos, SkPointPriv::AsScalars(fPositions[0]), fBuffIdx * 2 * sizeof(SkScalar));
fBuffIdx = 0;
}
diff --git a/src/pathops/SkOpSegment.cpp b/src/pathops/SkOpSegment.cpp
index 402f6664de..451a155c58 100644
--- a/src/pathops/SkOpSegment.cpp
+++ b/src/pathops/SkOpSegment.cpp
@@ -8,6 +8,7 @@
#include "SkOpContour.h"
#include "SkOpSegment.h"
#include "SkPathWriter.h"
+#include "SkPointPriv.h"
/*
After computing raw intersections, post process all segments to:
@@ -1351,7 +1352,7 @@ bool SkOpSegment::spansNearby(const SkOpSpanBase* refSpan, const SkOpSpanBase* c
goto nextRef;
}
}
- SkScalar distSq = ref->fPt.distanceToSqd(check->fPt);
+ SkScalar distSq = SkPointPriv::DistanceToSqd(ref->fPt, check->fPt);
if (distSqBest > distSq && (refSeg != check->segment()
|| !refSeg->ptsDisjoint(*ref, *check))) {
distSqBest = distSq;
@@ -1448,8 +1449,9 @@ bool SkOpSegment::ptsDisjoint(double t1, const SkPoint& pt1, double t2, const Sk
// on the other hand, the below check is relatively inexpensive
double midT = (t1 + t2) / 2;
SkPoint midPt = this->ptAtT(midT);
- double seDistSq = SkTMax(pt1.distanceToSqd(pt2) * 2, FLT_EPSILON * 2);
- return midPt.distanceToSqd(pt1) > seDistSq || midPt.distanceToSqd(pt2) > seDistSq;
+ double seDistSq = SkTMax(SkPointPriv::DistanceToSqd(pt1, pt2) * 2, FLT_EPSILON * 2);
+ return SkPointPriv::DistanceToSqd(midPt, pt1) > seDistSq ||
+ SkPointPriv::DistanceToSqd(midPt, pt2) > seDistSq;
}
void SkOpSegment::setUpWindings(SkOpSpanBase* start, SkOpSpanBase* end, int* sumMiWinding,
diff --git a/src/utils/SkDashPath.cpp b/src/utils/SkDashPath.cpp
index 4b5e58ef4f..d3c52daee2 100644
--- a/src/utils/SkDashPath.cpp
+++ b/src/utils/SkDashPath.cpp
@@ -7,6 +7,7 @@
#include "SkDashPathPriv.h"
#include "SkPathMeasure.h"
+#include "SkPointPriv.h"
#include "SkStrokeRec.h"
static inline int is_even(int x) {
@@ -166,7 +167,7 @@ public:
fPathLength = pathLength;
fTangent.scale(SkScalarInvert(pathLength));
- fTangent.rotateCCW(&fNormal);
+ SkPointPriv::RotateCCW(fTangent, &fNormal);
fNormal.scale(SkScalarHalf(rec->getWidth()));
// now estimate how many quads will be added to the path
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();
}
diff --git a/src/utils/SkShadowTessellator.cpp b/src/utils/SkShadowTessellator.cpp
index aff59bf36d..1a714076e7 100755
--- a/src/utils/SkShadowTessellator.cpp
+++ b/src/utils/SkShadowTessellator.cpp
@@ -12,6 +12,7 @@
#include "SkInsetConvexPolygon.h"
#include "SkPath.h"
#include "SkPoint3.h"
+#include "SkPointPriv.h"
#include "SkVertices.h"
#if SK_SUPPORT_GPU
@@ -458,7 +459,7 @@ SkAmbientShadowTessellator::SkAmbientShadowTessellator(const SkPath& path,
// make sure we don't end up with a sharp alpha edge along the quad diagonal
if (fColors[fPrevUmbraIndex] != fColors[fFirstVertexIndex] &&
- fFirstPoint.distanceToSqd(fPositions[fPrevUmbraIndex]) > kMaxEdgeLenSqr) {
+ SkPointPriv::DistanceToSqd(fFirstPoint, fPositions[fPrevUmbraIndex]) > kMaxEdgeLenSqr) {
SkPoint centerPoint = fPositions[fPrevUmbraIndex] + fPositions[fFirstVertexIndex];
centerPoint *= 0.5f;
*fPositions.push() = centerPoint;
@@ -642,7 +643,7 @@ void SkAmbientShadowTessellator::addEdge(const SkPoint& nextPoint, const SkVecto
// Split the edge to make sure we don't end up with a sharp alpha edge along the quad diagonal
if (fColors[fPrevUmbraIndex] != fUmbraColor &&
- nextPoint.distanceToSqd(fPositions[fPrevUmbraIndex]) > kMaxEdgeLenSqr) {
+ SkPointPriv::DistanceToSqd(nextPoint, fPositions[fPrevUmbraIndex]) > kMaxEdgeLenSqr) {
// This is lacking 1/4 of the next inset -- we'll add it the next time we call addEdge()
SkPoint centerPoint = fPositions[fPrevUmbraIndex] + umbraPoint;
@@ -847,8 +848,8 @@ SkSpotShadowTessellator::SkSpotShadowTessellator(const SkPath& path, const SkMat
}
// check to see if umbra collapses
- SkScalar minDistSq = fCentroid.distanceToLineSegmentBetweenSqd(fPathPolygon[0],
- fPathPolygon[1]);
+ SkScalar minDistSq = SkPointPriv::DistanceToLineSegmentBetweenSqd(fCentroid, fPathPolygon[0],
+ fPathPolygon[1]);
SkRect bounds;
bounds.setBounds(&fPathPolygon[0], fPathPolygon.count());
for (int i = 1; i < fPathPolygon.count(); ++i) {
@@ -858,7 +859,8 @@ SkSpotShadowTessellator::SkSpotShadowTessellator(const SkPath& path, const SkMat
}
SkPoint currPoint = fPathPolygon[i];
SkPoint nextPoint = fPathPolygon[j];
- SkScalar distSq = fCentroid.distanceToLineSegmentBetweenSqd(currPoint, nextPoint);
+ SkScalar distSq = SkPointPriv::DistanceToLineSegmentBetweenSqd(fCentroid, currPoint,
+ nextPoint);
if (distSq < minDistSq) {
minDistSq = distSq;
}
@@ -1153,13 +1155,13 @@ bool SkSpotShadowTessellator::clipUmbraPoint(const SkPoint& umbraPoint, const Sk
}
int SkSpotShadowTessellator::getClosestUmbraPoint(const SkPoint& p) {
- SkScalar minDistance = p.distanceToSqd(fUmbraPolygon[fCurrUmbraPoint]);
+ SkScalar minDistance = SkPointPriv::DistanceToSqd(p, fUmbraPolygon[fCurrUmbraPoint]);
int index = fCurrUmbraPoint;
int dir = 1;
int next = (index + dir) % fUmbraPolygon.count();
// init travel direction
- SkScalar distance = p.distanceToSqd(fUmbraPolygon[next]);
+ SkScalar distance = SkPointPriv::DistanceToSqd(p, fUmbraPolygon[next]);
if (distance < minDistance) {
index = next;
minDistance = distance;
@@ -1169,12 +1171,12 @@ int SkSpotShadowTessellator::getClosestUmbraPoint(const SkPoint& p) {
// iterate until we find a point that increases the distance
next = (index + dir) % fUmbraPolygon.count();
- distance = p.distanceToSqd(fUmbraPolygon[next]);
+ distance = SkPointPriv::DistanceToSqd(p, fUmbraPolygon[next]);
while (distance < minDistance) {
index = next;
minDistance = distance;
next = (index + dir) % fUmbraPolygon.count();
- distance = p.distanceToSqd(fUmbraPolygon[next]);
+ distance = SkPointPriv::DistanceToSqd(p, fUmbraPolygon[next]);
}
fCurrUmbraPoint = index;
@@ -1194,7 +1196,7 @@ static bool duplicate_pt(const SkPoint& p0, const SkPoint& p1) {
static constexpr SkScalar kClose = (SK_Scalar1 / 16);
static constexpr SkScalar kCloseSqd = kClose*kClose;
- SkScalar distSq = p0.distanceToSqd(p1);
+ SkScalar distSq = SkPointPriv::DistanceToSqd(p0, p1);
return distSq < kCloseSqd;
}
diff --git a/tests/GeometryTest.cpp b/tests/GeometryTest.cpp
index ad3a6b4baf..a9265016ac 100644
--- a/tests/GeometryTest.cpp
+++ b/tests/GeometryTest.cpp
@@ -6,8 +6,9 @@
*/
#include "SkGeometry.h"
-#include "Test.h"
+#include "SkPointPriv.h"
#include "SkRandom.h"
+#include "Test.h"
#include <array>
static bool nearly_equal(const SkPoint& a, const SkPoint& b) {
@@ -152,7 +153,7 @@ static void test_this_conic_to_quad(skiatest::Reporter* r, const SkPoint pts[3],
const int qcount = quadder.countQuads();
const int pcount = qcount * 2 + 1;
- REPORTER_ASSERT(r, SkPointsAreFinite(qpts, pcount));
+ REPORTER_ASSERT(r, SkPointPriv::AreFinite(qpts, pcount));
}
/**
diff --git a/tests/PathCoverageTest.cpp b/tests/PathCoverageTest.cpp
index 255156394a..ed5ed0eaeb 100644
--- a/tests/PathCoverageTest.cpp
+++ b/tests/PathCoverageTest.cpp
@@ -6,7 +6,7 @@
*/
#include "SkMathPriv.h"
-#include "SkPoint.h"
+#include "SkPointPriv.h"
#include "SkScalar.h"
#include "Test.h"
@@ -42,7 +42,7 @@ static inline int estimate_distance(const SkPoint points[]) {
}
static inline SkScalar compute_distance(const SkPoint points[]) {
- return points[1].distanceToLineSegmentBetween(points[0], points[2]);
+ return SkPointPriv::DistanceToLineSegmentBetween(points[1], points[0], points[2]);
}
static inline uint32_t estimate_pointCount(int distance) {
diff --git a/tests/PointTest.cpp b/tests/PointTest.cpp
index c0d1f26086..76ac3a1a79 100644
--- a/tests/PointTest.cpp
+++ b/tests/PointTest.cpp
@@ -6,7 +6,7 @@
*/
// Unit tests for src/core/SkPoint.cpp and its header
-#include "SkPoint.h"
+#include "SkPointPriv.h"
#include "SkRect.h"
#include "Test.h"
@@ -17,7 +17,7 @@ static void test_casts(skiatest::Reporter* reporter) {
const SkScalar* pPtr = SkTCast<const SkScalar*>(&p);
const SkScalar* rPtr = SkTCast<const SkScalar*>(&r);
- REPORTER_ASSERT(reporter, p.asScalars() == pPtr);
+ REPORTER_ASSERT(reporter, SkPointPriv::AsScalars(p) == pPtr);
REPORTER_ASSERT(reporter, r.asScalars() == rPtr);
}
@@ -146,7 +146,7 @@ DEF_TEST(Point_setLengthFast, reporter) {
SkPoint slow = kOne, fast = kOne;
slow.setLength(tests[i]);
- fast.setLengthFast(tests[i]);
+ SkPointPriv::SetLengthFast(&fast, tests[i]);
if (slow.length() < FLT_MIN && fast.length() < FLT_MIN) continue;
diff --git a/tests/RoundRectTest.cpp b/tests/RoundRectTest.cpp
index d9b7a9aa08..2e31cf1b65 100644
--- a/tests/RoundRectTest.cpp
+++ b/tests/RoundRectTest.cpp
@@ -6,6 +6,7 @@
*/
#include "SkMatrix.h"
+#include "SkPointPriv.h"
#include "SkRRect.h"
#include "Test.h"
@@ -197,7 +198,8 @@ static void test_round_rect_basic(skiatest::Reporter* reporter) {
for (int i = 0; i < 4; ++i) {
REPORTER_ASSERT(reporter,
- rr2.radii((SkRRect::Corner) i).equalsWithinTolerance(halfPoint));
+ SkPointPriv::EqualsWithinTolerance(rr2.radii((SkRRect::Corner) i),
+ halfPoint));
}
SkRRect rr2_2; // construct the same RR using the most general set function
SkVector rr2_2_radii[4] = { { halfPoint.fX, halfPoint.fY }, { halfPoint.fX, halfPoint.fY },
diff --git a/tests/StrokerTest.cpp b/tests/StrokerTest.cpp
index aa6435f2a1..1ccb51814c 100644
--- a/tests/StrokerTest.cpp
+++ b/tests/StrokerTest.cpp
@@ -11,6 +11,7 @@
#include "SkPathOpsCubic.h"
#include "SkPaint.h"
#include "SkPath.h"
+#include "SkPointPriv.h"
#include "SkRandom.h"
#include "SkStrokerPriv.h"
#include "SkTime.h"
@@ -239,12 +240,12 @@ DEF_TEST(QuadStrokerConstrained, reporter) {
do {
quad[1].fX = r.nextRangeF(0, 500);
quad[1].fY = r.nextRangeF(0, 500);
- } while (quad[0].distanceToSqd(quad[1]) < halfSquared);
+ } while (SkPointPriv::DistanceToSqd(quad[0], quad[1]) < halfSquared);
do {
quad[2].fX = r.nextRangeF(0, 500);
quad[2].fY = r.nextRangeF(0, 500);
- } while (quad[0].distanceToSqd(quad[2]) < halfSquared
- || quad[1].distanceToSqd(quad[2]) < halfSquared);
+ } while (SkPointPriv::DistanceToSqd(quad[0], quad[2]) < halfSquared
+ || SkPointPriv::DistanceToSqd(quad[1], quad[2]) < halfSquared);
path.moveTo(quad[0].fX, quad[0].fY);
path.quadTo(quad[1].fX, quad[1].fY, quad[2].fX, quad[2].fY);
p.setStrokeWidth(r.nextRangeF(0, 500));
@@ -291,18 +292,18 @@ DEF_TEST(CubicStrokerConstrained, reporter) {
do {
cubic[1].fX = r.nextRangeF(0, 500);
cubic[1].fY = r.nextRangeF(0, 500);
- } while (cubic[0].distanceToSqd(cubic[1]) < halfSquared);
+ } while (SkPointPriv::DistanceToSqd(cubic[0], cubic[1]) < halfSquared);
do {
cubic[2].fX = r.nextRangeF(0, 500);
cubic[2].fY = r.nextRangeF(0, 500);
- } while ( cubic[0].distanceToSqd(cubic[2]) < halfSquared
- || cubic[1].distanceToSqd(cubic[2]) < halfSquared);
+ } while ( SkPointPriv::DistanceToSqd(cubic[0], cubic[2]) < halfSquared
+ || SkPointPriv::DistanceToSqd(cubic[1], cubic[2]) < halfSquared);
do {
cubic[3].fX = r.nextRangeF(0, 500);
cubic[3].fY = r.nextRangeF(0, 500);
- } while ( cubic[0].distanceToSqd(cubic[3]) < halfSquared
- || cubic[1].distanceToSqd(cubic[3]) < halfSquared
- || cubic[2].distanceToSqd(cubic[3]) < halfSquared);
+ } while ( SkPointPriv::DistanceToSqd(cubic[0], cubic[3]) < halfSquared
+ || SkPointPriv::DistanceToSqd(cubic[1], cubic[3]) < halfSquared
+ || SkPointPriv::DistanceToSqd(cubic[2], cubic[3]) < halfSquared);
path.moveTo(cubic[0].fX, cubic[0].fY);
path.cubicTo(cubic[1].fX, cubic[1].fY, cubic[2].fX, cubic[2].fY, cubic[3].fX, cubic[3].fY);
p.setStrokeWidth(r.nextRangeF(0, 500));