~ubuntu-branches/ubuntu/raring/glmark2/raring

« back to all changes in this revision

Viewing changes to src/libmatrix/matrix_inverse_test.cc

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo
  • Date: 2012-08-21 15:38:09 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120821153809-bwux72bat8qp2n5v
Tags: 2012.08-0ubuntu1
* New upstream release 2012.08 (LP: #1039736)
  - Avoid crashing if gl used is not >= 2.0 (LP: #842279)
* Bumping dh compatibility level to v9
* debian/control:
  - Update Standards-Version to 3.9.3.
  - Add libjpeg-dev build dependency.
  - Use libegl1-x11-dev as an build-dep alternative instead of libegl1-dev.
  - Update description of glmark2-data binary package.
* debian/copyright:
  - Refresh copyright based on the current upstrem version
* debian/rules:
  - Clean compiled python code from unpacked waflib/ directory, as
    described in http://wiki.debian.org/UnpackWaf

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// Copyright (c) 2010 Linaro Limited
3
 
//
4
 
// All rights reserved. This program and the accompanying materials
5
 
// are made available under the terms of the MIT License which accompanies
6
 
// this distribution, and is available at
7
 
// http://www.opensource.org/licenses/mit-license.php
8
 
//
9
 
// Contributors:
10
 
//     Jesse Barker - original implementation.
11
 
//
12
 
#include <iostream>
13
 
#include "mat.h"
14
 
 
15
 
using LibMatrix::mat4;
16
 
using LibMatrix::mat3;
17
 
using LibMatrix::mat2;
18
 
using std::cerr;
19
 
using std::cout;
20
 
using std::endl;
21
 
 
22
 
bool mat2OK()
23
 
{
24
 
    mat2 m;
25
 
    cout << "Starting with mat2 (should be identity): " << endl << endl;
26
 
    m.print();
27
 
 
28
 
    m[0][1] = -2.5;
29
 
    
30
 
    cout << endl << "Matrix should now have (0, 1) == -2.500000" << endl << endl;
31
 
    m.print();
32
 
    
33
 
    mat2 mi(m);
34
 
 
35
 
    cout << endl << "Copy of previous matrix (should have (0, 1) == -2.500000)" << endl << endl;
36
 
    mi.print();
37
 
 
38
 
    mi.inverse();
39
 
 
40
 
    cout << endl << "Inverse of copy: " << endl << endl;
41
 
    mi.print();
42
 
 
43
 
    mat2 i = m * mi;
44
 
 
45
 
    cout << endl << "Product of original and inverse (should be identity): " << endl << endl;
46
 
    i.print();
47
 
 
48
 
    mat2 ident;
49
 
    if (i != ident)
50
 
    {
51
 
        return false;
52
 
    }
53
 
 
54
 
    return true;
55
 
}
56
 
 
57
 
bool mat3OK()
58
 
{
59
 
    mat3 m;
60
 
    cout << "Starting with mat3 (should be identity): " << endl << endl;
61
 
    m.print();
62
 
 
63
 
    m[1][2] = -2.5;
64
 
    
65
 
    cout << endl << "Matrix should now have (1, 2) == -2.500000" << endl << endl;
66
 
    m.print();
67
 
    
68
 
    mat3 mi(m);
69
 
 
70
 
    cout << endl << "Copy of previous matrix (should have (1, 2) == -2.500000)" << endl << endl;
71
 
    mi.print();
72
 
 
73
 
    mi.inverse();
74
 
 
75
 
    cout << endl << "Inverse of copy: " << endl << endl;
76
 
    mi.print();
77
 
 
78
 
    mat3 i = m * mi;
79
 
 
80
 
    cout << endl << "Product of original and inverse (should be identity): " << endl << endl;
81
 
    i.print();
82
 
 
83
 
    mat3 ident;
84
 
    if (i != ident)
85
 
    {
86
 
        return false;
87
 
    }
88
 
 
89
 
    return true;
90
 
}
91
 
 
92
 
bool mat4OK()
93
 
{
94
 
    mat4 m;
95
 
    cout << "Starting with mat4 (should be identity): " << endl << endl;
96
 
    m.print();
97
 
 
98
 
    m[2][3] = -2.5;
99
 
    
100
 
    cout << endl << "Matrix should now have (2, 3) == -2.500000" << endl << endl;
101
 
    m.print();
102
 
    
103
 
    mat4 mi(m);
104
 
 
105
 
    cout << endl << "Copy of previous matrix (should have (2, 3) == -2.500000)" << endl << endl;
106
 
    mi.print();
107
 
 
108
 
    mi.inverse();
109
 
 
110
 
    cout << endl << "Inverse of copy: " << endl << endl;
111
 
    mi.print();
112
 
 
113
 
    mat4 i = m * mi;
114
 
 
115
 
    cout << endl <<  "Product of original and inverse (should be identity): " << endl << endl;
116
 
    i.print();
117
 
 
118
 
    mat4 ident;
119
 
    if (i != ident)
120
 
    {
121
 
        return false;
122
 
    }
123
 
 
124
 
    return true;
125
 
}
126
 
 
127
 
int
128
 
main(int argc, char** argv)
129
 
{
130
 
    if (!mat2OK())
131
 
    {
132
 
        cerr << "mat2::inverse() does not work!" << endl;
133
 
        return 1;
134
 
    }
135
 
    cout << "mat2::inverse() is okay!" << endl << endl;
136
 
 
137
 
    if (!mat3OK())
138
 
    {
139
 
        cerr << "mat3::inverse() does not work!" << endl;
140
 
        return 1;
141
 
    }
142
 
    cout << "mat3::inverse() is okay!" << endl << endl;
143
 
 
144
 
    if (!mat4OK())
145
 
    {
146
 
        cerr << "mat4::inverse() does not work!" << endl;
147
 
        return 1;
148
 
    }
149
 
    cout << "mat4::inverse() is okay!" << endl << endl;
150
 
 
151
 
    return 0;
152
 
}