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