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

Unified Diff: src/pathops/SkPathOpsTypes.cpp

Issue 1522183002: only call scalar finite when necessary (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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
Index: src/pathops/SkPathOpsTypes.cpp
diff --git a/src/pathops/SkPathOpsTypes.cpp b/src/pathops/SkPathOpsTypes.cpp
index ca84405aa780f15b8db4ec24313b139ae524635d..1ed484afee4f42fb1ed3f61f078214f8d9bbc829 100644
--- a/src/pathops/SkPathOpsTypes.cpp
+++ b/src/pathops/SkPathOpsTypes.cpp
@@ -16,6 +16,16 @@ static bool arguments_denormalized(float a, float b, int epsilon) {
// from http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
// FIXME: move to SkFloatBits.h
static bool equal_ulps(float a, float b, int epsilon, int depsilon) {
+ if (arguments_denormalized(a, b, depsilon)) {
+ return true;
+ }
+ int aBits = SkFloatAs2sCompliment(a);
+ int bBits = SkFloatAs2sCompliment(b);
+ // Find the difference in ULPs.
+ return aBits < bBits + epsilon && bBits < aBits + epsilon;
+}
+
+static bool equal_ulps_pin(float a, float b, int epsilon, int depsilon) {
reed1 2015/12/15 14:17:21 Just an idea, may not be any clearer... To avoid
if (!SkScalarIsFinite(a) || !SkScalarIsFinite(b)) {
return false;
}
@@ -29,9 +39,6 @@ static bool equal_ulps(float a, float b, int epsilon, int depsilon) {
}
static bool d_equal_ulps(float a, float b, int epsilon) {
- if (!SkScalarIsFinite(a) || !SkScalarIsFinite(b)) {
- return false;
- }
int aBits = SkFloatAs2sCompliment(a);
int bBits = SkFloatAs2sCompliment(b);
// Find the difference in ULPs.
@@ -39,6 +46,16 @@ static bool d_equal_ulps(float a, float b, int epsilon) {
}
static bool not_equal_ulps(float a, float b, int epsilon) {
+ if (arguments_denormalized(a, b, epsilon)) {
+ return false;
+ }
+ int aBits = SkFloatAs2sCompliment(a);
+ int bBits = SkFloatAs2sCompliment(b);
+ // Find the difference in ULPs.
+ return aBits >= bBits + epsilon || bBits >= aBits + epsilon;
+}
+
+static bool not_equal_ulps_pin(float a, float b, int epsilon) {
if (!SkScalarIsFinite(a) || !SkScalarIsFinite(b)) {
return false;
}
@@ -52,9 +69,6 @@ static bool not_equal_ulps(float a, float b, int epsilon) {
}
static bool d_not_equal_ulps(float a, float b, int epsilon) {
- if (!SkScalarIsFinite(a) || !SkScalarIsFinite(b)) {
- return false;
- }
int aBits = SkFloatAs2sCompliment(a);
int bBits = SkFloatAs2sCompliment(b);
// Find the difference in ULPs.
@@ -62,9 +76,6 @@ static bool d_not_equal_ulps(float a, float b, int epsilon) {
}
static bool less_ulps(float a, float b, int epsilon) {
- if (!SkScalarIsFinite(a) || !SkScalarIsFinite(b)) {
- return false;
- }
if (arguments_denormalized(a, b, epsilon)) {
return a <= b - FLT_EPSILON * epsilon;
}
@@ -75,9 +86,6 @@ static bool less_ulps(float a, float b, int epsilon) {
}
static bool less_or_equal_ulps(float a, float b, int epsilon) {
- if (!SkScalarIsFinite(a) || !SkScalarIsFinite(b)) {
- return false;
- }
if (arguments_denormalized(a, b, epsilon)) {
return a < b + FLT_EPSILON * epsilon;
}
@@ -104,10 +112,7 @@ bool AlmostDequalUlps(float a, float b) {
}
bool AlmostDequalUlps(double a, double b) {
- if (SkScalarIsFinite(a) || SkScalarIsFinite(b)) {
- return AlmostDequalUlps(SkDoubleToScalar(a), SkDoubleToScalar(b));
- }
- return fabs(a - b) / SkTMax(fabs(a), fabs(b)) < FLT_EPSILON * 16;
+ return AlmostDequalUlps(SkDoubleToScalar(a), SkDoubleToScalar(b));
}
bool AlmostEqualUlps(float a, float b) {
@@ -115,11 +120,21 @@ bool AlmostEqualUlps(float a, float b) {
return equal_ulps(a, b, UlpsEpsilon, UlpsEpsilon);
}
+bool AlmostEqualUlps_Pin(float a, float b) {
+ const int UlpsEpsilon = 16;
+ return equal_ulps_pin(a, b, UlpsEpsilon, UlpsEpsilon);
+}
+
bool NotAlmostEqualUlps(float a, float b) {
const int UlpsEpsilon = 16;
return not_equal_ulps(a, b, UlpsEpsilon);
}
+bool NotAlmostEqualUlps_Pin(float a, float b) {
+ const int UlpsEpsilon = 16;
+ return not_equal_ulps_pin(a, b, UlpsEpsilon);
+}
+
bool NotAlmostDequalUlps(float a, float b) {
const int UlpsEpsilon = 16;
return d_not_equal_ulps(a, b, UlpsEpsilon);
@@ -148,9 +163,6 @@ bool AlmostLessOrEqualUlps(float a, float b) {
}
int UlpsDistance(float a, float b) {
- if (!SkScalarIsFinite(a) || !SkScalarIsFinite(b)) {
- return SK_MaxS32;
- }
SkFloatIntUnion floatIntA, floatIntB;
floatIntA.fFloat = a;
floatIntB.fFloat = b;

Powered by Google App Engine
This is Rietveld 408576698