1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_BASEGFX_MATRIX_B2DHOMMATRIX_HXX
21 #define INCLUDED_BASEGFX_MATRIX_B2DHOMMATRIX_HXX
23 #include <sal/config.h>
27 #include <sal/types.h>
28 #include <o3tl/cow_wrapper.hxx>
29 #include <basegfx/basegfxdllapi.h>
34 class Impl2DHomMatrix
;
36 class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2DHomMatrix
39 typedef o3tl::cow_wrapper
< Impl2DHomMatrix
> ImplType
;
46 B2DHomMatrix(const B2DHomMatrix
& rMat
);
47 B2DHomMatrix(B2DHomMatrix
&& rMat
);
50 /** Convenience creator for declaration of the matrix that is commonly
51 used by web standards (SVG, CSS, HTML).
53 Values a,b,c,d,e,f represent the following values in the matrix:
59 static B2DHomMatrix
abcdef(double da
, double db
, double dc
, double dd
, double de
, double df
)
61 return B2DHomMatrix(da
, dc
, de
, db
, dd
, df
);
64 // Convenience accessor for value at 0,0 position in the matrix
65 double a() { return get(0,0); }
66 // Convenience accessor for value at 1,0 position in the matrix
67 double b() { return get(1,0); }
68 // Convenience accessor for value at 0,1 position in the matrix
69 double c() { return get(0,1); }
70 // Convenience accessor for value at 1,1 position in the matrix
71 double d() { return get(1,1); }
72 // Convenience accessor for value at 0,2 position in the matrix
73 double e() { return get(0,2); }
74 // Convenience accessor for value at 1,2 position in the matrix
75 double f() { return get(1,2); }
77 /** constructor to allow setting all needed values for a 3x2 matrix at once. The
78 parameter f_0x1 e.g. is the same as using set(0, 1, f)
80 B2DHomMatrix(double f_0x0
, double f_0x1
, double f_0x2
, double f_1x0
, double f_1x1
, double f_1x2
);
82 double get(sal_uInt16 nRow
, sal_uInt16 nColumn
) const;
83 void set(sal_uInt16 nRow
, sal_uInt16 nColumn
, double fValue
);
85 /** allow setting all needed values for a 3x2 matrix in one call. The
86 parameter f_0x1 e.g. is the same as using set(0, 1, f)
88 void set3x2(double f_0x0
, double f_0x1
, double f_0x2
, double f_1x0
, double f_1x1
, double f_1x2
);
90 // test if last line is default to see if last line needs to be
91 // involved in calculations
92 bool isLastLineDefault() const;
94 // reset to a standard matrix
95 bool isIdentity() const;
98 bool isInvertible() const;
101 void rotate(double fRadiant
);
103 void translate(double fX
, double fY
);
104 void translate(const B2DTuple
& rTuple
);
106 void scale(double fX
, double fY
);
107 void scale(const B2DTuple
& rTuple
);
110 void shearX(double fSx
);
111 void shearY(double fSy
);
113 B2DHomMatrix
& operator+=(const B2DHomMatrix
& rMat
);
114 B2DHomMatrix
& operator-=(const B2DHomMatrix
& rMat
);
116 bool operator==(const B2DHomMatrix
& rMat
) const;
117 bool operator!=(const B2DHomMatrix
& rMat
) const;
119 B2DHomMatrix
& operator*=(double fValue
);
120 B2DHomMatrix
& operator/=(double fValue
);
122 // matrix multiplication from the left to the local
123 B2DHomMatrix
& operator*=(const B2DHomMatrix
& rMat
);
125 // assignment operator
126 B2DHomMatrix
& operator=(const B2DHomMatrix
& rMat
);
127 B2DHomMatrix
& operator=(B2DHomMatrix
&& rMat
);
129 // Help routine to decompose given homogen 3x3 matrix to components. A correction of
130 // the components is done to avoid inaccuracies.
131 bool decompose(B2DTuple
& rScale
, B2DTuple
& rTranslate
, double& rRotate
, double& rShearX
) const;
134 inline B2DHomMatrix
operator*(const B2DHomMatrix
& rMatA
, const B2DHomMatrix
& rMatB
)
136 B2DHomMatrix
aMul(rMatB
);
141 template<typename charT
, typename traits
>
142 std::basic_ostream
<charT
, traits
> & operator <<(
143 std::basic_ostream
<charT
, traits
> & stream
, B2DHomMatrix
const & matrix
)
146 << '[' << matrix
.get(0, 0) << ' ' << matrix
.get(0, 1) << ' '
147 << matrix
.get(0, 2) << "; " << matrix
.get(1, 0) << ' '
148 << matrix
.get(1, 1) << ' ' << matrix
.get(1, 2) << "; "
149 << matrix
.get(2, 0) << ' ' << matrix
.get(2, 1) << ' '
150 << matrix
.get(2, 2) << ']';
152 } // end of namespace basegfx
154 #endif // INCLUDED_BASEGFX_MATRIX_B2DHOMMATRIX_HXX
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */