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

Unified Diff: include/core/SkScalar.h

Issue 1783583003: Add SkScalarTruncToScalar and speed up SkScalarFraction. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months 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 | include/private/SkFloatingPoint.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkScalar.h
diff --git a/include/core/SkScalar.h b/include/core/SkScalar.h
index 84b53c85751630a60c35e28b72b0a684c03d7f62..c154609fcb03f9f15ce396e3968d23171a5a87ff 100644
--- a/include/core/SkScalar.h
+++ b/include/core/SkScalar.h
@@ -38,6 +38,7 @@ typedef float SkScalar;
#define SkScalarFloorToScalar(x) sk_float_floor(x)
#define SkScalarCeilToScalar(x) sk_float_ceil(x)
#define SkScalarRoundToScalar(x) sk_float_floor((x) + 0.5f)
+#define SkScalarTruncToScalar(x) sk_float_trunc(x)
#define SkScalarFloorToInt(x) sk_float_floor2int(x)
#define SkScalarCeilToInt(x) sk_float_ceil2int(x)
@@ -46,7 +47,6 @@ typedef float SkScalar;
#define SkScalarAbs(x) sk_float_abs(x)
#define SkScalarCopySign(x, y) sk_float_copysign(x, y)
#define SkScalarMod(x, y) sk_float_mod(x,y)
-#define SkScalarFraction(x) sk_float_mod(x, 1.0f)
#define SkScalarSqrt(x) sk_float_sqrt(x)
#define SkScalarPow(b, e) sk_float_pow(b, e)
@@ -81,6 +81,7 @@ typedef double SkScalar;
#define SkScalarFloorToScalar(x) floor(x)
#define SkScalarCeilToScalar(x) ceil(x)
#define SkScalarRoundToScalar(x) floor((x) + 0.5)
+#define SkScalarTruncToScalar(x) trunc(x)
#define SkScalarFloorToInt(x) (int)floor(x)
#define SkScalarCeilToInt(x) (int)ceil(x)
@@ -89,7 +90,6 @@ typedef double SkScalar;
#define SkScalarAbs(x) abs(x)
#define SkScalarCopySign(x, y) copysign(x, y)
#define SkScalarMod(x, y) fmod(x,y)
-#define SkScalarFraction(x) fmod(x, 1.0)
#define SkScalarSqrt(x) sqrt(x)
#define SkScalarPow(b, e) pow(b, e)
@@ -168,6 +168,11 @@ static inline int SkDScalarRoundToInt(SkScalar x) {
return (int)floor(xx);
}
+/** Returns the fractional part of the scalar. */
+static inline SkScalar SkScalarFraction(SkScalar x) {
+ return x - SkScalarTruncToScalar(x);
+}
+
static inline SkScalar SkScalarClampMax(SkScalar x, SkScalar max) {
x = SkTMin(x, max);
x = SkTMax<SkScalar>(x, 0);
« no previous file with comments | « no previous file | include/private/SkFloatingPoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698