Skip to content

Commit

Permalink
Wrote tests transferable to the 2x2 cases in C++
Browse files Browse the repository at this point in the history
Signed-off-by: Owen Thompson <[email protected]>
  • Loading branch information
oxt3479 authored and cary-ilm committed Apr 17, 2020
1 parent d404df4 commit 1b20f7b
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions IlmBase/ImathTest/testMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,54 @@ testMatrix ()
union {double d; Int64 i;} nand;
nand.i = 0x7ff0000000000001ULL; // NAN

{
cout << "Imath::M22f constructors and equality operators" << endl;

IMATH_INTERNAL_NAMESPACE::M22f m1;
m1[0][0] = 99.0f;
m1[1][2] = 101.0f;

IMATH_INTERNAL_NAMESPACE::M22f test(m1);
assert(test == m1);

IMATH_INTERNAL_NAMESPACE::M22f test2;
assert(test != test2);

IMATH_INTERNAL_NAMESPACE::M22f test3;
test3.makeIdentity();
assert(test2 == test3);
}

{
cout << "M22d constructors and equality operators" << endl;

IMATH_INTERNAL_NAMESPACE::M22d m2;
m2[0][0] = 99.0f;
m2[1][2] = 101.0f;

IMATH_INTERNAL_NAMESPACE::M22d test(m2);
assert(test == m2);

IMATH_INTERNAL_NAMESPACE::M22d test2;
assert(test != test2);

IMATH_INTERNAL_NAMESPACE::M22d test3;
test3.makeIdentity();
assert(test2 == test3);

IMATH_INTERNAL_NAMESPACE::M22f test4 (1.0f, 2.0f, 3.0f,
4.0f);

IMATH_INTERNAL_NAMESPACE::M22d test5 = IMATH_INTERNAL_NAMESPACE::M22d (test4);

assert (test5[0][0] == 1.0);
assert (test5[0][1] == 2.0);


assert (test5[1][0] == 3.0);
assert (test5[1][1] == 4.0);
}

{
cout << "Imath::M33f shear functions" << endl;

Expand Down Expand Up @@ -276,6 +324,40 @@ testMatrix ()
}

// Determinants (by building a random singular value decomposition)

{
cout << "2x2 determinant" << endl;

IMATH_INTERNAL_NAMESPACE::Rand32 random;

IMATH_INTERNAL_NAMESPACE::M22f u;
IMATH_INTERNAL_NAMESPACE::M22f v;
IMATH_INTERNAL_NAMESPACE::M22f s;

u.setRotation( random.nextf() );
v.setRotation( random.nextf() );
s[0][0] = random.nextf();
s[1][1] = random.nextf();

IMATH_INTERNAL_NAMESPACE::M22f c = u * s * v.transpose();
assert (fabsf(c.determinant() - s[0][0]*s[1][1]) <= u.baseTypeEpsilon());
}
{
IMATH_INTERNAL_NAMESPACE::Rand32 random;

IMATH_INTERNAL_NAMESPACE::M22d u;
IMATH_INTERNAL_NAMESPACE::M22d v;
IMATH_INTERNAL_NAMESPACE::M22d s;

u.setRotation( (double)random.nextf() );
v.setRotation( (double)random.nextf() );
s[0][0] = (double)random.nextf();
s[1][1] = (double)random.nextf();

IMATH_INTERNAL_NAMESPACE::M22d c = u * s * v.transpose();
assert (fabs(c.determinant() - s[0][0]*s[1][1]) <= u.baseTypeEpsilon());
}

{
cout << "3x3 determinant" << endl;

Expand Down

0 comments on commit 1b20f7b

Please sign in to comment.