diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-09 02:24:26 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-09 02:24:26 +0000 |
commit | d41344553163085bfcfaf7d5882c6028934f8e3b (patch) | |
tree | 5dd30ae71a99eeb6bf4ffd812ae36313d5c5a160 /tests | |
parent | 337490d4ae0138e93eff01ded76b1140d105a023 (diff) |
update to work correctly for scalar == fixed or float
git-svn-id: http://skia.googlecode.com/svn/trunk@780 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/BlitRowTest.cpp | 3 | ||||
-rw-r--r-- | tests/ClipCubicTest.cpp | 18 | ||||
-rw-r--r-- | tests/InfRectTest.cpp | 52 | ||||
-rw-r--r-- | tests/MathTest.cpp | 26 | ||||
-rw-r--r-- | tests/MatrixTest.cpp | 4 | ||||
-rw-r--r-- | tests/PaintTest.cpp | 12 |
6 files changed, 59 insertions, 56 deletions
diff --git a/tests/BlitRowTest.cpp b/tests/BlitRowTest.cpp index 91d6b94e75..d18cb8a7fa 100644 --- a/tests/BlitRowTest.cpp +++ b/tests/BlitRowTest.cpp @@ -207,7 +207,8 @@ static void test_diagonal(skiatest::Reporter* reporter) { SkBitmap srcBM; srcBM.setConfig(SkBitmap::kARGB_8888_Config, W, H); srcBM.allocPixels(); - SkRect srcR = { 0, 0, srcBM.width(), srcBM.height() }; + SkRect srcR = { + 0, 0, SkIntToScalar(srcBM.width()), SkIntToScalar(srcBM.height()) }; // cons up a mesh to draw the bitmap with Mesh mesh(srcBM, &paint); diff --git a/tests/ClipCubicTest.cpp b/tests/ClipCubicTest.cpp index 905b733667..e38a22fcc5 100644 --- a/tests/ClipCubicTest.cpp +++ b/tests/ClipCubicTest.cpp @@ -7,10 +7,10 @@ static void PrintCurve(const char *name, const SkPoint crv[4]) { printf("%s: %.10g, %.10g, %.10g, %.10g, %.10g, %.10g, %.10g, %.10g\n", name, - crv[0].fX, crv[0].fY, - crv[1].fX, crv[1].fY, - crv[2].fX, crv[2].fY, - crv[3].fX, crv[3].fY); + (float)crv[0].fX, (float)crv[0].fY, + (float)crv[1].fX, (float)crv[1].fY, + (float)crv[2].fX, (float)crv[2].fY, + (float)crv[3].fX, (float)crv[3].fY); } @@ -46,17 +46,17 @@ static SkPoint* SetCurve(float x0, float y0, static void TestCubicClipping(skiatest::Reporter* reporter) { static SkPoint crv[4] = { - { SkFloatToScalar(0), SkFloatToScalar(0) }, - { SkFloatToScalar(2), SkFloatToScalar(3) }, - { SkFloatToScalar(1), SkFloatToScalar(10) }, - { SkFloatToScalar(4), SkFloatToScalar(12) } + { SkIntToScalar(0), SkIntToScalar(0) }, + { SkIntToScalar(2), SkIntToScalar(3) }, + { SkIntToScalar(1), SkIntToScalar(10) }, + { SkIntToScalar(4), SkIntToScalar(12) } }; SkCubicClipper clipper; SkPoint clipped[4], shouldbe[4]; SkIRect clipRect; bool success; - const float tol = 1e-4; + const float tol = SkFloatToScalar(1e-4); // Test no clip, with plenty of room. clipRect.set(-2, -2, 6, 14); diff --git a/tests/InfRectTest.cpp b/tests/InfRectTest.cpp index bcdbf4a53c..1e1502352a 100644 --- a/tests/InfRectTest.cpp +++ b/tests/InfRectTest.cpp @@ -1,41 +1,41 @@ #include "Test.h" #include "SkRect.h" +#ifdef SK_SCALAR_IS_FLOAT static float make_zero() { return sk_float_sin(0); } +#endif + +static void check_invalid(skiatest::Reporter* reporter, + SkScalar l, SkScalar t, SkScalar r, SkScalar b) { + SkRect rect; + rect.set(l, t, r, b); + REPORTER_ASSERT(reporter, !rect.hasValidCoordinates()); +} // Tests that hasValidCoordinates() will reject any rect with +/-inf values // as one of its coordinates. static void TestInfRect(skiatest::Reporter* reporter) { - float zero = make_zero(); - - SkRect rect = SkRect::MakeXYWH(10.0f, 10.0f, 100.0f, 100.0f); +#ifdef SK_SCALAR_IS_FLOAT + float invalid = 1 / make_zero(); // infinity +#else + SkFixed invalid = SK_FixedNaN; +#endif + SkScalar small = SkIntToScalar(10); + SkScalar big = SkIntToScalar(100); + + SkRect rect = SkRect::MakeXYWH(small, small, big, big); REPORTER_ASSERT(reporter, rect.hasValidCoordinates()); - rect = SkRect::MakeXYWH(10.0f, 10.0f, 100.0f, 1.0f/zero); // Make 'inf' value without numeric_limits. - REPORTER_ASSERT(reporter, !rect.hasValidCoordinates()); - - rect = SkRect::MakeXYWH(10.0f, 10.0f, 1.0f/zero, 100.0f); - REPORTER_ASSERT(reporter, !rect.hasValidCoordinates()); - - rect = SkRect::MakeXYWH(1.0f/zero, 10.0f, 100.0f, 100.0f); - REPORTER_ASSERT(reporter, !rect.hasValidCoordinates()); - - rect = SkRect::MakeXYWH(10.0f, 1.0f/zero, 100.0f, 100.0f); - REPORTER_ASSERT(reporter, !rect.hasValidCoordinates()); - - rect = SkRect::MakeXYWH(10.0f, 10.0f, 100.0f, -1.0f/zero); - REPORTER_ASSERT(reporter, !rect.hasValidCoordinates()); - - rect = SkRect::MakeXYWH(10.0f, 10.0f, -1.0f/zero, 100.0f); - REPORTER_ASSERT(reporter, !rect.hasValidCoordinates()); - - rect = SkRect::MakeXYWH(-1.0f/zero, 10.0f, 100.0f, 100.0f); - REPORTER_ASSERT(reporter, !rect.hasValidCoordinates()); - - rect = SkRect::MakeXYWH(10.0f, -1.0f/zero, 100.0f, 100.0f); - REPORTER_ASSERT(reporter, !rect.hasValidCoordinates()); + check_invalid(reporter, small, small, big, invalid); + check_invalid(reporter, small, small, invalid, big); + check_invalid(reporter, small, invalid, big, big); + check_invalid(reporter, invalid, small, big, big); + check_invalid(reporter, small, small, big, -invalid); + check_invalid(reporter, small, small, -invalid, big); + check_invalid(reporter, small, -invalid, big, big); + check_invalid(reporter, -invalid, small, big, big); } // need tests for SkStrSearch diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp index 9aed9f9aa0..493691e6f7 100644 --- a/tests/MathTest.cpp +++ b/tests/MathTest.cpp @@ -146,9 +146,11 @@ static void unittest_fastfloat(skiatest::Reporter* reporter) { } } +#ifdef SK_SCALAR_IS_FLOAT static float make_zero() { return sk_float_sin(0); } +#endif static void unittest_isfinite(skiatest::Reporter* reporter) { #ifdef SK_SCALAR_IS_FLOAT @@ -156,28 +158,24 @@ static void unittest_isfinite(skiatest::Reporter* reporter) { float inf = 1.0 / make_zero(); float big = 3.40282e+038; - REPORTER_ASSERT(reporter, SkScalarIsNaN(nan)); REPORTER_ASSERT(reporter, !SkScalarIsNaN(inf)); + REPORTER_ASSERT(reporter, !SkScalarIsNaN(-inf)); + REPORTER_ASSERT(reporter, !SkScalarIsFinite(inf)); + REPORTER_ASSERT(reporter, !SkScalarIsFinite(-inf)); +#else + SkFixed nan = SK_FixedNaN; + SkFixed big = SK_FixedMax; +#endif + + REPORTER_ASSERT(reporter, SkScalarIsNaN(nan)); REPORTER_ASSERT(reporter, !SkScalarIsNaN(big)); REPORTER_ASSERT(reporter, !SkScalarIsNaN(-big)); REPORTER_ASSERT(reporter, !SkScalarIsNaN(0)); - + REPORTER_ASSERT(reporter, !SkScalarIsFinite(nan)); - REPORTER_ASSERT(reporter, !SkScalarIsFinite(inf)); REPORTER_ASSERT(reporter, SkScalarIsFinite(big)); REPORTER_ASSERT(reporter, SkScalarIsFinite(-big)); REPORTER_ASSERT(reporter, SkScalarIsFinite(0)); -#else - REPORTER_ASSERT(reporter, SkScalarIsNaN(0x80000000)); - REPORTER_ASSERT(reporter, !SkScalarIsNaN(0x7FFFFFFF)); - REPORTER_ASSERT(reporter, !SkScalarIsNaN(0x80000001)); - REPORTER_ASSERT(reporter, !SkScalarIsNaN(0)); - - REPORTER_ASSERT(reporter, !SkScalarIsFinite(0x80000000)); - REPORTER_ASSERT(reporter, SkScalarIsFinite(0x7FFFFFFF)); - REPORTER_ASSERT(reporter, SkScalarIsFinite(0x80000001)); - REPORTER_ASSERT(reporter, SkScalarIsFinite(0)); -#endif } #endif diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp index 052687da34..49a98c2c2c 100644 --- a/tests/MatrixTest.cpp +++ b/tests/MatrixTest.cpp @@ -5,7 +5,7 @@ static bool nearly_equal_scalar(SkScalar a, SkScalar b) { #ifdef SK_SCALAR_IS_FLOAT const float tolerance = 0.000005f; #else - const int32_t tolerance = 3; + const int32_t tolerance = 8; #endif return SkScalarAbs(a - b) <= tolerance; @@ -14,7 +14,7 @@ static bool nearly_equal_scalar(SkScalar a, SkScalar b) { static bool nearly_equal(const SkMatrix& a, const SkMatrix& b) { for (int i = 0; i < 9; i++) { if (!nearly_equal_scalar(a[i], b[i])) { - printf("not equal %g %g\n", a[i], b[i]); + printf("not equal %g %g\n", (float)a[i], (float)b[i]); return false; } } diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp index 4e6c8b9d59..5b19090bdb 100644 --- a/tests/PaintTest.cpp +++ b/tests/PaintTest.cpp @@ -8,10 +8,14 @@ static void regression_cubic(skiatest::Reporter* reporter) { SkPath path, stroke; SkPaint paint; - path.moveTo(460.2881309415525, 303.250847066498); - path.cubicTo(463.36378422175284, 302.1169735073363, - 456.32239330810046, 304.720354932878, - 453.15255460013304, 305.788586869862); + path.moveTo(SkFloatToFixed(460.2881309415525f), + SkFloatToFixed(303.250847066498)); + path.cubicTo(SkFloatToFixed(463.36378422175284), + SkFloatToFixed(302.1169735073363), + SkFloatToFixed(456.32239330810046), + SkFloatToFixed(304.720354932878), + SkFloatToFixed(453.15255460013304), + SkFloatToFixed(305.788586869862)); SkRect fillR, strokeR; fillR = path.getBounds(); |