source: GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/math/Mat2.h @ 1025

Revision 1025, 2.9 KB checked in by gumbau, 18 years ago (diff)

namespace simplif

Line 
1#ifndef GFXMATH_MAT2_INCLUDED // -*- C++ -*-
2#define GFXMATH_MAT2_INCLUDED
3
4#include <gfx/math/Vec2.h>
5
6namespace simplif
7{
8        class Mat2
9        {
10        private:
11                Vec2 row[2];
12
13        protected:
14
15                inline void copy(const Mat2& m);
16                inline Vec2 col(int i) const {return Vec2(row[0][i],row[1][i]);}
17
18        public:
19                // Standard matrices
20                static Mat2 identity;
21                static Mat2 zero;
22                static Mat2 unit;
23
24                // Standard constructors
25                Mat2() { copy(zero); }
26                Mat2(const Vec2& r0,const Vec2& r1)
27                { row[0]=r0; row[1]=r1; }
28                Mat2(const Mat2& m) { copy(m); }
29
30                // Access methods
31                // M(i, j) == row i;col j
32                real& operator()(int i, int j)       { return row[i][j]; }
33                real  operator()(int i, int j) const { return row[i][j]; }
34
35                // Assignment methods
36                inline Mat2& operator=(const Mat2& m) { copy(m); return *this; }
37                inline Mat2& operator+=(const Mat2& m);
38                inline Mat2& operator-=(const Mat2& m);
39
40                inline Mat2& operator*=(real s);
41                inline Mat2& operator/=(real s);
42
43
44                // Arithmetic methods
45                inline Mat2 operator+(const Mat2& m) const;
46                inline Mat2 operator-(const Mat2& m) const;
47                inline Mat2 operator-() const;
48
49                inline Mat2 operator*(real s) const;
50                inline Mat2 operator/(real s) const;
51                Mat2 operator*(const Mat2& m) const;
52
53                inline Vec2 operator*(const Vec2& v) const; // [x y]
54
55                // Matrix operations
56                real det();
57                Mat2 transpose();
58                real inverse(Mat2&);
59
60
61                // Input/Output methods
62/*              friend ostream& operator<<(ostream&, const Mat2&);
63                friend istream& operator>>(istream&, Mat2&);*/
64        };
65
66
67        inline void Mat2::copy(const Mat2& m)
68        {
69                row[0] = m.row[0]; row[1] = m.row[1];
70        }
71
72        inline Mat2& Mat2::operator+=(const Mat2& m)
73        {
74                row[0] += m.row[0]; row[1] += m.row[1];
75                return *this;
76        }
77
78        inline Mat2& Mat2::operator-=(const Mat2& m)
79        {
80                row[0] -= m.row[0]; row[1] -= m.row[1];
81                return *this;
82        }
83
84        inline Mat2& Mat2::operator*=(real s)
85        {
86                row[0] *= s; row[1] *= s;
87                return *this;
88        }
89
90        inline Mat2& Mat2::operator/=(real s)
91        {
92                row[0] /= s; row[1] /= s;
93                return *this;
94        }
95
96        inline Mat2 Mat2::operator+(const Mat2& m) const
97        {
98                return Mat2(row[0]+m.row[0],
99                        row[1]+m.row[1]);
100        }
101
102        inline Mat2 Mat2::operator-(const Mat2& m) const
103        {
104                return Mat2(row[0]-m.row[0],
105                        row[1]-m.row[1]);
106        }
107
108        inline Mat2 Mat2::operator-() const
109        {
110                return Mat2(-row[0], -row[1]);
111        }
112
113        inline Mat2 Mat2::operator*(real s) const
114        {
115                return Mat2(row[0]*s, row[1]*s);
116        }
117
118        inline Mat2 Mat2::operator/(real s) const
119        {
120                return Mat2(row[0]/s, row[1]/s);
121        }
122
123        inline Vec2 Mat2::operator*(const Vec2& v) const
124        {
125                return Vec2(row[0]*v, row[1]*v);
126        }
127}
128/*
129inline ostream& operator<<(ostream& out, const Mat2& M)
130{
131    return out << M.row[0] << endl  << M.row[1];
132}
133
134inline istream& operator>>(istream& in, Mat2& M)
135{
136    return in >> M.row[0] >> M.row[1];
137}
138*/
139
140// GFXMATH_MAT2_INCLUDED
141#endif
Note: See TracBrowser for help on using the repository browser.