Skip to content

Commit

Permalink
Simplify kmMat3Transpose and make it work on the same input and outpu…
Browse files Browse the repository at this point in the history
…t. Fix a broken test that was using double rather than kmScalar and trashing memory
  • Loading branch information
Kazade committed Jan 4, 2013
1 parent 5c8bb7c commit db2390f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
21 changes: 15 additions & 6 deletions kazmath/mat3.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,21 @@ const int kmMat3IsIdentity(const kmMat3* pIn)
/** Sets pOut to the transpose of pIn, returns pOut */
kmMat3* const kmMat3Transpose(kmMat3* pOut, const kmMat3* pIn)
{
int z, x;
for (z = 0; z < 3; ++z) {
for (x = 0; x < 3; ++x) {
pOut->mat[(z * 3) + x] = pIn->mat[(x * 3) + z];
}
}
kmScalar temp[9];

temp[0] = pIn->mat[0];
temp[1] = pIn->mat[3];
temp[2] = pIn->mat[6];

temp[3] = pIn->mat[1];
temp[4] = pIn->mat[4];
temp[5] = pIn->mat[7];

temp[6] = pIn->mat[2];
temp[7] = pIn->mat[5];
temp[8] = pIn->mat[8];

memcpy(&pOut->mat, temp, sizeof(kmScalar)*9);

return pOut;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_aabb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <limits>

#include "../kazmath/aabb.h"

/*
TEST(test_aabb_triangle_intersection) {
kmAABB box;
Expand Down Expand Up @@ -49,6 +49,6 @@ TEST(test_aabb_triangle_intersection) {
};
CHECK(kmAABBIntersectsTriangle(&box, &tri4[0], &tri4[1], &tri4[2]));
}
}*/


10 changes: 5 additions & 5 deletions tests/test_mat3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ TEST(test_mat3_inverse) {

TEST(test_mat3_transpose) {
kmMat3 mat;
double temp[] = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
memcpy(mat.mat, temp, sizeof(double) * 9);
kmScalar temp[] = { 1.0f, 3.0f, 5.0f, 2.0f, 4.0f, 6.0f, 8.0f, 3.0f, 1.0f };
memcpy(mat.mat, temp, sizeof(kmScalar) * 9);

kmMat3 transpose;
double temp2[] = {0.0f, 3.0f, 6.0f, 1.0f, 4.0f, 7.0f, 2.0f, 5.0f, 8.0f };
memcpy(transpose.mat, temp2, sizeof(double) * 9);
kmScalar temp2[] = {1.0f, 2.0f, 8.0f, 3.0f, 4.0f, 3.0f, 5.0f, 6.0f, 1.0f };
memcpy(transpose.mat, temp2, sizeof(kmScalar) * 9);

kmMat3 result;
CHECK(NULL != kmMat3Transpose(&result, &mat));
CHECK(kmMat3AreEqual(&transpose, &result));
CHECK(kmMat3AreEqual(&transpose, &result));
}

TEST(test_mat3_fill) {
Expand Down

0 comments on commit db2390f

Please sign in to comment.