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])) { SkDebugf("not equal %g %g\n", (float)a[i], (float)b[i]); return false; } } return true; }
static bool nearly_equal(const SkMatrix44& a, const SkMatrix44& b) { for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { if (!nearly_equal_scalar(a.get(i, j), b.get(i, j))) { printf("not equal %g %g\n", a.get(i, j), b.get(i, j)); return false; } } } return true; }
static void test_3x3_conversion(skiatest::Reporter* reporter) { SkMScalar values4x4[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; SkScalar values3x3[9] = { 1, 2, 4, 5, 6, 8, 13, 14, 16 }; SkMScalar values4x4flattened[16] = { 1, 2, 0, 4, 5, 6, 0, 8, 0, 0, 1, 0, 13, 14, 0, 16 }; SkMatrix44 a44(SkMatrix44::kUninitialized_Constructor); a44.setRowMajor(values4x4); SkMatrix a33 = a44; SkMatrix expected33; for (int i = 0; i < 9; i++) expected33[i] = values3x3[i]; REPORTER_ASSERT(reporter, expected33 == a33); SkMatrix44 a44flattened = a33; SkMatrix44 expected44flattened(SkMatrix44::kUninitialized_Constructor); expected44flattened.setRowMajor(values4x4flattened); REPORTER_ASSERT(reporter, nearly_equal(a44flattened, expected44flattened)); // Test that a point with a Z value of 0 is transformed the same way. SkScalar vec4[4] = { 2, 4, 0, 8 }; SkScalar vec3[3] = { 2, 4, 8 }; SkScalar vec4transformed[4]; SkScalar vec3transformed[3]; SkScalar vec4transformed2[4]; a44.mapScalars(vec4, vec4transformed); a33.mapHomogeneousPoints(vec3transformed, vec3, 1); a44flattened.mapScalars(vec4, vec4transformed2); REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[0], vec3transformed[0])); REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[1], vec3transformed[1])); REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[3], vec3transformed[2])); REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[0], vec4transformed2[0])); REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[1], vec4transformed2[1])); REPORTER_ASSERT(reporter, !nearly_equal_scalar(vec4transformed[2], vec4transformed2[2])); REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[3], vec4transformed2[3])); }