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 _BGFX_MATRIX_B2DHOMMATRIX_HXX
21 #define _BGFX_MATRIX_B2DHOMMATRIX_HXX
23 #include <sal/types.h>
24 #include <o3tl/cow_wrapper.hxx>
25 #include <basegfx/basegfxdllapi.h>
30 class Impl2DHomMatrix
;
32 class BASEGFX_DLLPUBLIC B2DHomMatrix
35 typedef o3tl::cow_wrapper
< Impl2DHomMatrix
> ImplType
;
42 B2DHomMatrix(const B2DHomMatrix
& rMat
);
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)
48 B2DHomMatrix(double f_0x0
, double f_0x1
, double f_0x2
, double f_1x0
, double f_1x1
, double f_1x2
);
50 double get(sal_uInt16 nRow
, sal_uInt16 nColumn
) const;
51 void set(sal_uInt16 nRow
, sal_uInt16 nColumn
, double fValue
);
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)
56 void set3x2(double f_0x0
, double f_0x1
, double f_0x2
, double f_1x0
, double f_1x1
, double f_1x2
);
58 // test if last line is default to see if last line needs to be
59 // involved in calculations
60 bool isLastLineDefault() const;
62 // reset to a standard matrix
63 bool isIdentity() const;
66 bool isInvertible() const;
69 void rotate(double fRadiant
);
71 void translate(double fX
, double fY
);
73 void scale(double fX
, double fY
);
76 void shearX(double fSx
);
77 void shearY(double fSy
);
79 B2DHomMatrix
& operator+=(const B2DHomMatrix
& rMat
);
80 B2DHomMatrix
& operator-=(const B2DHomMatrix
& rMat
);
82 bool operator==(const B2DHomMatrix
& rMat
) const;
83 bool operator!=(const B2DHomMatrix
& rMat
) const;
85 B2DHomMatrix
& operator*=(double fValue
);
86 B2DHomMatrix
& operator/=(double fValue
);
88 // matrix multiplication from the left to the local
89 B2DHomMatrix
& operator*=(const B2DHomMatrix
& rMat
);
91 // assignment operator
92 B2DHomMatrix
& operator=(const B2DHomMatrix
& rMat
);
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;
99 // addition, subtraction
100 inline B2DHomMatrix
operator+(const B2DHomMatrix
& rMatA
, const B2DHomMatrix
& rMatB
)
102 B2DHomMatrix
aSum(rMatA
);
107 inline B2DHomMatrix
operator-(const B2DHomMatrix
& rMatA
, const B2DHomMatrix
& rMatB
)
109 B2DHomMatrix
aDiv(rMatA
);
114 // multiplication, division by a constant
115 inline B2DHomMatrix
operator*(const B2DHomMatrix
& rMat
, double fValue
)
117 B2DHomMatrix
aNew(rMat
);
122 inline B2DHomMatrix
operator/(const B2DHomMatrix
& rMat
, double fValue
)
124 B2DHomMatrix
aNew(rMat
);
125 aNew
*= 1.0 / fValue
;
129 inline B2DHomMatrix
operator*(const B2DHomMatrix
& rMatA
, const B2DHomMatrix
& rMatB
)
131 B2DHomMatrix
aMul(rMatB
);
135 } // end of namespace basegfx
137 #endif /* _BGFX_MATRIX_B2DHOMMATRIX_HXX */
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */