Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_BASEGFX_MATRIX_B2DHOMMATRIX_HXX
21 : #define INCLUDED_BASEGFX_MATRIX_B2DHOMMATRIX_HXX
22 :
23 : #include <sal/types.h>
24 : #include <o3tl/cow_wrapper.hxx>
25 : #include <basegfx/basegfxdllapi.h>
26 :
27 : namespace basegfx
28 : {
29 : class B2DTuple;
30 : class Impl2DHomMatrix;
31 :
32 : class BASEGFX_DLLPUBLIC B2DHomMatrix
33 : {
34 : public:
35 : typedef o3tl::cow_wrapper< Impl2DHomMatrix > ImplType;
36 :
37 : private:
38 : ImplType mpImpl;
39 :
40 : public:
41 : B2DHomMatrix();
42 : B2DHomMatrix(const B2DHomMatrix& rMat);
43 : ~B2DHomMatrix();
44 :
45 : /** constructor to allow setting all needed values for a 3x2 matrix at once. The
46 : parameter f_0x1 e.g. is the same as using set(0, 1, f)
47 : */
48 : B2DHomMatrix(double f_0x0, double f_0x1, double f_0x2, double f_1x0, double f_1x1, double f_1x2);
49 :
50 : double get(sal_uInt16 nRow, sal_uInt16 nColumn) const;
51 : void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue);
52 :
53 : /** allow setting all needed values for a 3x2 matrix in one call. The
54 : parameter f_0x1 e.g. is the same as using set(0, 1, f)
55 : */
56 : void set3x2(double f_0x0, double f_0x1, double f_0x2, double f_1x0, double f_1x1, double f_1x2);
57 :
58 : // test if last line is default to see if last line needs to be
59 : // involved in calculations
60 : bool isLastLineDefault() const;
61 :
62 : // reset to a standard matrix
63 : bool isIdentity() const;
64 : void identity();
65 :
66 : bool isInvertible() const;
67 : bool invert();
68 :
69 : void rotate(double fRadiant);
70 :
71 : void translate(double fX, double fY);
72 :
73 : void scale(double fX, double fY);
74 :
75 : // Shearing-Matrices
76 : void shearX(double fSx);
77 : void shearY(double fSy);
78 :
79 : B2DHomMatrix& operator+=(const B2DHomMatrix& rMat);
80 : B2DHomMatrix& operator-=(const B2DHomMatrix& rMat);
81 :
82 : bool operator==(const B2DHomMatrix& rMat) const;
83 : bool operator!=(const B2DHomMatrix& rMat) const;
84 :
85 : B2DHomMatrix& operator*=(double fValue);
86 : B2DHomMatrix& operator/=(double fValue);
87 :
88 : // matrix multiplication from the left to the local
89 : B2DHomMatrix& operator*=(const B2DHomMatrix& rMat);
90 :
91 : // assignment operator
92 : B2DHomMatrix& operator=(const B2DHomMatrix& rMat);
93 :
94 : // Help routine to decompose given homogen 3x3 matrix to components. A correction of
95 : // the components is done to avoid inaccuracies.
96 : bool decompose(B2DTuple& rScale, B2DTuple& rTranslate, double& rRotate, double& rShearX) const;
97 : };
98 :
99 : // addition, subtraction
100 : inline B2DHomMatrix operator+(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB)
101 : {
102 : B2DHomMatrix aSum(rMatA);
103 : aSum += rMatB;
104 : return aSum;
105 : }
106 :
107 : inline B2DHomMatrix operator-(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB)
108 : {
109 : B2DHomMatrix aDiv(rMatA);
110 : aDiv -= rMatB;
111 : return aDiv;
112 : }
113 :
114 : // multiplication, division by a constant
115 : inline B2DHomMatrix operator*(const B2DHomMatrix& rMat, double fValue)
116 : {
117 : B2DHomMatrix aNew(rMat);
118 : aNew *= fValue;
119 : return aNew;
120 : }
121 :
122 : inline B2DHomMatrix operator/(const B2DHomMatrix& rMat, double fValue)
123 : {
124 : B2DHomMatrix aNew(rMat);
125 : aNew *= 1.0 / fValue;
126 : return aNew;
127 : }
128 :
129 0 : inline B2DHomMatrix operator*(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB)
130 : {
131 0 : B2DHomMatrix aMul(rMatB);
132 0 : aMul *= rMatA;
133 0 : return aMul;
134 : }
135 : } // end of namespace basegfx
136 :
137 : #endif // INCLUDED_BASEGFX_MATRIX_B2DHOMMATRIX_HXX
138 :
139 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|