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

Unified Diff: tests/ScalarTest.cpp

Issue 267003002: add rounding-using-doubles methods on SkScalar and SkRect (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix spelling in comment Created 6 years, 7 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 | « tests/PathTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ScalarTest.cpp
diff --git a/tests/ScalarTest.cpp b/tests/ScalarTest.cpp
index 82f61ec5c54917c8b1cb9002f4dc72a1b25f6674..6b7fe6bfa02e259ed34529776fc71b0938086a10 100644
--- a/tests/ScalarTest.cpp
+++ b/tests/ScalarTest.cpp
@@ -12,6 +12,19 @@
#include "SkRect.h"
#include "Test.h"
+static void test_roundtoint(skiatest::Reporter* reporter) {
+ SkScalar x = 0.49999997;
+ int ix = SkScalarRoundToInt(x);
+ // We "should" get 0, since x < 0.5, but we don't due to float addition rounding up the low
+ // bit after adding 0.5.
+ REPORTER_ASSERT(reporter, 1 == ix);
+
+ // This version explicitly performs the +0.5 step using double, which should avoid losing the
+ // low bits.
+ ix = SkDScalarRoundToInt(x);
+ REPORTER_ASSERT(reporter, 0 == ix);
+}
+
struct PointSet {
const SkPoint* fPts;
size_t fCount;
@@ -187,4 +200,5 @@ static void test_isfinite(skiatest::Reporter* reporter) {
DEF_TEST(Scalar, reporter) {
test_isfinite(reporter);
+ test_roundtoint(reporter);
}
« no previous file with comments | « tests/PathTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698