JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_AffineTransform.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
42class JUCE_API AffineTransform final
43{
44public:
45 //==============================================================================
47 AffineTransform() = default;
48
50 AffineTransform (const AffineTransform&) = default;
51
60 AffineTransform (float mat00, float mat01, float mat02,
61 float mat10, float mat11, float mat12) noexcept;
62
64 AffineTransform& operator= (const AffineTransform&) = default;
65
67 bool operator== (const AffineTransform& other) const noexcept;
68
70 bool operator!= (const AffineTransform& other) const noexcept;
71
72 //==============================================================================
74 template <typename ValueType>
75 void transformPoint (ValueType& x, ValueType& y) const noexcept
76 {
77 auto oldX = x;
78 x = static_cast<ValueType> (mat00 * oldX + mat01 * y + mat02);
79 y = static_cast<ValueType> (mat10 * oldX + mat11 * y + mat12);
80 }
81
87 template <typename ValueType>
88 void transformPoints (ValueType& x1, ValueType& y1,
89 ValueType& x2, ValueType& y2) const noexcept
90 {
91 auto oldX1 = x1, oldX2 = x2;
92 x1 = static_cast<ValueType> (mat00 * oldX1 + mat01 * y1 + mat02);
93 y1 = static_cast<ValueType> (mat10 * oldX1 + mat11 * y1 + mat12);
94 x2 = static_cast<ValueType> (mat00 * oldX2 + mat01 * y2 + mat02);
95 y2 = static_cast<ValueType> (mat10 * oldX2 + mat11 * y2 + mat12);
96 }
97
103 template <typename ValueType>
104 void transformPoints (ValueType& x1, ValueType& y1,
105 ValueType& x2, ValueType& y2,
106 ValueType& x3, ValueType& y3) const noexcept
107 {
108 auto oldX1 = x1, oldX2 = x2, oldX3 = x3;
109 x1 = static_cast<ValueType> (mat00 * oldX1 + mat01 * y1 + mat02);
110 y1 = static_cast<ValueType> (mat10 * oldX1 + mat11 * y1 + mat12);
111 x2 = static_cast<ValueType> (mat00 * oldX2 + mat01 * y2 + mat02);
112 y2 = static_cast<ValueType> (mat10 * oldX2 + mat11 * y2 + mat12);
113 x3 = static_cast<ValueType> (mat00 * oldX3 + mat01 * y3 + mat02);
114 y3 = static_cast<ValueType> (mat10 * oldX3 + mat11 * y3 + mat12);
115 }
116
117 //==============================================================================
119 AffineTransform translated (float deltaX,
120 float deltaY) const noexcept;
121
123 template <typename PointType>
124 AffineTransform translated (PointType delta) const noexcept
125 {
126 return translated ((float) delta.x, (float) delta.y);
127 }
128
130 static AffineTransform translation (float deltaX,
131 float deltaY) noexcept;
132
134 template <typename PointType>
135 static AffineTransform translation (PointType delta) noexcept
136 {
137 return translation ((float) delta.x, (float) delta.y);
138 }
139
141 AffineTransform withAbsoluteTranslation (float translationX,
142 float translationY) const noexcept;
143
149 AffineTransform rotated (float angleInRadians) const noexcept;
150
156 AffineTransform rotated (float angleInRadians,
157 float pivotX,
158 float pivotY) const noexcept;
159
161 static AffineTransform rotation (float angleInRadians) noexcept;
162
164 static AffineTransform rotation (float angleInRadians,
165 float pivotX,
166 float pivotY) noexcept;
167
171 AffineTransform scaled (float factorX,
172 float factorY) const noexcept;
173
177 AffineTransform scaled (float factor) const noexcept;
178
182 AffineTransform scaled (float factorX, float factorY,
183 float pivotX, float pivotY) const noexcept;
184
186 static AffineTransform scale (float factorX,
187 float factorY) noexcept;
188
190 static AffineTransform scale (float factor) noexcept;
191
193 static AffineTransform scale (float factorX, float factorY,
194 float pivotX, float pivotY) noexcept;
195
199 AffineTransform sheared (float shearX, float shearY) const noexcept;
200
202 static AffineTransform shear (float shearX, float shearY) noexcept;
203
207 static AffineTransform verticalFlip (float height) noexcept;
208
214 AffineTransform inverted() const noexcept;
215
222 static AffineTransform fromTargetPoints (float x00, float y00,
223 float x10, float y10,
224 float x01, float y01) noexcept;
225
227 static AffineTransform fromTargetPoints (float sourceX1, float sourceY1, float targetX1, float targetY1,
228 float sourceX2, float sourceY2, float targetX2, float targetY2,
229 float sourceX3, float sourceY3, float targetX3, float targetY3) noexcept;
230
232 template <typename PointType>
233 static AffineTransform fromTargetPoints (PointType source1, PointType target1,
234 PointType source2, PointType target2,
235 PointType source3, PointType target3) noexcept
236 {
237 return fromTargetPoints (source1.x, source1.y, target1.x, target1.y,
238 source2.x, source2.y, target2.x, target2.y,
239 source3.x, source3.y, target3.x, target3.y);
240 }
241
242 //==============================================================================
244 AffineTransform followedBy (const AffineTransform& other) const noexcept;
245
247 bool isIdentity() const noexcept;
248
250 bool isSingularity() const noexcept;
251
254 bool isOnlyTranslation() const noexcept;
255
259 float getTranslationX() const noexcept { return mat02; }
260
264 float getTranslationY() const noexcept { return mat12; }
265
267 float getDeterminant() const noexcept;
268
269 //==============================================================================
270 #ifndef DOXYGEN
284 [[deprecated ("This method produces incorrect values for transforms containing rotations. "
285 "See the method docs for a code example on how to calculate the correct scale factor.")]]
286 float getScaleFactor() const noexcept;
287
288 [[deprecated ("If you need an identity transform, just use AffineTransform() or {}.")]]
289 static const AffineTransform identity;
290 #endif
291
292 //==============================================================================
293 /* The transform matrix is:
294
295 (mat00 mat01 mat02)
296 (mat10 mat11 mat12)
297 ( 0 0 1 )
298 */
299 float mat00 { 1.0f }, mat01 { 0.0f }, mat02 { 0.0f };
300 float mat10 { 0.0f }, mat11 { 1.0f }, mat12 { 0.0f };
301};
302
303} // namespace juce
Represents a 2D affine-transformation matrix.
void transformPoint(ValueType &x, ValueType &y) const noexcept
Transforms a 2D coordinate using this matrix.
AffineTransform translated(PointType delta) const noexcept
Returns a new transform which is the same as this one followed by a translation.
float getTranslationY() const noexcept
If this transform is only a translation, this returns the X offset.
AffineTransform()=default
Creates an identity transform.
void transformPoints(ValueType &x1, ValueType &y1, ValueType &x2, ValueType &y2, ValueType &x3, ValueType &y3) const noexcept
Transforms three 2D coordinates using this matrix.
AffineTransform(const AffineTransform &)=default
Creates a copy of another transform.
void transformPoints(ValueType &x1, ValueType &y1, ValueType &x2, ValueType &y2) const noexcept
Transforms two 2D coordinates using this matrix.
static AffineTransform translation(PointType delta) noexcept
Returns a new transform which is a translation.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
y1