Scribus
Open source desktop publishing at your fingertips
matrix.h
Go to the documentation of this file.
1 #ifndef __Geom_MATRIX_H__
2 #define __Geom_MATRIX_H__
3 
20 //#include <glib/gmessages.h>
21 
22 #include "point.h"
23 
24 namespace Geom {
25 
46 class Matrix {
47  private:
48  Coord _c[6];
49  public:
50  Matrix() {}
51 
52  Matrix(Matrix const &m) {
53  for(int i = 0; i < 6; i++) {
54  _c[i] = m[i];
55  }
56  }
57 
58  Matrix(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4, Coord c5) {
59  _c[0] = c0; _c[1] = c1;
60  _c[2] = c2; _c[3] = c3;
61  _c[4] = c4; _c[5] = c5;
62  }
63 
64  Matrix &operator=(Matrix const &m) {
65  for(int i = 0; i < 6; i++)
66  _c[i] = m._c[i];
67  return *this;
68  }
69 
70  inline Coord operator[](unsigned const i) const { return _c[i]; }
71  inline Coord &operator[](unsigned const i) { return _c[i]; }
72 
73 
74  Point xAxis() const;
75  Point yAxis() const;
76  Point translation() const;
77  void setXAxis(Point const &vec);
78  void setYAxis(Point const &vec);
79  void setTranslation(Point const &loc);
80 
81  double expansionX() const;
82  double expansionY() const;
83  void setExpansionX(double val);
84  void setExpansionY(double val);
85 
86  void setIdentity();
87 
88  bool isIdentity(Coord eps = EPSILON) const;
89  bool isTranslation(Coord eps = EPSILON) const;
90  bool isRotation(double eps = EPSILON) const;
91  bool isScale(double eps = EPSILON) const;
92  bool isUniformScale(double eps = EPSILON) const;
93  bool onlyScaleAndTranslation(double eps = EPSILON) const;
94 
95  bool flips() const;
96 
98 
99  Matrix inverse() const;
100 
101  Coord det() const;
102  Coord descrim2() const;
103  Coord descrim() const;
104 };
105 
106 Matrix operator*(Matrix const &a, Matrix const &b);
107 
109 inline std::ostream &operator<< (std::ostream &out_file, const Geom::Matrix &m) {
110  out_file << "A: " << m[0] << " C: " << m[2] << " E: " << m[4] << "\n";
111  out_file << "B: " << m[1] << " D: " << m[3] << " F: " << m[5] << "\n";
112  return out_file;
113 }
114 
117 Matrix elliptic_quadratic_form(Matrix const &m);
118 
121 class Eigen{
122 public:
123  Point vectors[2];
124  double values[2];
125  Eigen(Matrix const &m);
126 };
127 
128 // Matrix factories
129 Matrix from_basis(const Point x_basis, const Point y_basis, const Point offset=Point(0,0));
130 
132 inline Matrix identity() {
133  return Matrix(1.0, 0.0,
134  0.0, 1.0,
135  0.0, 0.0);
136 }
137 
138 inline bool operator==(Matrix const &a, Matrix const &b) {
139  for(unsigned i = 0; i < 6; ++i) {
140  if ( a[i] != b[i] ) return false;
141  }
142  return true;
143 }
144 inline bool operator!=(Matrix const &a, Matrix const &b) { return !( a == b ); }
145 
146 
147 
148 } /* namespace Geom */
149 
150 #endif /* !__Geom_MATRIX_H__ */
151 
152 /*
153  Local Variables:
154  mode:c++
155  c-file-style:"stroustrup"
156  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
157  indent-tabs-mode:nil
158  fill-column:99
159  End:
160 */
161 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
bool isUniformScale(double eps=EPSILON) const
Definition: matrix.cpp:140
Matrix identity()
Definition: matrix.h:132
Definition: angle.h:38
Definition: matrix.h:46
double expansionY() const
Definition: matrix.cpp:81
double Coord
Definition: coord.h:45
Point translation() const
Definition: matrix.cpp:48
bool isScale(double eps=EPSILON) const
Definition: matrix.cpp:130
void setIdentity()
Definition: matrix.cpp:102
Definition: matrix.h:121
bool isRotation(double eps=EPSILON) const
Definition: matrix.cpp:150
double expansionX() const
Definition: matrix.cpp:73
Coord descrim() const
Definition: matrix.cpp:207
Coord descrim2() const
Definition: matrix.cpp:202
Matrix elliptic_quadratic_form(Matrix const &m)
Definition: matrix.cpp:224
bool isTranslation(Coord eps=EPSILON) const
Definition: matrix.cpp:120
Matrix inverse() const
Definition: matrix.cpp:174
Cartesian point.
Definition: point.h:20
Matrix without_translation() const
Definition: matrix.cpp:165
Coord det() const
Definition: matrix.cpp:195
void setTranslation(Point const &loc)
Definition: matrix.cpp:64
Matrix from_basis(Point const x_basis, Point const y_basis, Point const offset)
Definition: matrix.cpp:32