LibreOffice Module basegfx (master) 1
b2dhommatrixtools.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/types.h>
27#include <utility>
29
30namespace basegfx { class B2DRange; }
31
32namespace basegfx::utils
33{
42 void createSinCosOrthogonal(double& o_rSin, double& rCos, double fRadiant);
43
47 BASEGFX_DLLPUBLIC B2DHomMatrix createScaleB2DHomMatrix(double fScaleX, double fScaleY);
48 BASEGFX_DLLPUBLIC B2DHomMatrix createShearXB2DHomMatrix(double fShearX);
49 BASEGFX_DLLPUBLIC B2DHomMatrix createShearYB2DHomMatrix(double fShearY);
50 BASEGFX_DLLPUBLIC B2DHomMatrix createRotateB2DHomMatrix(double fRadiant);
51 BASEGFX_DLLPUBLIC B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY);
52
55 {
56 return createScaleB2DHomMatrix(rScale.getX(), rScale.getY());
57 }
58
60 {
61 return createTranslateB2DHomMatrix(rTranslate.getX(), rTranslate.getY());
62 }
63
72 double fScaleX, double fScaleY,
73 double fShearX,
74 double fRadiant,
75 double fTranslateX, double fTranslateY);
77 const B2DTuple& rScale,
78 double fShearX,
79 double fRadiant,
80 const B2DTuple& rTranslate)
81 {
83 rScale.getX(), rScale.getY(),
84 fShearX,
85 fRadiant,
86 rTranslate.getX(), rTranslate.getY());
87 }
88
90 double fShearX,
91 double fRadiant,
92 double fTranslateX, double fTranslateY);
94 double fShearX,
95 double fRadiant,
96 const B2DTuple& rTranslate)
97 {
99 fShearX,
100 fRadiant,
101 rTranslate.getX(), rTranslate.getY());
102 }
103
105 double fScaleX, double fScaleY,
106 double fTranslateX, double fTranslateY);
108 const B2DTuple& rScale,
109 const B2DTuple& rTranslate)
110 {
112 rScale.getX(), rScale.getY(),
113 rTranslate.getX(), rTranslate.getY());
114 }
115
118 double fPointX, double fPointY,
119 double fRadiant);
121 const B2DTuple& rPoint,
122 double fRadiant)
123 {
125 rPoint.getX(), rPoint.getY(),
126 fRadiant);
127 }
128
133 const basegfx::B2DRange& rTargetRange,
134 double fRotate);
135
138 const B2DRange& rSourceRange,
139 const B2DRange& rTargetRange);
140
143 const B2DPoint& rOrigin,
144 const B2DVector& rX,
145 const B2DVector& rY);
146
148 BASEGFX_DLLPUBLIC B2DTuple getColumn(const B2DHomMatrix& rMatrix, sal_uInt16 nCol);
149
150
152 {
153 private:
156 double mfRotate;
157 double mfShearX;
158
159 public:
161 : mfRotate(0.0),
162 mfShearX(0.0)
163 {
164 rB2DHomMatrix.decompose(maScale, maTranslate, mfRotate, mfShearX);
165 }
166
167 // data access
169 {
171 maScale, mfShearX, mfRotate, maTranslate);
172 }
173
174 const B2DVector& getScale() const { return maScale; }
175 const B2DVector& getTranslate() const { return maTranslate; }
176 double getRotate() const { return mfRotate; }
177 double getShearX() const { return mfShearX; }
178 };
179
181 {
182 private:
186 double mfRotate;
187 double mfShearX;
188
189 bool mbDecomposed : 1;
190
192 {
193 if(!mbDecomposed)
194 {
195 maB2DHomMatrix.decompose(maScale, maTranslate, mfRotate, mfShearX);
196 mbDecomposed = true;
197 }
198 }
199
200 public:
202 : maB2DHomMatrix(std::move(aB2DHomMatrix)),
203 mfRotate(0.0),
204 mfShearX(0.0),
205 mbDecomposed(false)
206 {
207 }
208
209 // data access
210 const B2DHomMatrix& getB2DHomMatrix() const { return maB2DHomMatrix; }
211 const B2DVector& getScale() const { const_cast< B2DHomMatrixBufferedOnDemandDecompose* >(this)->impCheckDecompose(); return maScale; }
212 const B2DVector& getTranslate() const { const_cast< B2DHomMatrixBufferedOnDemandDecompose* >(this)->impCheckDecompose(); return maTranslate; }
213 double getRotate() const { const_cast< B2DHomMatrixBufferedOnDemandDecompose* >(this)->impCheckDecompose(); return mfRotate; }
214 double getShearX() const { const_cast< B2DHomMatrixBufferedOnDemandDecompose* >(this)->impCheckDecompose(); return mfShearX; }
215 };
216} // end of namespace basegfx::utils
217
218/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define BASEGFX_DLLPUBLIC
Definition: basegfxdllapi.h:35
bool decompose(B2DTuple &rScale, B2DTuple &rTranslate, double &rRotate, double &rShearX) const
Help routine to decompose given homogen 3x3 matrix to components.
Base Point class with two double values.
Definition: b2dpoint.hxx:42
A two-dimensional interval over doubles.
Definition: b2drange.hxx:54
Base class for all Points/Vectors with two double values.
Definition: b2dtuple.hxx:39
Base Point class with two double values.
Definition: b2dvector.hxx:40
TYPE getX() const
Get X-Coordinate of 2D Tuple.
Definition: Tuple2D.hxx:63
TYPE getY() const
Get Y-Coordinate of 2D Tuple.
Definition: Tuple2D.hxx:66
B2DHomMatrixBufferedDecompose(const B2DHomMatrix &rB2DHomMatrix=B2DHomMatrix())
B2DHomMatrixBufferedOnDemandDecompose(B2DHomMatrix aB2DHomMatrix=B2DHomMatrix())
B2DHomMatrix createCoordinateSystemTransform(const B2DPoint &rOrigin, const B2DVector &rX, const B2DVector &rY)
create based on given CoordinateSystem which is defined by origin and x/yaxis
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
B2DHomMatrix createRotateAroundPoint(double fPointX, double fPointY, double fRadiant)
special for the often used case of rotation around a point
B2DHomMatrix createShearYB2DHomMatrix(double fShearY)
B2DHomMatrix createRotateAroundCenterKeepAspectRatioStayInsideRange(const basegfx::B2DRange &rTargetRange, double fRotate)
special for creating a mapping for a Range rotated around it's center while keeping AspectRatio uncha...
B2DHomMatrix createScaleB2DHomMatrix(double fScaleX, double fScaleY)
Tooling methods for on-the-fly matrix generation e.g.
B2DHomMatrix createShearXB2DHomMatrix(double fShearX)
B2DTuple getColumn(const B2DHomMatrix &rMatrix, sal_uInt16 nCol)
get column vector from B2dHomMatrix, e.g. to extract coordinate system origin and x/yaxis
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
B2DHomMatrix createRotateB2DHomMatrix(double fRadiant)
void createSinCosOrthogonal(double &o_rSin, double &o_rCos, double fRadiant)
If the rotation angle is an approximate multiple of pi/2, force fSin/fCos to -1/0/1,...
B2DHomMatrix createScaleShearXRotateTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
Tooling methods for faster completely combined matrix creation when scale, shearX,...
B2DHomMatrix createShearXRotateTranslateB2DHomMatrix(double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
B2DHomMatrix createSourceRangeTargetRangeTransform(const B2DRange &rSourceRange, const B2DRange &rTargetRange)
special for the case to map from source range to target range
basegfx::B2DHomMatrix maB2DHomMatrix