aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2014-10-21 12:33:21 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-21 12:33:21 -0700
commit39393e3ac309d4bedbc18bae98d3ebcb762501dd (patch)
treee8c984efb79c6e08474c0f52e8260597664a59b4
parentc7f7f467df07be73b22dbee38a59762997eb19bc (diff)
add round/ceil/etc. for SkMScalar
BUG=skia: TBR= Review URL: https://codereview.chromium.org/645793006
-rw-r--r--include/core/SkFloatingPoint.h7
-rw-r--r--include/utils/SkMatrix44.h25
-rw-r--r--tests/Matrix44Test.cpp16
3 files changed, 46 insertions, 2 deletions
diff --git a/include/core/SkFloatingPoint.h b/include/core/SkFloatingPoint.h
index f85c456aa8..1003b80b4f 100644
--- a/include/core/SkFloatingPoint.h
+++ b/include/core/SkFloatingPoint.h
@@ -116,6 +116,13 @@ static inline float sk_float_copysign(float x, float y) {
#define sk_float_ceil2int(x) (int)sk_float_ceil(x)
#endif
+#define sk_double_floor(x) floor(x)
+#define sk_double_round(x) floor((x) + 0.5)
+#define sk_double_ceil(x) ceil(x)
+#define sk_double_floor2int(x) (int)floor(x)
+#define sk_double_round2int(x) (int)floor((x) + 0.5f)
+#define sk_double_ceil2int(x) (int)ceil(x)
+
extern const uint32_t gIEEENotANumber;
extern const uint32_t gIEEEInfinity;
extern const uint32_t gIEEENegativeInfinity;
diff --git a/include/utils/SkMatrix44.h b/include/utils/SkMatrix44.h
index 38a011467f..553e8d7c4f 100644
--- a/include/utils/SkMatrix44.h
+++ b/include/utils/SkMatrix44.h
@@ -33,6 +33,16 @@
return fabs(x);
}
static const SkMScalar SK_MScalarPI = 3.141592653589793;
+
+ #define SkMScalarFloor(x) sk_double_floor(x)
+ #define SkMScalarCeil(x) sk_double_ceil(x)
+ #define SkMScalarRound(x) sk_double_round(x)
+
+ #define SkMScalarFloorToInt(x) sk_double_floor2int(x)
+ #define SkMScalarCeilToInt(x) sk_double_ceil2int(x)
+ #define SkMScalarRoundToInt(x) sk_double_round2int(x)
+
+
#elif defined SK_MSCALAR_IS_FLOAT
#ifdef SK_MSCALAR_IS_DOUBLE
#error "can't define MSCALAR both as DOUBLE and FLOAT"
@@ -55,10 +65,21 @@
return sk_float_abs(x);
}
static const SkMScalar SK_MScalarPI = 3.14159265f;
+
+ #define SkMScalarFloor(x) sk_float_floor(x)
+ #define SkMScalarCeil(x) sk_float_ceil(x)
+ #define SkMScalarRound(x) sk_float_round(x)
+
+ #define SkMScalarFloorToInt(x) sk_float_floor2int(x)
+ #define SkMScalarCeilToInt(x) sk_float_ceil2int(x)
+ #define SkMScalarRoundToInt(x) sk_float_round2int(x)
+
#endif
-#define SkMScalarToScalar SkMScalarToFloat
-#define SkScalarToMScalar SkFloatToMScalar
+#define SkIntToMScalar(n) static_cast<SkMScalar>(n)
+
+#define SkMScalarToScalar(x) SkMScalarToFloat(x)
+#define SkScalarToMScalar(x) SkFloatToMScalar(x)
static const SkMScalar SK_MScalar1 = 1;
diff --git a/tests/Matrix44Test.cpp b/tests/Matrix44Test.cpp
index 75dd5181d4..13ead192b3 100644
--- a/tests/Matrix44Test.cpp
+++ b/tests/Matrix44Test.cpp
@@ -761,6 +761,21 @@ static void test_preserves_2d_axis_alignment(skiatest::Reporter* reporter) {
test(true, reporter, transform);
}
+// just want to exercise the various converters for MScalar
+static void test_toint(skiatest::Reporter* reporter) {
+ SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor);
+ mat.setScale(3, 3, 3);
+
+ SkMScalar sum = SkMScalarFloor(mat.get(0, 0)) +
+ SkMScalarRound(mat.get(1, 0)) +
+ SkMScalarCeil(mat.get(2, 0));
+ int isum = SkMScalarFloorToInt(mat.get(0, 1)) +
+ SkMScalarRoundToInt(mat.get(1, 2)) +
+ SkMScalarCeilToInt(mat.get(2, 3));
+ REPORTER_ASSERT(reporter, sum >= 0);
+ REPORTER_ASSERT(reporter, isum >= 0);
+ REPORTER_ASSERT(reporter, static_cast<SkMScalar>(isum) == SkIntToMScalar(isum));
+}
DEF_TEST(Matrix44, reporter) {
SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor);
@@ -869,4 +884,5 @@ DEF_TEST(Matrix44, reporter) {
test_3x3_conversion(reporter);
test_has_perspective(reporter);
test_preserves_2d_axis_alignment(reporter);
+ test_toint(reporter);
}