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

Unified Diff: src/core/SkPath.cpp

Issue 784593002: add convexity logic and tests for scalar max, Inf, and NaN (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/PathTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPath.cpp
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 25fd058d20468feec4cf99d514cbad6fe4dcc4e8..a08abbd14b6bda1e1d8716b6f78652b465d44e98 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -2215,7 +2215,8 @@ struct Convexicator {
Convexicator()
: fPtCount(0)
, fConvexity(SkPath::kConvex_Convexity)
- , fDirection(SkPath::kUnknown_Direction) {
+ , fDirection(SkPath::kUnknown_Direction)
+ , fIsFinite(true) {
fExpectedDir = kInvalid_DirChange;
// warnings
fLastPt.set(0, 0);
@@ -2233,7 +2234,7 @@ struct Convexicator {
SkPath::Direction getDirection() const { return fDirection; }
void addPt(const SkPoint& pt) {
- if (SkPath::kConcave_Convexity == fConvexity) {
+ if (SkPath::kConcave_Convexity == fConvexity || !fIsFinite) {
return;
}
@@ -2242,7 +2243,10 @@ struct Convexicator {
++fPtCount;
} else {
SkVector vec = pt - fCurrPt;
- if (!SkScalarNearlyZero(vec.lengthSqd(), SK_ScalarNearlyZero*SK_ScalarNearlyZero)) {
+ SkScalar lengthSqd = vec.lengthSqd();
+ if (!SkScalarIsFinite(lengthSqd)) {
+ fIsFinite = false;
bsalomon 2014/12/05 20:23:46 Do we need to track fIsFinite or can this just be
+ } else if (!SkScalarNearlyZero(lengthSqd, SK_ScalarNearlyZero*SK_ScalarNearlyZero)) {
fLastPt = fCurrPt;
fCurrPt = pt;
if (++fPtCount == 2) {
@@ -2272,6 +2276,10 @@ struct Convexicator {
}
}
+ bool isFinite() const {
+ return fIsFinite;
+ }
+
private:
void addVec(const SkVector& vec) {
SkASSERT(vec.fX || vec.fY);
@@ -2310,6 +2318,7 @@ private:
SkPath::Convexity fConvexity;
SkPath::Direction fDirection;
int fDx, fDy, fSx, fSy;
+ bool fIsFinite;
};
SkPath::Convexity SkPath::internalGetConvexity() const {
@@ -2322,6 +2331,9 @@ SkPath::Convexity SkPath::internalGetConvexity() const {
int count;
Convexicator state;
+ if (!isFinite()) {
+ return kUnknown_Convexity;
+ }
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
switch (verb) {
case kMove_Verb:
@@ -2350,6 +2362,9 @@ SkPath::Convexity SkPath::internalGetConvexity() const {
state.addPt(pts[i]);
}
// early exit
+ if (!state.isFinite()) {
+ return kUnknown_Convexity;
+ }
if (kConcave_Convexity == state.getConvexity()) {
fConvexity = kConcave_Convexity;
return kConcave_Convexity;
« no previous file with comments | « no previous file | tests/PathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698