5#include "gtest/gtest.h"
13#include "flutter/fml/build_config.h"
14#include "flutter/testing/testing.h"
37 1.0f, 1.0f + std::numeric_limits<float>::epsilon() * 4));
40TEST(GeometryTest, MakeColumn) {
46 auto expect =
Matrix{1, 2, 3, 4,
51 ASSERT_TRUE(
matrix == expect);
54TEST(GeometryTest, MakeRow) {
60 auto expect =
Matrix{1, 5, 9, 13,
65 ASSERT_TRUE(
matrix == expect);
68TEST(GeometryTest, RotationMatrix) {
79TEST(GeometryTest, InvertMultMatrix) {
82 auto invert = rotation.Invert();
94 auto expect =
Matrix{0.5, 0, 0, 0,
102TEST(GeometryTest, MatrixBasis) {
107 auto basis =
matrix.Basis();
108 auto expect =
Matrix{1, 2, 3, 0,
115TEST(GeometryTest, MutliplicationMatrix) {
117 auto invert = rotation.Invert();
121TEST(GeometryTest, DeterminantTest) {
122 auto matrix =
Matrix{3, 4, 14, 155, 2, 1, 3, 4, 2, 3, 2, 1, 1, 2, 4, 2};
123 ASSERT_EQ(
matrix.GetDeterminant(), -1889);
126TEST(GeometryTest, InvertMatrix) {
127 auto inverted =
Matrix{10, -9, -12, 8,
134 438.0 / 85123.0, 1751.0 / 85123.0, -7783.0 / 85123.0, 4672.0 / 85123.0,
135 393.0 / 85123.0, -178.0 / 85123.0, -570.0 / 85123.0, 4192 / 85123.0,
136 -5230.0 / 85123.0, 2802.0 / 85123.0, -3461.0 / 85123.0, 962.0 / 85123.0,
137 2690.0 / 85123.0, 1814.0 / 85123.0, 3896.0 / 85123.0, 319.0 / 85123.0};
142TEST(GeometryTest, TestDecomposition) {
145 auto result = rotated.Decompose();
147 ASSERT_TRUE(
result.has_value());
155TEST(GeometryTest, TestDecomposition2) {
160 auto result = (translated * rotated * scaled).Decompose();
162 ASSERT_TRUE(
result.has_value());
174 ASSERT_FLOAT_EQ(res.
scale.
x, 2);
175 ASSERT_FLOAT_EQ(res.
scale.
y, 3);
176 ASSERT_FLOAT_EQ(res.
scale.
z, 1);
179TEST(GeometryTest, TestRecomposition) {
185 auto result = rotated.Decompose();
187 ASSERT_TRUE(
result.has_value());
201TEST(GeometryTest, TestRecomposition2) {
208 ASSERT_TRUE(
result.has_value());
213TEST(GeometryTest, MatrixVectorMultiplication) {
218 auto vector =
Vector4(10, 20, 30, 2);
221 auto expected =
Vector4(160, 220, 260, 2);
229 auto vector =
Vector3(10, 20, 30);
232 auto expected =
Vector3(60, 120, 160);
240 auto vector =
Point(10, 20);
243 auto expected =
Point(60, 120);
250 auto vector =
Vector3(3, 3, -3);
253 auto expected =
Vector3(-1, -1, 1.3468);
260 auto point =
Point(3, 3);
263 auto expected =
Point(-1, -1);
270 auto point =
Point(3, 3);
273 auto expected =
Point(0, 0);
278TEST(GeometryTest, MatrixMakeRotationFromQuaternion) {
298TEST(GeometryTest, MatrixTransformDirection) {
303 auto vector =
Vector4(10, 20, 30, 2);
306 auto expected =
Vector4(-40, 20, 60, 2);
314 auto vector =
Vector3(10, 20, 30);
317 auto expected =
Vector3(-40, 20, 60);
325 auto vector =
Point(10, 20);
328 auto expected =
Point(-40, 20);
333TEST(GeometryTest, MatrixGetMaxBasisLength) {
336 ASSERT_EQ(
m.GetMaxBasisLength(), 3);
339 ASSERT_EQ(
m.GetMaxBasisLength(), 5);
344 ASSERT_EQ(
m.GetMaxBasisLength(), 4);
348TEST(GeometryTest, MatrixGetMaxBasisLengthXY) {
351 ASSERT_EQ(
m.GetMaxBasisLengthXY(), 3);
354 ASSERT_EQ(
m.GetMaxBasisLengthXY(), 5);
359 ASSERT_EQ(
m.GetMaxBasisLengthXY(), 4);
365 1.0f, 0.0f, 0.0f, 0.0f,
366 0.0f, 1.0f, 0.0f, 0.0f,
367 4.0f, 0.0f, 1.0f, 0.0f,
368 0.0f, 0.0f, 0.0f, 1.0f
371 ASSERT_EQ(
m.GetMaxBasisLengthXY(), 1.0f);
375TEST(GeometryTest, MatrixMakeOrthographic) {
399TEST(GeometryTest, MatrixMakePerspective) {
423TEST(GeometryTest, MatrixGetBasisVectors) {
447TEST(GeometryTest, MatrixGetDirectionScale) {
451 ASSERT_FLOAT_EQ(
result, 1);
459 ASSERT_FLOAT_EQ(
result, 1);
466 ASSERT_FLOAT_EQ(
result, 8);
470TEST(GeometryTest, MatrixTranslationScaleOnly) {
473 bool result =
m.IsTranslationScaleOnly();
479 bool result =
m.IsTranslationScaleOnly();
485 bool result =
m.IsTranslationScaleOnly();
491 bool result =
m.IsTranslationScaleOnly();
496TEST(GeometryTest, MatrixLookAt) {
542TEST(GeometryTest, QuaternionLerp) {
546 auto q3 = q1.Slerp(q2, 0.5);
553TEST(GeometryTest, QuaternionVectorMultiply) {
595TEST(GeometryTest, CanGenerateMipCounts) {
596 ASSERT_EQ((
Size{128, 128}.MipCount()), 7u);
597 ASSERT_EQ((
Size{128, 256}.MipCount()), 8u);
598 ASSERT_EQ((
Size{128, 130}.MipCount()), 8u);
599 ASSERT_EQ((
Size{128, 257}.MipCount()), 9u);
600 ASSERT_EQ((
Size{257, 128}.MipCount()), 9u);
601 ASSERT_EQ((
Size{128, 0}.MipCount()), 1u);
602 ASSERT_EQ((
Size{128, -25}.MipCount()), 1u);
603 ASSERT_EQ((
Size{-128, 25}.MipCount()), 1u);
604 ASSERT_EQ((
Size{1, 1}.MipCount()), 1u);
605 ASSERT_EQ((
Size{0, 0}.MipCount()), 1u);
608TEST(GeometryTest, CanConvertTTypesExplicitly) {
619 ASSERT_EQ(s2.
width, 1u);
631TEST(GeometryTest, CanPerformAlgebraicPointOps) {
661TEST(GeometryTest, CanPerformAlgebraicPointOpsWithArithmeticTypes) {
693TEST(GeometryTest, PointIntegerCoercesToFloat) {
698 ASSERT_FLOAT_EQ(p2.
x, 2u);
699 ASSERT_FLOAT_EQ(p2.
y, 4u);
705 ASSERT_FLOAT_EQ(p2.
x, 2u);
706 ASSERT_FLOAT_EQ(p2.
y, 4u);
712 ASSERT_FLOAT_EQ(p2.
x, 2u);
713 ASSERT_FLOAT_EQ(p2.
y, 6u);
719 ASSERT_FLOAT_EQ(p2.
x, 1u);
720 ASSERT_FLOAT_EQ(p2.
y, 2u);
727 ASSERT_FLOAT_EQ(p2.
x, 2u);
728 ASSERT_FLOAT_EQ(p2.
y, 4u);
734 ASSERT_FLOAT_EQ(p2.
x, 2u);
735 ASSERT_FLOAT_EQ(p2.
y, 4u);
741 ASSERT_FLOAT_EQ(p2.
x, 2u);
742 ASSERT_FLOAT_EQ(p2.
y, 6u);
748 ASSERT_FLOAT_EQ(p2.
x, 1u);
749 ASSERT_FLOAT_EQ(p2.
y, 2u);
753TEST(GeometryTest, SizeCoercesToPoint) {
813TEST(GeometryTest, CanUsePointAssignmentOperators) {
888TEST(GeometryTest, PointDotProduct) {
892 ASSERT_FLOAT_EQ(
s, -1);
898 ASSERT_FLOAT_EQ(
s, 0);
904 ASSERT_FLOAT_EQ(
s, -5);
908TEST(GeometryTest, PointCrossProduct) {
912 ASSERT_FLOAT_EQ(
s, 0);
918 ASSERT_FLOAT_EQ(
s, -1);
924 ASSERT_FLOAT_EQ(
s, -10);
928TEST(GeometryTest, PointReflect) {
932 auto reflected =
a.Reflect(axis);
933 auto expected =
Point(2, -3);
940 auto reflected =
a.Reflect(axis);
941 auto expected =
Point(0, -1);
948 auto reflected =
a.Reflect(axis);
955 auto a_abs =
a.Abs();
956 auto expected =
Point(1, 2);
960TEST(GeometryTest, PointRotate) {
964 auto expected =
Point(0, 1);
971 auto expected =
Point(0, -1);
978 auto expected =
Point(-1, 0);
985 auto expected =
Point(0, -1);
990TEST(GeometryTest, PointAngleTo) {
1022 Point expected(0, 2);
1043 Point expected(1, 10);
1057 Vector4 expected(1, 10, 3, 4);
1064 Point expected(1, 2);
1085 Point expected(2, 3);
1106 Point expected(2, 2);
1127 Point expected(4, 8);
1141 Vector4 expected(4, 8, 12, 16);
1145TEST(GeometryTest, SeparatedVector2NormalizesWithConstructor) {
1151TEST(GeometryTest, SeparatedVector2GetVector) {
1156TEST(GeometryTest, SeparatedVector2GetAlignment) {
1179TEST(GeometryTest, SeparatedVector2AngleTo) {
1195TEST(GeometryTest, CanUseVector3AssignmentOperators) {
1217 ASSERT_EQ(
p.z, 12u);
1245TEST(GeometryTest, CanPerformAlgebraicVector3Ops) {
1249 ASSERT_EQ(p2.
x, 2u);
1250 ASSERT_EQ(p2.
y, 4u);
1251 ASSERT_EQ(p2.
z, 6u);
1257 ASSERT_EQ(p2.
x, 2u);
1258 ASSERT_EQ(p2.
y, 4u);
1259 ASSERT_EQ(p2.
z, 6u);
1265 ASSERT_EQ(p2.
x, 2u);
1266 ASSERT_EQ(p2.
y, 6u);
1267 ASSERT_EQ(p2.
z, 12u);
1273 ASSERT_EQ(p2.
x, 1u);
1274 ASSERT_EQ(p2.
y, 2u);
1275 ASSERT_EQ(p2.
z, 3u);
1279TEST(GeometryTest, CanPerformAlgebraicVector3OpsWithArithmeticTypes) {
1292 ASSERT_EQ(p2.
x, -1);
1327 ASSERT_EQ(p2.
z, -1);
1347TEST(GeometryTest, ColorPremultiply) {
1349 Color a(1.0, 0.5, 0.2, 0.5);
1350 Color premultiplied =
a.Premultiply();
1356 Color a(0.5, 0.25, 0.1, 0.5);
1357 Color unpremultiplied =
a.Unpremultiply();
1363 Color a(0.5, 0.25, 0.1, 0.0);
1364 Color unpremultiplied =
a.Unpremultiply();
1372 Color a(1.0, 0.5, 0.2, 0.5);
1373 std::array<uint8_t, 4> expected = {255, 128, 51, 128};
1378 Color a(0.0, 0.0, 0.0, 0.0);
1379 std::array<uint8_t, 4> expected = {0, 0, 0, 0};
1384 Color a(1.0, 1.0, 1.0, 1.0);
1385 std::array<uint8_t, 4> expected = {255, 255, 255, 255};
1392 Color a(0.0, 0.0, 0.0, 0.0);
1393 Color b(1.0, 1.0, 1.0, 1.0);
1402 Color a(0.2, 0.4, 1.0, 0.5);
1403 Color b(0.4, 1.0, 0.2, 0.3);
1432TEST(GeometryTest, ColorMakeRGBA8) {
1447 Color b(0.247059, 0.498039, 0.74902, 0.498039);
1452TEST(GeometryTest, ColorApplyColorMatrix) {
1461 auto expected =
Color(1, 1, 1, 1);
1473 auto expected =
Color(0.11, 0.22, 0.33, 0.44);
1478TEST(GeometryTest, ColorLinearToSRGB) {
1481 auto expected =
Color(1, 1, 1, 1);
1487 auto expected =
Color(0, 0, 0, 0);
1492 auto result =
Color(0.2, 0.4, 0.6, 0.8).LinearToSRGB();
1493 auto expected =
Color(0.484529, 0.665185, 0.797738, 0.8);
1498TEST(GeometryTest, ColorSRGBToLinear) {
1501 auto expected =
Color(1, 1, 1, 1);
1507 auto expected =
Color(0, 0, 0, 0);
1512 auto result =
Color(0.2, 0.4, 0.6, 0.8).SRGBToLinear();
1513 auto expected =
Color(0.0331048, 0.132868, 0.318547, 0.8);
1525 static const std::map<BlendMode, Color>
1655#define _BLEND_MODE_RESULT_CHECK(blend_mode) \
1656 expected = ColorBlendTestData::kExpectedResults[source_i] \
1657 .find(BlendMode::k##blend_mode) \
1659 EXPECT_COLOR_NEAR(dst.Blend(src, BlendMode::k##blend_mode), expected);
1661TEST(GeometryTest, ColorBlendReturnsExpectedResults) {
1663 for (
size_t source_i = 0;
1673#define _BLEND_MODE_NAME_CHECK(blend_mode) \
1674 case BlendMode::k##blend_mode: \
1675 ASSERT_STREQ(result, #blend_mode); \
1679 using BlendT = std::underlying_type_t<BlendMode>;
1687TEST(GeometryTest, CanConvertBetweenDegressAndRadians) {
1695TEST(GeometryTest, MatrixPrinting) {
1697 std::stringstream
stream;
1700 ASSERT_EQ(
stream.str(), R
"((
1701 1.000000, 0.000000, 0.000000, 0.000000,
1702 0.000000, 1.000000, 0.000000, 0.000000,
1703 0.000000, 0.000000, 1.000000, 0.000000,
1704 0.000000, 0.000000, 0.000000, 1.000000,
1709 std::stringstream stream;
1713 ASSERT_EQ(stream.str(), R"((
1714 1.000000, 0.000000, 0.000000, 10.000000,
1715 0.000000, 1.000000, 0.000000, 20.000000,
1716 0.000000, 0.000000, 1.000000, 30.000000,
1717 0.000000, 0.000000, 0.000000, 1.000000,
1724 std::stringstream stream;
1727 ASSERT_EQ(stream.str(), "(0, 0)");
1731 std::stringstream
stream;
1734 ASSERT_EQ(
stream.str(),
"(13, 37)");
1738TEST(GeometryTest, Vector3Printing) {
1740 std::stringstream
stream;
1743 ASSERT_EQ(
stream.str(),
"(0, 0, 0)");
1747 std::stringstream
stream;
1750 ASSERT_EQ(
stream.str(),
"(1, 2, 3)");
1754TEST(GeometryTest, Vector4Printing) {
1756 std::stringstream
stream;
1759 ASSERT_EQ(
stream.str(),
"(0, 0, 0, 1)");
1763 std::stringstream
stream;
1766 ASSERT_EQ(
stream.str(),
"(1, 2, 3, 4)");
1772 std::stringstream
stream;
1775 ASSERT_EQ(
stream.str(),
"(0, 0, 0, 0)");
1779 std::stringstream
stream;
1782 ASSERT_EQ(
stream.str(),
"(1, 2, 3, 4)");
1797 std::vector<Scalar> stops = {0.0, 1.0};
1802 ASSERT_EQ(gradient.texture_size, 2u);
1809 std::vector<Scalar> stops = {0.0, 0.25, 0.25, 1.0};
1812 ASSERT_EQ(gradient.texture_size, 5u);
1820 std::vector<Scalar> stops = {0.0, 0.33, 0.66, 1.0};
1825 ASSERT_EQ(gradient.texture_size, 4u);
1831 std::vector<Scalar> stops = {0.0, 0.25, 1.0};
1835 std::vector<Color> lerped_colors = {
1843 ASSERT_EQ(gradient.texture_size, 5u);
1848 std::vector<Color>
colors = {};
1849 std::vector<Scalar> stops = {};
1850 for (
auto i = 0u;
i < 1025;
i++) {
1852 stops.push_back(
i / 1025.0);
1857 ASSERT_EQ(gradient.texture_size, 1024u);
1858 ASSERT_EQ(gradient.color_bytes.size(), 1024u * 4);
1862TEST(GeometryTest, HalfConversions) {
1863#if defined(FML_OS_MACOSX) || defined(FML_OS_IOS) || \
1864 defined(FML_OS_IOS_SIMULATOR)
1888 ASSERT_EQ(
Half(0.5f),
Half(0.5f16));
1889 ASSERT_EQ(
Half(0.5),
Half(0.5f16));
1892 GTEST_SKIP() <<
"Half-precision floats (IEEE 754) are not portable and "
1893 "only used on Apple platforms.";
#define IMPELLER_FOR_EACH_BLEND_MODE(V)
#define ASSERT_VECTOR4_NEAR(a, b)
#define ASSERT_MATRIX_NEAR(a, b)
#define ASSERT_QUATERNION_NEAR(a, b)
#define ASSERT_COLOR_NEAR(a, b)
#define ASSERT_POINT_NEAR(a, b)
#define ASSERT_ARRAY_4_NEAR(a, b)
#define ASSERT_COLOR_BUFFER_NEAR(a, b)
#define ASSERT_VECTOR3_NEAR(a, b)
#define _BLEND_MODE_RESULT_CHECK(blend_mode)
#define _BLEND_MODE_NAME_CHECK(blend_mode)
unsigned useCenter Optional< SkMatrix > matrix
PODArray< SkColor > colors
SK_API sk_sp< SkShader > Color(SkColor)
static void Normalize(char *s)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
TEST(AiksCanvasTest, EmptyCullRect)
constexpr float kEhCloseEnough
constexpr InternalHalf ScalarToHalf(Scalar f)
Convert a scalar to a half precision float.
const char * BlendModeToString(BlendMode blend_mode)
GradientData CreateGradientBuffer(const std::vector< Color > &colors, const std::vector< Scalar > &stops)
Populate a vector with the interpolated color bytes for the linear gradient described by colors and s...
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
constexpr float k1OverSqrt2
SK_API sk_sp< PrecompileColorFilter > Matrix()
static constexpr uint32_t ToIColor(Color color)
Convert this color to a 32-bit representation.
static constexpr Color LimeGreen()
static constexpr Color BlackTransparent()
Color LinearToSRGB() const
Convert the color from linear space to sRGB space.
static constexpr Color Black()
static constexpr Color CornflowerBlue()
static constexpr Color White()
constexpr Color WithAlpha(Scalar new_alpha) const
Color ApplyColorMatrix(const ColorMatrix &color_matrix) const
A color filter that transforms colors through a 4x5 color matrix.
static constexpr Color Red()
static constexpr Color MakeRGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
static constexpr Color Lerp(Color a, Color b, Scalar t)
Return a color that is linearly interpolated between colors a and b, according to the value of t.
static constexpr Color Yellow()
Color SRGBToLinear() const
Convert the color from sRGB space to linear space.
static constexpr Color Blue()
static constexpr Color Green()
A storage only class for half precision floating point vector 2.
A storage only class for half precision floating point vector 3.
A storage only class for half precision floating point vector 4.
A storage only class for half precision floating point.
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeOrthographic(TSize< T > size)
static constexpr Matrix MakeTranslation(const Vector3 &t)
static constexpr Matrix MakePerspective(Radians fov_y, Scalar aspect_ratio, Scalar z_near, Scalar z_far)
static constexpr Matrix MakeColumn(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
static Matrix MakeRotationY(Radians r)
static constexpr Matrix MakeLookAt(Vector3 position, Vector3 target, Vector3 up)
static constexpr Matrix MakeRow(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
static constexpr Matrix MakeSkew(Scalar sx, Scalar sy)
static Matrix MakeRotationZ(Radians r)
static constexpr Matrix MakeScale(const Vector3 &s)
static Matrix MakeRotation(Quaternion q)
static Matrix MakeRotationX(Radians r)
A Vector2, broken down as a separate magnitude and direction. Assumes that the direction given is nor...
Radians AngleTo(const SeparatedVector2 &other) const
Returns the scalar angle between the two rays.
Scalar GetAlignment(const SeparatedVector2 &other) const
Vector2 direction
The normalized direction of the vector.
Vector2 GetVector() const
Returns the vector representation of the vector.
Scalar magnitude
The magnitude of the vector.
constexpr TPoint Normalize() const
static constexpr Color kDestinationColor
static const std::map< BlendMode, Color > kExpectedResults[sizeof(kSourceColors)]
static constexpr Color kSourceColors[]