aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Cary Clark <caryclark@skia.org>2017-10-18 11:46:18 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-18 16:09:46 +0000
commite4442cb0b537720ab32106b3b5353dbb78f11b26 (patch)
treec96d6669865bc85ef278a178d501bd60d29cc2eb /tests
parentb4379132d12cd11e52944331487b045f1f32989d (diff)
convert mapHomogeneousPoints to SkPoint3
SkMatrix::mapHomogeneousPoints takes an array of SkScalar, but expects essentially SkPoint3, so make it so. R: robertphillips@google.com, reed@google.com Bug: skia:6898 Change-Id: Ibaf8b05c08b7df16c67d6a77d914667ace9a70da Reviewed-on: https://skia-review.googlesource.com/58380 Commit-Queue: Cary Clark <caryclark@skia.org> Commit-Queue: Cary Clark <caryclark@google.com> Reviewed-by: Mike Reed <reed@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Matrix44Test.cpp13
-rw-r--r--tests/MatrixTest.cpp98
2 files changed, 60 insertions, 51 deletions
diff --git a/tests/Matrix44Test.cpp b/tests/Matrix44Test.cpp
index 382cd2175f..6a42a44058 100644
--- a/tests/Matrix44Test.cpp
+++ b/tests/Matrix44Test.cpp
@@ -6,6 +6,7 @@
*/
#include "SkMatrix44.h"
+#include "SkPoint3.h"
#include "Test.h"
static bool nearly_equal_double(double a, double b) {
@@ -554,17 +555,17 @@ static void test_3x3_conversion(skiatest::Reporter* reporter) {
// 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 };
+ SkPoint3 vec3 = { 2, 4, 8 };
SkScalar vec4transformed[4];
- SkScalar vec3transformed[3];
+ SkPoint3 vec3transformed;
SkScalar vec4transformed2[4];
a44.mapScalars(vec4, vec4transformed);
- a33.mapHomogeneousPoints(vec3transformed, vec3, 1);
+ 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], vec3transformed.fX));
+ REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[1], vec3transformed.fY));
+ REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[3], vec3transformed.fZ));
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]));
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp
index 6f7a14fdc7..578e8b06cf 100644
--- a/tests/MatrixTest.cpp
+++ b/tests/MatrixTest.cpp
@@ -8,6 +8,7 @@
#include "SkMath.h"
#include "SkMatrix.h"
#include "SkMatrixUtils.h"
+#include "SkPoint3.h"
#include "SkRandom.h"
#include "Test.h"
@@ -647,9 +648,15 @@ static void test_matrix_decomposition(skiatest::Reporter* reporter) {
}
// For test_matrix_homogeneous, below.
-static bool scalar_array_nearly_equal_relative(const SkScalar a[], const SkScalar b[], int count) {
+static bool point3_array_nearly_equal_relative(const SkPoint3 a[], const SkPoint3 b[], int count) {
for (int i = 0; i < count; ++i) {
- if (!scalar_nearly_equal_relative(a[i], b[i])) {
+ if (!scalar_nearly_equal_relative(a[i].fX, b[i].fX)) {
+ return false;
+ }
+ if (!scalar_nearly_equal_relative(a[i].fY, b[i].fY)) {
+ return false;
+ }
+ if (!scalar_nearly_equal_relative(a[i].fZ, b[i].fZ)) {
return false;
}
}
@@ -658,16 +665,16 @@ static bool scalar_array_nearly_equal_relative(const SkScalar a[], const SkScala
// For test_matrix_homogeneous, below.
// Maps a single triple in src using m and compares results to those in dst
-static bool naive_homogeneous_mapping(const SkMatrix& m, const SkScalar src[3],
- const SkScalar dst[3]) {
- SkScalar res[3];
+static bool naive_homogeneous_mapping(const SkMatrix& m, const SkPoint3& src,
+ const SkPoint3& dst) {
+ SkPoint3 res;
SkScalar ms[9] = {m[0], m[1], m[2],
m[3], m[4], m[5],
m[6], m[7], m[8]};
- res[0] = src[0] * ms[0] + src[1] * ms[1] + src[2] * ms[2];
- res[1] = src[0] * ms[3] + src[1] * ms[4] + src[2] * ms[5];
- res[2] = src[0] * ms[6] + src[1] * ms[7] + src[2] * ms[8];
- return scalar_array_nearly_equal_relative(res, dst, 3);
+ res.fX = src.fX * ms[0] + src.fY * ms[1] + src.fZ * ms[2];
+ res.fY = src.fX * ms[3] + src.fY * ms[4] + src.fZ * ms[5];
+ res.fZ = src.fX * ms[6] + src.fY * ms[7] + src.fZ * ms[8];
+ return point3_array_nearly_equal_relative(&res, &dst, 1);
}
static void test_matrix_homogeneous(skiatest::Reporter* reporter) {
@@ -687,9 +694,11 @@ static void test_matrix_homogeneous(skiatest::Reporter* reporter) {
#endif
SkRandom rand;
- SkScalar randTriples[3*kTripleCount];
- for (int i = 0; i < 3*kTripleCount; ++i) {
- randTriples[i] = rand.nextRangeF(-3000.f, 3000.f);
+ SkPoint3 randTriples[kTripleCount];
+ for (int i = 0; i < kTripleCount; ++i) {
+ randTriples[i].fX = rand.nextRangeF(-3000.f, 3000.f);
+ randTriples[i].fY = rand.nextRangeF(-3000.f, 3000.f);
+ randTriples[i].fZ = rand.nextRangeF(-3000.f, 3000.f);
}
SkMatrix mats[kMatrixCount];
@@ -702,29 +711,28 @@ static void test_matrix_homogeneous(skiatest::Reporter* reporter) {
// identity
{
mat.reset();
- SkScalar dst[3*kTripleCount];
+ SkPoint3 dst[kTripleCount];
mat.mapHomogeneousPoints(dst, randTriples, kTripleCount);
- REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(randTriples, dst, kTripleCount*3));
+ REPORTER_ASSERT(reporter, point3_array_nearly_equal_relative(randTriples, dst, kTripleCount));
}
+ const SkPoint3 zeros = {0.f, 0.f, 0.f};
// zero matrix
{
mat.setAll(0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
- SkScalar dst[3*kTripleCount];
+ SkPoint3 dst[kTripleCount];
mat.mapHomogeneousPoints(dst, randTriples, kTripleCount);
- SkScalar zeros[3] = {0.f, 0.f, 0.f};
for (int i = 0; i < kTripleCount; ++i) {
- REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(&dst[i*3], zeros, 3));
+ REPORTER_ASSERT(reporter, point3_array_nearly_equal_relative(&dst[i], &zeros, 1));
}
}
// zero point
{
- SkScalar zeros[3] = {0.f, 0.f, 0.f};
for (int i = 0; i < kMatrixCount; ++i) {
- SkScalar dst[3];
- mats[i].mapHomogeneousPoints(dst, zeros, 1);
- REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(dst, zeros, 3));
+ SkPoint3 dst;
+ mats[i].mapHomogeneousPoints(&dst, &zeros, 1);
+ REPORTER_ASSERT(reporter, point3_array_nearly_equal_relative(&dst, &zeros, 1));
}
}
@@ -736,29 +744,29 @@ static void test_matrix_homogeneous(skiatest::Reporter* reporter) {
// uniform scale of point
{
mat.setScale(kScale0, kScale0);
- SkScalar dst[3];
- SkScalar src[3] = {randTriples[0], randTriples[1], 1.f};
+ SkPoint3 dst;
+ SkPoint3 src = {randTriples[0].fX, randTriples[0].fY, 1.f};
SkPoint pnt;
- pnt.set(src[0], src[1]);
- mat.mapHomogeneousPoints(dst, src, 1);
+ pnt.set(src.fX, src.fY);
+ mat.mapHomogeneousPoints(&dst, &src, 1);
mat.mapPoints(&pnt, &pnt, 1);
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[0], pnt.fX));
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[1], pnt.fY));
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[2], SK_Scalar1));
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fX, pnt.fX));
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fY, pnt.fY));
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fZ, SK_Scalar1));
}
// rotation of point
{
mat.setRotate(kRotation0);
- SkScalar dst[3];
- SkScalar src[3] = {randTriples[0], randTriples[1], 1.f};
+ SkPoint3 dst;
+ SkPoint3 src = {randTriples[0].fX, randTriples[0].fY, 1.f};
SkPoint pnt;
- pnt.set(src[0], src[1]);
- mat.mapHomogeneousPoints(dst, src, 1);
+ pnt.set(src.fX, src.fY);
+ mat.mapHomogeneousPoints(&dst, &src, 1);
mat.mapPoints(&pnt, &pnt, 1);
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[0], pnt.fX));
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[1], pnt.fY));
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[2], SK_Scalar1));
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fX, pnt.fX));
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fY, pnt.fY));
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fZ, SK_Scalar1));
}
// rotation, scale, rotation of point
@@ -766,24 +774,24 @@ static void test_matrix_homogeneous(skiatest::Reporter* reporter) {
mat.setRotate(kRotation1);
mat.postScale(kScale0, kScale0);
mat.postRotate(kRotation0);
- SkScalar dst[3];
- SkScalar src[3] = {randTriples[0], randTriples[1], 1.f};
+ SkPoint3 dst;
+ SkPoint3 src = {randTriples[0].fX, randTriples[0].fY, 1.f};
SkPoint pnt;
- pnt.set(src[0], src[1]);
- mat.mapHomogeneousPoints(dst, src, 1);
+ pnt.set(src.fX, src.fY);
+ mat.mapHomogeneousPoints(&dst, &src, 1);
mat.mapPoints(&pnt, &pnt, 1);
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[0], pnt.fX));
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[1], pnt.fY));
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[2], SK_Scalar1));
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fX, pnt.fX));
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fY, pnt.fY));
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fZ, SK_Scalar1));
}
// compare with naive approach
{
for (int i = 0; i < kMatrixCount; ++i) {
for (int j = 0; j < kTripleCount; ++j) {
- SkScalar dst[3];
- mats[i].mapHomogeneousPoints(dst, &randTriples[j*3], 1);
- REPORTER_ASSERT(reporter, naive_homogeneous_mapping(mats[i], &randTriples[j*3], dst));
+ SkPoint3 dst;
+ mats[i].mapHomogeneousPoints(&dst, &randTriples[j], 1);
+ REPORTER_ASSERT(reporter, naive_homogeneous_mapping(mats[i], randTriples[j], dst));
}
}
}