]> git.lyx.org Git - lyx.git/blob - src/mathed/matriz.C
get rid of several friends small cleanup
[lyx.git] / src / mathed / matriz.C
1 #include <config.h>
2
3 #include <cstring>
4
5 #include "matriz.h"
6
7 static inline
8 int odd(int x) { return ((x) & 1); }
9
10 #define mateq(m1, m2)  memcpy(m1, m2, sizeof(matriz_data))
11
12
13 Matriz::matriz_data const Matriz::MATIDEN = { {1, 0}, {0, 1}};
14
15
16 Matriz::Matriz()
17 {
18         mateq(m_, MATIDEN);
19 }
20
21
22 void Matriz::rota(int code)
23 {
24         matriz_data r;
25         mateq(r, MATIDEN);
26         float const cs = (odd(code)) ? 0 : (1 - code);
27         float const sn = (odd(code)) ? (2 - code) : 0;
28         r[0][0] = cs;         r[0][1] = sn;
29         r[1][0] = -r[0][1];   r[1][1] = r[0][0];
30         matmat(r);
31 }
32
33
34 void Matriz::escala(float x, float y)
35 {
36         matriz_data s;
37         mateq(s, MATIDEN);
38         s[0][0] = x;  s[1][1] = y;
39         matmat(s);
40 }
41
42
43 void Matriz::matmat(matriz_data & a)
44 {
45         matriz_data c;   
46         for (int i = 0; i < 2; ++i) {
47                 c[0][i] = a[0][0] * m_[0][i] + a[0][1] * m_[1][i];
48                 c[1][i] = a[1][0] * m_[0][i] + a[1][1] * m_[1][i];
49         }
50         mateq(m_, c);
51 }
52
53
54 void Matriz::transf(float xp, float yp, float & x, float & y)
55 {
56         x = m_[0][0] * xp + m_[0][1] * yp;
57         y = m_[1][0] * xp + m_[1][1] * yp;
58 }