1
#ifndef __Geom_MATRIX_H__
2
#define __Geom_MATRIX_H__
5
* Definition of Geom::Matrix types.
7
* \note Operator functions (e.g. Matrix * Matrix etc.) are mostly in
8
* libnr/matrix-ops.h. See end of file for discussion.
11
* Lauris Kaplinski <lauris@kaplinski.com>:
12
* Original NRMatrix definition and related macros.
14
* Nathan Hurst <njh@mail.csse.monash.edu.au>:
15
* Geom::Matrix class version of the above.
17
* This code is in public domain.
20
//#include <glib/gmessages.h>
26
#include "translate.h"
33
* For purposes of multiplication, points should be thought of as row vectors
37
* to be right-multiplied by transformation matrices
41
| c[4] c[5] 1 | \endverbatim
43
* (so the columns of the matrix correspond to the columns (elements) of the result,
44
* and the rows of the matrix correspond to columns (elements) of the "input").
52
* Various forms of constructor
64
Matrix(Matrix const &m) {
66
Geom::Coord const *src = m._c;
67
Geom::Coord *dest = _c;
86
Matrix(double c0, double c1,
88
double c4, double c5) {
90
Geom::Coord *dest = _c;
106
Matrix &operator=(Matrix const &m) {
108
Geom::Coord const *src = m._c;
109
Geom::Coord *dest = _c;
111
*dest++ = *src++; //0
112
*dest++ = *src++; //1
113
*dest++ = *src++; //2
114
*dest++ = *src++; //3
115
*dest++ = *src++; //4
127
explicit Matrix(scale const &sm) {
129
Geom::Coord *dest = _c;
148
explicit Matrix(rotate const &r) {
150
Geom::Coord *dest = _c;
152
*dest++ = r.vec[X]; //0
153
*dest++ = r.vec[Y]; //1
154
*dest++ = -r.vec[Y]; //2
155
*dest++ = r.vec[X]; //3
167
explicit Matrix(translate const &tm) {
169
Geom::Coord *dest = _c;
185
bool test_identity() const;
191
bool is_translation(Coord const eps = 1e-6) const;
197
Matrix inverse() const;
203
Matrix &operator*=(Matrix const &other);
209
Matrix &operator*=(scale const &other);
216
Matrix &operator*=(translate const &other) {
227
inline Coord &operator[](int const i) {
236
inline Coord operator[](int const i) const {
255
Coord descrim2() const;
261
Coord descrim() const;
267
double expansion() const;
273
double expansionX() const;
279
double expansionY() const;
287
Matrix &assign(Coord const *array);
293
Coord *copyto(Coord *array) const;
303
/** A function to print out the Matrix (for debugging) */
304
inline std::ostream &operator<< (std::ostream &out_file, const Geom::Matrix &m) {
305
out_file << "A: " << m[0] << " C: " << m[2] << " E: " << m[4] << "\n";
306
out_file << "B: " << m[1] << " D: " << m[3] << " F: " << m[5] << "\n";
310
extern void assert_close(Matrix const &a, Matrix const &b);
312
} /* namespace Geom */
321
* Discussion of splitting up matrix.h into lots of little files:
325
* - Reducing amount of recompilation necessary when anything changes.
327
* - Hopefully also reducing compilation time by reducing the number of inline
328
* function definitions encountered by the compiler for a given .o file.
329
* (No timing comparisons done yet. On systems without much memory available
330
* for caching, this may be outweighed by additional I/O costs.)
334
* - More #include lines necessary per file. If a compile fails due to
335
* not having all the necessary #include lines, then the developer needs
336
* to spend some time working out what #include to add.
339
#endif /* !__Geom_MATRIX_H__ */
345
c-file-style:"stroustrup"
346
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
351
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :