30 float m10,
float m11,
float m12) noexcept
31 : mat00 (m00), mat01 (m01), mat02 (m02),
32 mat10 (m10), mat11 (m11), mat12 (m12)
40 return std::tie (a.mat00, a.mat01, a.mat02, a.mat10, a.mat11, a.mat12);
43 return tie (*
this) == tie (other);
48 return ! operator== (other);
57const AffineTransform AffineTransform::identity (1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
62 return { other.mat00 * mat00 + other.mat01 * mat10,
63 other.mat00 * mat01 + other.mat01 * mat11,
64 other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
65 other.mat10 * mat00 + other.mat11 * mat10,
66 other.mat10 * mat01 + other.mat11 * mat11,
67 other.mat10 * mat02 + other.mat11 * mat12 + other.mat12 };
72 return { mat00, mat01, mat02 + dx,
73 mat10, mat11, mat12 + dy };
78 return { 1.0f, 0.0f, dx,
84 return { mat00, mat01, tx,
93 return { cosRad * mat00 - sinRad * mat10,
94 cosRad * mat01 - sinRad * mat11,
95 cosRad * mat02 - sinRad * mat12,
96 sinRad * mat00 + cosRad * mat10,
97 sinRad * mat01 + cosRad * mat11,
98 sinRad * mat02 + cosRad * mat12 };
106 return { cosRad, -sinRad, 0,
115 return { cosRad, -sinRad, -cosRad * pivotX + sinRad * pivotY + pivotX,
116 sinRad, cosRad, -sinRad * pivotX + -cosRad * pivotY + pivotY };
121 return followedBy (rotation (angle, pivotX, pivotY));
126 return { factorX * mat00, factorX * mat01, factorX * mat02,
127 factorY * mat10, factorY * mat11, factorY * mat12 };
132 return { factor * mat00, factor * mat01, factor * mat02,
133 factor * mat10, factor * mat11, factor * mat12 };
138 return { factorX, 0, 0, 0, factorY, 0 };
143 return { factor, 0, 0, 0, factor, 0 };
147 float pivotX,
float pivotY)
const noexcept
149 return { factorX * mat00, factorX * mat01, factorX * mat02 + pivotX * (1.0f - factorX),
150 factorY * mat10, factorY * mat11, factorY * mat12 + pivotY * (1.0f - factorY) };
154 float pivotX,
float pivotY)
noexcept
156 return { factorX, 0, pivotX * (1.0f - factorX),
157 0, factorY, pivotY * (1.0f - factorY) };
162 return { 1.0f, shearX, 0,
168 return { mat00 + shearX * mat10,
169 mat01 + shearX * mat11,
170 mat02 + shearX * mat12,
171 mat10 + shearY * mat00,
172 mat11 + shearY * mat01,
173 mat12 + shearY * mat02 };
178 return { 1.0f, 0.0f, 0.0f,
179 0.0f, -1.0f, height };
188 determinant = 1.0 / determinant;
190 auto dst00 = (
float) ( mat11 * determinant);
191 auto dst10 = (
float) (-mat10 * determinant);
192 auto dst01 = (
float) (-mat01 * determinant);
193 auto dst11 = (
float) ( mat00 * determinant);
195 return { dst00, dst01, -mat02 * dst00 - mat12 * dst01,
196 dst10, dst11, -mat02 * dst10 - mat12 * dst11 };
205 return exactlyEqual (mat00 * mat11 - mat10 * mat01, 0.0f);
209 float x10,
float y10,
210 float x01,
float y01)
noexcept
212 return { x10 - x00, x01 - x00, x00,
213 y10 - y00, y01 - y00, y00 };
217 float sx2,
float sy2,
float tx2,
float ty2,
218 float sx3,
float sy3,
float tx3,
float ty3)
noexcept
220 return fromTargetPoints (sx1, sy1, sx2, sy2, sx3, sy3)
222 .
followedBy (fromTargetPoints (tx1, ty1, tx2, ty2, tx3, ty3));
235 return (mat00 * mat11) - (mat01 * mat10);
238float AffineTransform::getScaleFactor() const noexcept
240 return (std::abs (mat00) + std::abs (mat11)) / 2.0f;
248class AffineTransformTests final :
public UnitTest
251 AffineTransformTests()
252 : UnitTest (
"AffineTransform", UnitTestCategories::maths)
255 void runTest()
override
257 beginTest (
"Determinant");
259 constexpr float scale1 = 1.5f, scale2 = 1.3f;
261 auto transform = AffineTransform::scale (scale1)
262 .followedBy (AffineTransform::rotation (degreesToRadians (72.0f)))
263 .followedBy (AffineTransform::translation (100.0f, 20.0f))
264 .followedBy (AffineTransform::scale (scale2));
266 expect (approximatelyEqual (
std::sqrt (std::abs (
transform.getDeterminant())), scale1 * scale2));
271static AffineTransformTests timeTests;
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
constexpr bool exactlyEqual(Type a, Type b)
Equivalent to operator==, but suppresses float-equality warnings.