update to work correctly for scalar == fixed or float

git-svn-id: http://skia.googlecode.com/svn/trunk@780 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@android.com 2011-02-09 02:24:26 +00:00
Родитель 337490d4ae
Коммит d413445531
6 изменённых файлов: 58 добавлений и 55 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -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();
#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(10.0f, 10.0f, 100.0f, 100.0f);
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

Просмотреть файл

@ -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

Просмотреть файл

@ -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;
}
}

Просмотреть файл

@ -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();