]> git.lyx.org Git - lyx.git/blob - src/mathed/matriz.C
adjust to be able to complile with gcc 3.0, put selection vars into own struct, remov...
[lyx.git] / src / mathed / matriz.C
1 #include <config.h>
2
3 #include <cstring> // memcpy
4
5 #include "matriz.h"
6
7 #ifndef CXX_GLOBAL_CSTD
8 using std::memcpy;
9 #endif
10  
11 namespace {
12
13 inline
14 int odd(int x)
15 {
16         return (x & 1);
17 }
18
19 } // namespace anon
20
21
22 #define mateq(m1, m2)  memcpy(m1, m2, sizeof(matriz_data))
23
24
25 Matriz::matriz_data const Matriz::MATIDEN = { {1, 0}, {0, 1}};
26
27
28 Matriz::Matriz()
29 {
30         mateq(m_, MATIDEN);
31 }
32
33
34 void Matriz::rota(int code)
35 {
36         matriz_data r;
37         mateq(r, MATIDEN);
38         float const cs = (odd(code)) ? 0 : (1 - code);
39         float const sn = (odd(code)) ? (2 - code) : 0;
40         r[0][0] = cs;
41         r[0][1] = sn;
42         r[1][0] = -r[0][1];
43         r[1][1] = r[0][0];
44         matmat(r);
45 }
46
47
48 void Matriz::escala(float x, float y)
49 {
50         matriz_data s;
51         mateq(s, MATIDEN);
52         s[0][0] = x;
53         s[1][1] = y;
54         matmat(s);
55 }
56
57
58 void Matriz::matmat(matriz_data & a)
59 {
60         matriz_data c;
61         c[0][0] = a[0][0] * m_[0][0] + a[0][1] * m_[1][0];
62         c[1][0] = a[1][0] * m_[0][0] + a[1][1] * m_[1][0];
63         c[0][1] = a[0][0] * m_[0][1] + a[0][1] * m_[1][1];
64         c[1][1] = a[1][0] * m_[0][1] + a[1][1] * m_[1][1];
65         mateq(m_, c);
66 }
67
68
69 void Matriz::transf(float xp, float yp, float & x, float & y)
70 {
71         x = m_[0][0] * xp + m_[0][1] * yp;
72         y = m_[1][0] * xp + m_[1][1] * yp;
73 }