~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef __Geom_MATRIX_H__
#define __Geom_MATRIX_H__

/** \file
 *  \brief Definition of Geom::Matrix types.
 *
 * Main authors:
 *   Lauris Kaplinski <lauris@kaplinski.com>:
 *     Original NRMatrix definition and related macros.
 *
 *   Nathan Hurst <njh@mail.csse.monash.edu.au>:
 *     Geom::Matrix class version of the above.
 *
 *   Michael G. Sloan <mgsloan@gmail.com>:
 *     Reorganization and additions.
 *
 * This code is in public domain.
 */

//#include <glib/gmessages.h>

#include <2geom/point.h>

namespace Geom {

/**
 * The Matrix class.
 * 
 * For purposes of multiplication, points should be thought of as row vectors
 *
 * \f$(p_X p_Y 1)\f$
 *
 * to be right-multiplied by transformation matrices of the form
 * \f[
   \left[
   \begin{array}{ccc}
    c_0&c_1&0 \\
    c_2&c_3&0 \\
    c_4&c_5&1
   \end{array}
   \right]
   \f]
 * (so the columns of the matrix correspond to the columns (elements) of the result,
 * and the rows of the matrix correspond to columns (elements) of the "input").
 */
class Matrix {
  private:
    Coord _c[6];
  public:
    Matrix() {}

    Matrix(Matrix const &m) {
        for(int i = 0; i < 6; i++) {
            _c[i] = m[i];
        }
    }

    Matrix(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4, Coord c5) {
        _c[0] = c0; _c[1] = c1;
        _c[2] = c2; _c[3] = c3;
        _c[4] = c4; _c[5] = c5;
    }

    Matrix &operator=(Matrix const &m) {
        for(int i = 0; i < 6; i++)
            _c[i] = m._c[i];
        return *this;
    }

    inline Coord operator[](unsigned const i) const { return _c[i]; }
    inline Coord &operator[](unsigned const i) { return _c[i]; }


    Point xAxis() const;
    Point yAxis() const;
    void setXAxis(Point const &vec);
    void setYAxis(Point const &vec);

    Point translation() const;
    void setTranslation(Point const &loc);

    double expansionX() const;
    double expansionY() const;
    inline Point expansion() const { return Point(expansionX(), expansionY()); }
    void setExpansionX(double val);
    void setExpansionY(double val);

    void setIdentity();

    bool isIdentity(Coord eps = EPSILON) const;
    bool isTranslation(Coord eps = EPSILON) const;
    bool isRotation(double eps = EPSILON) const;
    bool isScale(double eps = EPSILON) const;
    bool isUniformScale(double eps = EPSILON) const;
    bool onlyScaleAndTranslation(double eps = EPSILON) const;
    bool isSingular(double eps = EPSILON) const;

    bool flips() const;

    Matrix without_translation() const;

    Matrix inverse() const;

    Coord det() const;
    Coord descrim2() const;
    Coord descrim() const;
};

Matrix operator*(Matrix const &a, Matrix const &b);
inline Matrix &operator*=(Matrix &a, Matrix const &b) { a = a * b; return a; }

/** A function to print out the Matrix (for debugging) */
inline std::ostream &operator<< (std::ostream &out_file, const Geom::Matrix &m) {
    out_file << "A: " << m[0] << "  C: " << m[2] << "  E: " << m[4] << "\n";
    out_file << "B: " << m[1] << "  D: " << m[3] << "  F: " << m[5] << "\n";
    return out_file;
}

/** Given a matrix m such that unit_circle = m*x, this returns the
 * quadratic form x*A*x = 1. */
Matrix elliptic_quadratic_form(Matrix const &m);

/** Given a matrix (ignoring the translation) this returns the eigen
 * values and vectors. */
class Eigen{
public:
    Point vectors[2];
    double values[2];
    Eigen(Matrix const &m);
};

// Matrix factories
Matrix from_basis(const Point x_basis, const Point y_basis, const Point offset=Point(0,0));

/** Returns the Identity Matrix. */
inline Matrix identity() {
    return Matrix(1.0, 0.0,
                  0.0, 1.0,
                  0.0, 0.0);
}

inline bool operator==(Matrix const &a, Matrix const &b) {
    for(unsigned i = 0; i < 6; ++i) {
        if ( a[i] != b[i] ) return false;
    }
    return true;
}
inline bool operator!=(Matrix const &a, Matrix const &b) { return !( a == b ); }



} /* namespace Geom */

#endif /* !__Geom_MATRIX_H__ */

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :