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 #include <basegfx/basegfxdllapi.h> 30 31 namespace basegfx 32 { 33 class B2DTuple; 34 class Impl2DHomMatrix; 35 36 class BASEGFX_DLLPUBLIC B2DHomMatrix 37 { 38 public: 39 typedef o3tl::cow_wrapper< Impl2DHomMatrix > ImplType; 40 41 private: 42 ImplType mpImpl; 43 44 public: 45 B2DHomMatrix(); 46 B2DHomMatrix(const B2DHomMatrix& rMat); 47 ~B2DHomMatrix(); 48 49 /** constructor to allow setting all needed values for a 3x2 matrix at once. The 50 parameter f_0x1 e.g. is the same as using set(0, 1, f) 51 */ 52 B2DHomMatrix(double f_0x0, double f_0x1, double f_0x2, double f_1x0, double f_1x1, double f_1x2); 53 54 /// unshare this matrix with all internally shared instances 55 void makeUnique(); 56 57 double get(sal_uInt16 nRow, sal_uInt16 nColumn) const; 58 void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue); 59 60 /** allow setting all needed values for a 3x2 matrix in one call. The 61 parameter f_0x1 e.g. is the same as using set(0, 1, f) 62 */ 63 void set3x2(double f_0x0, double f_0x1, double f_0x2, double f_1x0, double f_1x1, double f_1x2); 64 65 // test if last line is default to see if last line needs to be 66 // involved in calculations 67 bool isLastLineDefault() const; 68 69 // Auf Einheitsmatrix zuruecksetzen 70 bool isIdentity() const; 71 void identity(); 72 73 // Invertierung 74 bool isInvertible() const; 75 bool invert(); 76 77 // Normalisierung 78 bool isNormalized() const; 79 void normalize(); 80 81 // Determinante 82 double determinant() const; 83 84 // Trace 85 double trace() const; 86 87 // Transpose 88 void transpose(); 89 90 // Rotation 91 void rotate(double fRadiant); 92 93 // Translation 94 void translate(double fX, double fY); 95 96 // Skalierung 97 void scale(double fX, double fY); 98 99 // Shearing-Matrices 100 void shearX(double fSx); 101 void shearY(double fSy); 102 103 // Addition, Subtraktion 104 B2DHomMatrix& operator+=(const B2DHomMatrix& rMat); 105 B2DHomMatrix& operator-=(const B2DHomMatrix& rMat); 106 107 // Vergleichsoperatoren 108 bool operator==(const B2DHomMatrix& rMat) const; 109 bool operator!=(const B2DHomMatrix& rMat) const; 110 111 // Multiplikation, Division mit Konstante 112 B2DHomMatrix& operator*=(double fValue); 113 B2DHomMatrix& operator/=(double fValue); 114 115 // Matritzenmultiplikation von links auf die lokale 116 B2DHomMatrix& operator*=(const B2DHomMatrix& rMat); 117 118 // assignment operator 119 B2DHomMatrix& operator=(const B2DHomMatrix& rMat); 120 121 // Help routine to decompose given homogen 3x3 matrix to components. A correction of 122 // the components is done to avoid inaccuracies. 123 // Zerlegung 124 bool decompose(B2DTuple& rScale, B2DTuple& rTranslate, double& rRotate, double& rShearX) const; 125 }; 126 127 // Addition, Subtraktion operator +(const B2DHomMatrix & rMatA,const B2DHomMatrix & rMatB)128 inline B2DHomMatrix operator+(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB) 129 { 130 B2DHomMatrix aSum(rMatA); 131 aSum += rMatB; 132 return aSum; 133 } 134 operator -(const B2DHomMatrix & rMatA,const B2DHomMatrix & rMatB)135 inline B2DHomMatrix operator-(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB) 136 { 137 B2DHomMatrix aDiv(rMatA); 138 aDiv -= rMatB; 139 return aDiv; 140 } 141 142 // Multiplikation, Division mit Konstante operator *(const B2DHomMatrix & rMat,double fValue)143 inline B2DHomMatrix operator*(const B2DHomMatrix& rMat, double fValue) 144 { 145 B2DHomMatrix aNew(rMat); 146 aNew *= fValue; 147 return aNew; 148 } 149 operator /(const B2DHomMatrix & rMat,double fValue)150 inline B2DHomMatrix operator/(const B2DHomMatrix& rMat, double fValue) 151 { 152 B2DHomMatrix aNew(rMat); 153 aNew *= 1.0 / fValue; 154 return aNew; 155 } 156 operator *(const B2DHomMatrix & rMatA,const B2DHomMatrix & rMatB)157 inline B2DHomMatrix operator*(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB) 158 { 159 B2DHomMatrix aMul(rMatB); 160 aMul *= rMatA; 161 return aMul; 162 } 163 } // end of namespace basegfx 164 165 #endif /* _BGFX_MATRIX_B2DHOMMATRIX_HXX */ 166