LibreOffice Module basegfx (master) 1
b2dhommatrix.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <sal/config.h>
23
24#include <ostream>
25
26#include <sal/types.h>
29#include <array>
30
31namespace basegfx
32{
33 class B2DTuple;
34
36 {
37 private:
38 // Since this is a graphics matrix, the last row is always 0 0 1, so we don't bother to store it.
39 std::array<std::array<double, 3>, 2> mfValues {
40 std::array<double, 3>{ 1.0, 0.0, 0.0 },
41 std::array<double, 3>{ 0.0, 1.0, 0.0 } };
42
43 public:
44 constexpr B2DHomMatrix() = default;
45
49 constexpr B2DHomMatrix(double f_0x0, double f_0x1, double f_0x2, double f_1x0, double f_1x1, double f_1x2)
50 {
51 mfValues[0][0] = f_0x0;
52 mfValues[0][1] = f_0x1;
53 mfValues[0][2] = f_0x2;
54 mfValues[1][0] = f_1x0;
55 mfValues[1][1] = f_1x1;
56 mfValues[1][2] = f_1x2;
57 }
58
68 static B2DHomMatrix abcdef(double da, double db, double dc, double dd, double de, double df)
69 {
70 return B2DHomMatrix(da, dc, de, db, dd, df);
71 }
72
73 // Convenience accessor for value at 0,0 position in the matrix
74 double a() const { return get(0,0); }
75 // Convenience accessor for value at 1,0 position in the matrix
76 double b() const { return get(1,0); }
77 // Convenience accessor for value at 0,1 position in the matrix
78 double c() const { return get(0,1); }
79 // Convenience accessor for value at 1,1 position in the matrix
80 double d() const { return get(1,1); }
81 // Convenience accessor for value at 0,2 position in the matrix
82 double e() const { return get(0,2); }
83 // Convenience accessor for value at 1,2 position in the matrix
84 double f() const { return get(1,2); }
85
86 double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
87 {
88 return mfValues[nRow][nColumn];
89 }
90
91 void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
92 {
93 mfValues[nRow][nColumn] = fValue;
94 }
95
99 void set3x2(double f_0x0, double f_0x1, double f_0x2, double f_1x0, double f_1x1, double f_1x2);
100
101 // reset to a standard matrix
102 bool isIdentity() const;
103 void identity();
104
105 bool isInvertible() const;
106 bool invert();
107
108 void rotate(double fRadiant);
109
110 void translate(double fX, double fY);
111 void translate(const B2DTuple& rTuple);
112
113 void scale(double fX, double fY);
114 void scale(const B2DTuple& rTuple);
115
116 // Shearing-Matrices
117 void shearX(double fSx);
118 void shearY(double fSy);
119
120 bool operator==(const B2DHomMatrix& rMat) const;
121 bool operator!=(const B2DHomMatrix& rMat) const;
122
123 // matrix multiplication from the left to the local
125
133 bool decompose(B2DTuple& rScale, B2DTuple& rTranslate, double& rRotate, double& rShearX) const;
134
135 private:
136 void computeAdjoint(double (&dst)[6]) const;
137 double computeDeterminant(double (&dst)[6]) const;
138 void doMulMatrix(const B2DHomMatrix& rMat);
139 };
140
141 inline B2DHomMatrix operator*(const B2DHomMatrix& rMatA, const B2DHomMatrix& rMatB)
142 {
143 B2DHomMatrix aMul(rMatB);
144 aMul *= rMatA;
145 return aMul;
146 }
147
148 template<typename charT, typename traits>
149 std::basic_ostream<charT, traits> & operator <<(
150 std::basic_ostream<charT, traits> & stream, B2DHomMatrix const & matrix)
151 {
152 return stream
153 << '[' << matrix.get(0, 0) << ' ' << matrix.get(0, 1) << ' '
154 << matrix.get(0, 2) << "; " << matrix.get(1, 0) << ' '
155 << matrix.get(1, 1) << ' ' << matrix.get(1, 2) << ']';
156 }
157} // end of namespace basegfx
158
159/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define BASEGFX_DLLPUBLIC
Definition: basegfxdllapi.h:35
constexpr B2DHomMatrix(double f_0x0, double f_0x1, double f_0x2, double f_1x0, double f_1x1, double f_1x2)
constructor to allow setting all needed values for a 3x2 matrix at once.
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
static B2DHomMatrix abcdef(double da, double db, double dc, double dd, double de, double df)
Convenience creator for declaration of the matrix that is commonly used by web standards (SVG,...
double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
constexpr B2DHomMatrix()=default
Base class for all Points/Vectors with two double values.
Definition: b2dtuple.hxx:39
Reference< XOutputStream > stream
def rotate(shapename, deg)
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, BColor const &color)
Definition: bcolor.hxx:176
B2DPoint operator*(const ::basegfx::B2DHomMatrix &rMat, const B2DPoint &rPoint)
Definition: b2dpoint.cxx:43
rtl::OString decompose(rtl::OString const &type, sal_Int32 *rank=nullptr, std::vector< rtl::OString > *arguments=nullptr)
double matrix[4][4]
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
sal_Int32 scale
#define SAL_WARN_UNUSED
SmFace & operator*=(SmFace &rFace, const Fraction &rFrac)
bool operator!=(const XclExpString &rLeft, const XclExpString &rRight)
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)