1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX
25 #define _BGFX_MATRIX_B2DHOMMATRIX_HXX
26 
27 #include <sal/types.h>
28 #include <o3tl/cow_wrapper.hxx>
29 
30 namespace basegfx
31 {
32 	class B2DTuple;
33     class Impl2DHomMatrix;
34 
35 	class B2DHomMatrix
36 	{
37     public:
38         typedef o3tl::cow_wrapper< Impl2DHomMatrix > ImplType;
39 
40 	private:
41         ImplType                                     mpImpl;
42 
43 	public:
44 		B2DHomMatrix();
45 		B2DHomMatrix(const B2DHomMatrix& rMat);
46 		~B2DHomMatrix();
47 
48 		/** constructor to allow setting all needed values for a 3x2 matrix at once. The
49 			parameter f_0x1 e.g. is the same as using set(0, 1, f)
50 		 */
51 		B2DHomMatrix(double f_0x0, double f_0x1, double f_0x2, double f_1x0, double f_1x1, double f_1x2);
52 
53 		/// unshare this matrix with all internally shared instances
54         void makeUnique();
55 
56 		double get(sal_uInt16 nRow, sal_uInt16 nColumn) const;
57 		void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue);
58 
59 		/** allow setting all needed values for a 3x2 matrix in one call. The
60 			parameter f_0x1 e.g. is the same as using set(0, 1, f)
61 		 */
62 		void set3x2(double f_0x0, double f_0x1, double f_0x2, double f_1x0, double f_1x1, double f_1x2);
63 
64 		// test if last line is default to see if last line needs to be
65 		// involved in calculations
66 		bool isLastLineDefault() const;
67 
68 		// Auf Einheitsmatrix zuruecksetzen
69 		bool isIdentity() const;
70 		void identity();
71 
72 		// Invertierung
73 		bool isInvertible() const;
74 		bool invert();
75 
76 		// Normalisierung
77 		bool isNormalized() const;
78 		void normalize();
79 
80 		// Determinante
81 		double determinant() const;
82 
83 		// Trace
84 		double trace() const;
85 
86 		// Transpose
87 		void transpose();
88 
89 		// Rotation
90 		void rotate(double fRadiant);
91 
92 		// Translation
93 		void translate(double fX, double fY);
94 
95 		// Skalierung
96 		void scale(double fX, double fY);
97 
98 		// Shearing-Matrices
99 		void shearX(double fSx);
100 		void shearY(double fSy);
101 
102 		// Addition, Subtraktion
103 		B2DHomMatrix& operator+=(const B2DHomMatrix& rMat);
104 		B2DHomMatrix& operator-=(const B2DHomMatrix& rMat);
105 
106 		// Vergleichsoperatoren
107 		bool operator==(const B2DHomMatrix& rMat) const;
108 		bool operator!=(const B2DHomMatrix& rMat) const;
109 
110 		// Multiplikation, Division mit Konstante
111 		B2DHomMatrix& operator*=(double fValue);
112 		B2DHomMatrix& operator/=(double fValue);
113 
114 		// Matritzenmultiplikation von links auf die lokale
115 		B2DHomMatrix& operator*=(const B2DHomMatrix& rMat);
116 
117 		// assignment operator
118 		B2DHomMatrix& operator=(const B2DHomMatrix& rMat);
119 
120 		// Help routine to decompose given homogen 3x3 matrix to components. A correction of
121 		// the components is done to avoid inaccuracies.
122 		// Zerlegung
123 		bool decompose(B2DTuple& rScale, B2DTuple& rTranslate, double& rRotate, double& rShearX) const;
124 	};
125 
126 	// Addition, Subtraktion
operator +(const B2DHomMatrix & rMatA,const B2DHomMatrix & rMatB)127 	inline B2DHomMatrix	operator+(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB)
128 	{
129 		B2DHomMatrix aSum(rMatA);
130 		aSum += rMatB;
131 		return aSum;
132 	}
133 
operator -(const B2DHomMatrix & rMatA,const B2DHomMatrix & rMatB)134 	inline B2DHomMatrix	operator-(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB)
135 	{
136 		B2DHomMatrix aDiv(rMatA);
137 		aDiv -= rMatB;
138 		return aDiv;
139 	}
140 
141 	// Multiplikation, Division mit Konstante
operator *(const B2DHomMatrix & rMat,double fValue)142 	inline B2DHomMatrix	operator*(const B2DHomMatrix& rMat, double fValue)
143 	{
144 		B2DHomMatrix aNew(rMat);
145 		aNew *= fValue;
146 		return aNew;
147 	}
148 
operator /(const B2DHomMatrix & rMat,double fValue)149 	inline B2DHomMatrix	operator/(const B2DHomMatrix& rMat, double fValue)
150 	{
151 		B2DHomMatrix aNew(rMat);
152 		aNew *= 1.0 / fValue;
153 		return aNew;
154 	}
155 
operator *(const B2DHomMatrix & rMatA,const B2DHomMatrix & rMatB)156 	inline B2DHomMatrix	operator*(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB)
157 	{
158 		B2DHomMatrix aMul(rMatB);
159 		aMul *= rMatA;
160 		return aMul;
161 	}
162 } // end of namespace basegfx
163 
164 #endif /* _BGFX_MATRIX_B2DHOMMATRIX_HXX */
165