Changeset 1257 for trunk/test


Ignore:
Timestamp:
Apr 21, 2012, 6:58:26 PM (8 years ago)
Author:
sam
Message:

math: add inversion code for 2×2 and 3×3 matrices, and transposition
code for all matrices.

Location:
trunk/test
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Makefile.am

    r1139 r1257  
    2323
    2424testsuite_SOURCES = testsuite.cpp \
    25     unit/vector.cpp unit/half.cpp unit/trig.cpp unit/build.cpp \
    26     unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp
     25    unit/vector.cpp unit/matrix.cpp unit/half.cpp unit/trig.cpp \
     26    unit/build.cpp unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp
    2727testsuite_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@
    2828testsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@
  • trunk/test/benchmark/vector.cpp

    r1139 r1257  
    5353        timer.GetMs();
    5454        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
    55             pf[i] = pm[i].det();
     55            pf[i] = determinant(pm[i]);
    5656        result[1] += timer.GetMs();
    5757
     
    7171        timer.GetMs();
    7272        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
    73             pm[i] = pm[i].invert();
     73            pm[i] = inverse(pm[i]);
    7474        result[4] += timer.GetMs();
    7575    }
  • trunk/test/unit/vector.cpp

    r1139 r1257  
    2121LOLUNIT_FIXTURE(VectorTest)
    2222{
    23     void SetUp()
    24     {
    25         identity = mat4(1.0f);
    26         triangular = mat4(vec4(1.0f, 0.0f, 0.0f, 0.0f),
    27                           vec4(7.0f, 2.0f, 0.0f, 0.0f),
    28                           vec4(1.0f, 5.0f, 3.0f, 0.0f),
    29                           vec4(8.0f, 9.0f, 2.0f, 4.0f));
    30         invertible = mat4(vec4( 1.0f,  1.0f,  2.0f, -1.0f),
    31                           vec4(-2.0f, -1.0f, -2.0f,  2.0f),
    32                           vec4( 4.0f,  2.0f,  5.0f, -4.0f),
    33                           vec4( 5.0f, -3.0f, -7.0f, -6.0f));
    34     }
     23    void SetUp() {}
    3524
    3625    void TearDown() {}
     
    136125        LOLUNIT_ASSERT_EQUAL(a3, a1);
    137126    }
    138 
    139     LOLUNIT_TEST(MatrixDeterminant)
    140     {
    141         float d1 = triangular.det();
    142         LOLUNIT_ASSERT_EQUAL(d1, 24.0f);
    143         float d2 = invertible.det();
    144         LOLUNIT_ASSERT_EQUAL(d2, -1.0f);
    145     }
    146 
    147     LOLUNIT_TEST(MatrixMultiplication)
    148     {
    149         mat4 m0 = identity;
    150         mat4 m1 = identity;
    151         mat4 m2 = m0 * m1;
    152 
    153         LOLUNIT_ASSERT_EQUAL(m2[0][0], 1.0f);
    154         LOLUNIT_ASSERT_EQUAL(m2[1][0], 0.0f);
    155         LOLUNIT_ASSERT_EQUAL(m2[2][0], 0.0f);
    156         LOLUNIT_ASSERT_EQUAL(m2[3][0], 0.0f);
    157 
    158         LOLUNIT_ASSERT_EQUAL(m2[0][1], 0.0f);
    159         LOLUNIT_ASSERT_EQUAL(m2[1][1], 1.0f);
    160         LOLUNIT_ASSERT_EQUAL(m2[2][1], 0.0f);
    161         LOLUNIT_ASSERT_EQUAL(m2[3][1], 0.0f);
    162 
    163         LOLUNIT_ASSERT_EQUAL(m2[0][2], 0.0f);
    164         LOLUNIT_ASSERT_EQUAL(m2[1][2], 0.0f);
    165         LOLUNIT_ASSERT_EQUAL(m2[2][2], 1.0f);
    166         LOLUNIT_ASSERT_EQUAL(m2[3][2], 0.0f);
    167 
    168         LOLUNIT_ASSERT_EQUAL(m2[0][3], 0.0f);
    169         LOLUNIT_ASSERT_EQUAL(m2[1][3], 0.0f);
    170         LOLUNIT_ASSERT_EQUAL(m2[2][3], 0.0f);
    171         LOLUNIT_ASSERT_EQUAL(m2[3][3], 1.0f);
    172     }
    173 
    174     LOLUNIT_TEST(MatrixInverse)
    175     {
    176         mat4 m0 = invertible;
    177         mat4 m1 = m0.invert();
    178 
    179         mat4 m2 = m0 * m1;
    180 
    181         LOLUNIT_ASSERT_EQUAL(m2[0][0], 1.0f);
    182         LOLUNIT_ASSERT_EQUAL(m2[1][0], 0.0f);
    183         LOLUNIT_ASSERT_EQUAL(m2[2][0], 0.0f);
    184         LOLUNIT_ASSERT_EQUAL(m2[3][0], 0.0f);
    185 
    186         LOLUNIT_ASSERT_EQUAL(m2[0][1], 0.0f);
    187         LOLUNIT_ASSERT_EQUAL(m2[1][1], 1.0f);
    188         LOLUNIT_ASSERT_EQUAL(m2[2][1], 0.0f);
    189         LOLUNIT_ASSERT_EQUAL(m2[3][1], 0.0f);
    190 
    191         LOLUNIT_ASSERT_EQUAL(m2[0][2], 0.0f);
    192         LOLUNIT_ASSERT_EQUAL(m2[1][2], 0.0f);
    193         LOLUNIT_ASSERT_EQUAL(m2[2][2], 1.0f);
    194         LOLUNIT_ASSERT_EQUAL(m2[3][2], 0.0f);
    195 
    196         LOLUNIT_ASSERT_EQUAL(m2[0][3], 0.0f);
    197         LOLUNIT_ASSERT_EQUAL(m2[1][3], 0.0f);
    198         LOLUNIT_ASSERT_EQUAL(m2[2][3], 0.0f);
    199         LOLUNIT_ASSERT_EQUAL(m2[3][3], 1.0f);
    200     }
    201 
    202     mat4 triangular, identity, invertible;
    203127};
    204128
Note: See TracChangeset for help on using the changeset viewer.