34#include <gtest/gtest.h>
40TEST(AffineTest, Equality) {
42 Affine a(1, 2, 3, 4, 5, 6);
49TEST(AffineTest, Classification) {
70 EXPECT_FALSE(a.
flips());
93 EXPECT_FALSE(a.
flips());
116 EXPECT_TRUE(a.
flips());
139 EXPECT_FALSE(a.
flips());
162 EXPECT_TRUE(a.
flips());
185 EXPECT_FALSE(a.
flips());
208 EXPECT_FALSE(a.
flips());
232 EXPECT_FALSE(a.
flips());
236 Point rotation_center(1.23,4.56);
257 EXPECT_FALSE(a.
flips());
280 EXPECT_FALSE(a.
flips());
303 EXPECT_FALSE(a.
flips());
326 EXPECT_FALSE(a.
flips());
333 Affine a(0, 0, 0, 0, 0, 0);
352 EXPECT_FALSE(a.
flips());
356 Affine a(0, 1, 0, 1, 10, 10);
375 EXPECT_FALSE(a.
flips());
381 Affine i(1, 2, 1, -2, 10, 15);
382 Affine n(1, 2, 1, 2, 15, 30);
386 EXPECT_EQ(n.inverse(), e);
390TEST(AffineTest, CoordinateAccess) {
391 Affine a(0, 1, 2, 3, 4, 5);
392 for (
int i=0; i<6; ++i) {
395 for (
int i=0; i<6; ++i) {
398 for (
int i=0; i<6; ++i) {
399 EXPECT_EQ(a[i], 5*i);
404 Affine a1(1, 0, 1, 2, 1e-8, 1e-8);
405 Affine a2(1+1e-8, 0, 1, 2-1e-8, -1e-8, -1e-8);
406 EXPECT_TRUE(
are_near(a1, a2, 1e-7));
407 EXPECT_FALSE(
are_near(a1, a2, 1e-9));
410TEST(AffineTest, Multiplication) {
414 EXPECT_EQ(a1 * a2 * a3, t100);
415 EXPECT_EQ(a3 * a2 * a1, t1);
3x3 affine transformation matrix.
3x3 matrix representing an affine transformation.
bool isHShear(Coord eps=EPSILON) const
Check whether this matrix represents pure horizontal shearing.
bool isNonzeroScale(Coord eps=EPSILON) const
Check whether this matrix represents pure, nonzero scaling.
bool flips() const
Check whether this transformation flips objects.
bool preservesDistances(Coord eps=EPSILON) const
Check whether the transformation preserves distances between points.
bool preservesAngles(Coord eps=EPSILON) const
Check whether the transformation preserves angles between lines.
bool preservesArea(Coord eps=EPSILON) const
Check whether the transformation preserves areas of polygons.
bool isNonzeroNonpureRotation(Coord eps=EPSILON) const
Check whether this matrix represents a non-zero rotation about any point.
bool isScale(Coord eps=EPSILON) const
Check whether this matrix represents pure scaling.
bool isUniformScale(Coord eps=EPSILON) const
Check whether this matrix represents pure uniform scaling.
bool isNonzeroTranslation(Coord eps=EPSILON) const
Check whether this matrix represents a pure nonzero translation.
bool isNonzeroHShear(Coord eps=EPSILON) const
Check whether this matrix represents pure, nonzero horizontal shearing.
bool isVShear(Coord eps=EPSILON) const
Check whether this matrix represents pure vertical shearing.
bool isSingular(Coord eps=EPSILON) const
Check whether this matrix is singular.
bool isZoom(Coord eps=EPSILON) const
Check whether this matrix represents zooming.
bool isIdentity(Coord eps=EPSILON) const
Check whether this matrix is an identity matrix.
bool isNonzeroUniformScale(Coord eps=EPSILON) const
Check whether this matrix represents pure, nonzero uniform scaling.
Point rotationCenter() const
For a (possibly non-pure) non-zero-rotation matrix, calculate the rotation center.
bool isNonzeroVShear(Coord eps=EPSILON) const
Check whether this matrix represents pure, nonzero vertical shearing.
bool isTranslation(Coord eps=EPSILON) const
Check whether this matrix represents a pure translation.
Affine inverse() const
Compute the inverse matrix.
Affine withoutTranslation() const
bool isRotation(Coord eps=EPSILON) const
Check whether this matrix represents a pure rotation.
bool isNonzeroRotation(Coord eps=EPSILON) const
Check whether this matrix represents a pure, nonzero rotation.
Two-dimensional point that doubles as a vector.
Rotation around the origin.
Combination of a translation and uniform scale.
Various utility functions.
Affine identity()
Create an identity matrix.
TEST(AffineTest, Equality)
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)