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>
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp
index 6f7a14f..578e8b0 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 @@
}
// 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 @@
// 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 @@
#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 @@
// 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 @@
// 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 @@
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));
}
}
}