5 #include "gtest/gtest.h"
10 #include <type_traits>
12 #include "flutter/fml/build_config.h"
13 #include "flutter/testing/testing.h"
38 1.0f, 1.0f + std::numeric_limits<float>::epsilon() * 4));
41 TEST(GeometryTest, MakeColumn) {
47 auto expect =
Matrix{1, 2, 3, 4,
52 ASSERT_TRUE(matrix == expect);
55 TEST(GeometryTest, MakeRow) {
61 auto expect =
Matrix{1, 5, 9, 13,
66 ASSERT_TRUE(matrix == expect);
69 TEST(GeometryTest, RotationMatrix) {
71 auto expect =
Matrix{0.707, 0.707, 0, 0,
78 TEST(GeometryTest, InvertMultMatrix) {
81 auto invert = rotation.
Invert();
82 auto expect =
Matrix{0.707, -0.707, 0, 0,
90 auto invert = scale.
Invert();
91 auto expect =
Matrix{0.5, 0, 0, 0,
99 TEST(GeometryTest, MatrixBasis) {
100 auto matrix =
Matrix{1, 2, 3, 4,
104 auto basis = matrix.
Basis();
105 auto expect =
Matrix{1, 2, 3, 0,
112 TEST(GeometryTest, MutliplicationMatrix) {
114 auto invert = rotation.
Invert();
118 TEST(GeometryTest, DeterminantTest) {
119 auto matrix =
Matrix{3, 4, 14, 155, 2, 1, 3, 4, 2, 3, 2, 1, 1, 2, 4, 2};
120 ASSERT_EQ(matrix.GetDeterminant(), -1889);
123 TEST(GeometryTest, InvertMatrix) {
124 auto inverted =
Matrix{10, -9, -12, 8,
131 438.0 / 85123.0, 1751.0 / 85123.0, -7783.0 / 85123.0, 4672.0 / 85123.0,
132 393.0 / 85123.0, -178.0 / 85123.0, -570.0 / 85123.0, 4192 / 85123.0,
133 -5230.0 / 85123.0, 2802.0 / 85123.0, -3461.0 / 85123.0, 962.0 / 85123.0,
134 2690.0 / 85123.0, 1814.0 / 85123.0, 3896.0 / 85123.0, 319.0 / 85123.0};
139 TEST(GeometryTest, TestDecomposition) {
144 ASSERT_TRUE(result.has_value());
152 TEST(GeometryTest, TestDecomposition2) {
157 auto result = (translated * rotated * scaled).Decompose();
159 ASSERT_TRUE(result.has_value());
171 ASSERT_FLOAT_EQ(res.
scale.
x, 2);
172 ASSERT_FLOAT_EQ(res.
scale.
y, 3);
173 ASSERT_FLOAT_EQ(res.
scale.
z, 1);
176 TEST(GeometryTest, TestRecomposition) {
184 ASSERT_TRUE(result.has_value());
198 TEST(GeometryTest, TestRecomposition2) {
205 ASSERT_TRUE(result.has_value());
210 TEST(GeometryTest, MatrixVectorMultiplication) {
215 auto vector =
Vector4(10, 20, 30, 2);
217 Vector4 result = matrix * vector;
218 auto expected =
Vector4(160, 220, 260, 2);
226 auto vector =
Vector3(10, 20, 30);
228 Vector3 result = matrix * vector;
229 auto expected =
Vector3(60, 120, 160);
237 auto vector =
Point(10, 20);
239 Point result = matrix * vector;
240 auto expected =
Point(60, 120);
247 auto vector =
Vector3(3, 3, -3);
249 Vector3 result = matrix * vector;
250 auto expected =
Vector3(-1, -1, 1.3468);
257 auto point =
Point(3, 3);
259 Point result = matrix * point;
260 auto expected =
Point(-1, -1);
267 auto point =
Point(3, 3);
269 Point result = matrix * point;
270 auto expected =
Point(0, 0);
275 TEST(GeometryTest, MatrixMakeRotationFromQuaternion) {
295 TEST(GeometryTest, MatrixTransformDirection) {
300 auto vector =
Vector4(10, 20, 30, 2);
302 Vector4 result = matrix.TransformDirection(vector);
303 auto expected =
Vector4(-40, 20, 60, 2);
311 auto vector =
Vector3(10, 20, 30);
313 Vector3 result = matrix.TransformDirection(vector);
314 auto expected =
Vector3(-40, 20, 60);
322 auto vector =
Point(10, 20);
324 Point result = matrix.TransformDirection(vector);
325 auto expected =
Point(-40, 20);
330 TEST(GeometryTest, MatrixGetMaxBasisLength) {
333 ASSERT_EQ(m.GetMaxBasisLength(), 3);
336 ASSERT_EQ(m.GetMaxBasisLength(), 5);
341 ASSERT_EQ(m.GetMaxBasisLength(), 4);
345 TEST(GeometryTest, MatrixGetMaxBasisLengthXY) {
348 ASSERT_EQ(m.GetMaxBasisLengthXY(), 3);
351 ASSERT_EQ(m.GetMaxBasisLengthXY(), 5);
356 ASSERT_EQ(m.GetMaxBasisLengthXY(), 4);
360 TEST(GeometryTest, MatrixMakeOrthographic) {
384 TEST(GeometryTest, MatrixMakePerspective) {
408 TEST(GeometryTest, MatrixGetBasisVectors) {
432 TEST(GeometryTest, MatrixGetDirectionScale) {
436 ASSERT_FLOAT_EQ(result, 1);
444 ASSERT_FLOAT_EQ(result, 1);
451 ASSERT_FLOAT_EQ(result, 8);
455 TEST(GeometryTest, MatrixIsAligned) {
465 ASSERT_FALSE(result);
469 TEST(GeometryTest, MatrixTranslationScaleOnly) {
472 bool result = m.IsTranslationScaleOnly();
478 bool result = m.IsTranslationScaleOnly();
484 bool result = m.IsTranslationScaleOnly();
490 bool result = m.IsTranslationScaleOnly();
491 ASSERT_FALSE(result);
495 TEST(GeometryTest, MatrixLookAt) {
541 TEST(GeometryTest, QuaternionLerp) {
545 auto q3 = q1.Slerp(q2, 0.5);
552 TEST(GeometryTest, QuaternionVectorMultiply) {
594 TEST(GeometryTest, EmptyPath) {
596 ASSERT_EQ(path.GetComponentCount(), 1u);
599 path.GetContourComponentAtIndex(0, c);
603 ASSERT_TRUE(polyline.
points.empty());
604 ASSERT_TRUE(polyline.
contours.empty());
607 TEST(GeometryTest, SimplePath) {
610 auto path = builder.
AddLine({0, 0}, {100, 100})
611 .AddQuadraticCurve({100, 100}, {200, 200}, {300, 300})
612 .AddCubicCurve({300, 300}, {400, 400}, {500, 500}, {600, 600})
615 ASSERT_EQ(path.GetComponentCount(), 6u);
621 path.EnumerateComponents(
625 ASSERT_EQ(index, 1u);
626 ASSERT_EQ(linear.
p1, p1);
627 ASSERT_EQ(linear.
p2, p2);
633 ASSERT_EQ(index, 3u);
634 ASSERT_EQ(quad.p1, p1);
635 ASSERT_EQ(quad.cp, cp);
636 ASSERT_EQ(quad.p2, p2);
643 ASSERT_EQ(index, 5u);
644 ASSERT_EQ(cubic.p1, p1);
645 ASSERT_EQ(cubic.cp1, cp1);
646 ASSERT_EQ(cubic.cp2, cp2);
647 ASSERT_EQ(cubic.p2, p2);
653 ASSERT_EQ(contour.destination, p1);
654 }
else if (index == 2u) {
656 ASSERT_EQ(contour.destination, p1);
657 }
else if (index == 4u) {
659 ASSERT_EQ(contour.destination, p1);
663 ASSERT_FALSE(contour.is_closed);
667 TEST(GeometryTest, BoundingBoxCubic) {
670 builder.
AddCubicCurve({120, 160}, {25, 200}, {220, 260}, {220, 40})
672 auto box = path.GetBoundingBox();
673 Rect expected(93.9101, 40, 126.09, 158.862);
674 ASSERT_TRUE(box.has_value());
678 TEST(GeometryTest, BoundingBoxOfCompositePathIsCorrect) {
683 Rect expected(10, 10, 300, 300);
684 ASSERT_TRUE(actual.has_value());
688 TEST(GeometryTest, ExtremaOfCubicPathComponentIsCorrect) {
690 {-6.2857933, 204.356461},
691 {-4.53997231, 156.552902},
692 {17.0067291, 109.472488}};
694 ASSERT_EQ(points.size(),
static_cast<size_t>(3));
698 TEST(GeometryTest, PathGetBoundingBoxForCubicWithNoDerivativeRootsIsCorrect) {
705 ASSERT_TRUE(actual.has_value());
709 TEST(GeometryTest, CanGenerateMipCounts) {
722 TEST(GeometryTest, CanConvertTTypesExplicitly) {
733 ASSERT_EQ(s2.
width, 1u);
745 Rect r1(1.0, 2.0, 3.0, 4.0);
754 TEST(GeometryTest, CanPerformAlgebraicPointOps) {
784 TEST(GeometryTest, CanPerformAlgebraicPointOpsWithArithmeticTypes) {
816 TEST(GeometryTest, PointIntegerCoercesToFloat) {
821 ASSERT_FLOAT_EQ(p2.
x, 2u);
822 ASSERT_FLOAT_EQ(p2.
y, 4u);
828 ASSERT_FLOAT_EQ(p2.
x, 2u);
829 ASSERT_FLOAT_EQ(p2.
y, 4u);
835 ASSERT_FLOAT_EQ(p2.
x, 2u);
836 ASSERT_FLOAT_EQ(p2.
y, 6u);
842 ASSERT_FLOAT_EQ(p2.
x, 1u);
843 ASSERT_FLOAT_EQ(p2.
y, 2u);
850 ASSERT_FLOAT_EQ(p2.
x, 2u);
851 ASSERT_FLOAT_EQ(p2.
y, 4u);
857 ASSERT_FLOAT_EQ(p2.
x, 2u);
858 ASSERT_FLOAT_EQ(p2.
y, 4u);
864 ASSERT_FLOAT_EQ(p2.
x, 2u);
865 ASSERT_FLOAT_EQ(p2.
y, 6u);
871 ASSERT_FLOAT_EQ(p2.
x, 1u);
872 ASSERT_FLOAT_EQ(p2.
y, 2u);
876 TEST(GeometryTest, SizeCoercesToPoint) {
936 TEST(GeometryTest, CanUsePointAssignmentOperators) {
1011 TEST(GeometryTest, PointDotProduct) {
1015 ASSERT_FLOAT_EQ(s, -1);
1021 ASSERT_FLOAT_EQ(s, 0);
1027 ASSERT_FLOAT_EQ(s, -5);
1031 TEST(GeometryTest, PointCrossProduct) {
1035 ASSERT_FLOAT_EQ(s, 0);
1041 ASSERT_FLOAT_EQ(s, -1);
1047 ASSERT_FLOAT_EQ(s, -10);
1055 auto reflected = a.
Reflect(axis);
1056 auto expected =
Point(2, -3);
1063 auto reflected = a.
Reflect(axis);
1064 auto expected =
Point(0, -1);
1071 auto reflected = a.
Reflect(axis);
1078 auto a_abs = a.
Abs();
1079 auto expected =
Point(1, 2);
1105 Point b(0.01, 0.01);
1115 Point expected(0, 2);
1136 Point expected(1, 10);
1150 Vector4 expected(1, 10, 3, 4);
1157 Point expected(1, 2);
1169 Vector4 p(1.5, 2.3, 3.9, 4.0);
1178 Point expected(2, 3);
1190 Vector4 p(1.5, 2.3, 3.9, 4.0);
1199 Point expected(2, 2);
1211 Vector4 p(1.5, 2.3, 3.9, 4.0);
1220 Point expected(4, 8);
1234 Vector4 expected(4, 8, 12, 16);
1238 TEST(GeometryTest, CanUseVector3AssignmentOperators) {
1260 ASSERT_EQ(p.
z, 12u);
1288 TEST(GeometryTest, CanPerformAlgebraicVector3Ops) {
1292 ASSERT_EQ(p2.
x, 2u);
1293 ASSERT_EQ(p2.
y, 4u);
1294 ASSERT_EQ(p2.
z, 6u);
1300 ASSERT_EQ(p2.
x, 2u);
1301 ASSERT_EQ(p2.
y, 4u);
1302 ASSERT_EQ(p2.
z, 6u);
1308 ASSERT_EQ(p2.
x, 2u);
1309 ASSERT_EQ(p2.
y, 6u);
1310 ASSERT_EQ(p2.
z, 12u);
1316 ASSERT_EQ(p2.
x, 1u);
1317 ASSERT_EQ(p2.
y, 2u);
1318 ASSERT_EQ(p2.
z, 3u);
1322 TEST(GeometryTest, CanPerformAlgebraicVector3OpsWithArithmeticTypes) {
1335 ASSERT_EQ(p2.
x, -1);
1370 ASSERT_EQ(p2.
z, -1);
1390 TEST(GeometryTest, ColorPremultiply) {
1392 Color a(1.0, 0.5, 0.2, 0.5);
1399 Color a(0.5, 0.25, 0.1, 0.5);
1406 Color a(0.5, 0.25, 0.1, 0.0);
1413 TEST(GeometryTest, ColorR8G8B8A8) {
1415 Color a(1.0, 0.5, 0.2, 0.5);
1416 std::array<uint8_t, 4> expected = {255, 128, 51, 128};
1421 Color a(0.0, 0.0, 0.0, 0.0);
1422 std::array<uint8_t, 4> expected = {0, 0, 0, 0};
1427 Color a(1.0, 1.0, 1.0, 1.0);
1428 std::array<uint8_t, 4> expected = {255, 255, 255, 255};
1435 Color a(0.0, 0.0, 0.0, 0.0);
1436 Color b(1.0, 1.0, 1.0, 1.0);
1445 Color a(0.2, 0.4, 1.0, 0.5);
1446 Color b(0.4, 1.0, 0.2, 0.3);
1475 TEST(GeometryTest, ColorMakeRGBA8) {
1490 Color b(0.247059, 0.498039, 0.74902, 0.498039);
1495 TEST(GeometryTest, ColorApplyColorMatrix) {
1504 auto expected =
Color(1, 1, 1, 1);
1516 auto expected =
Color(0.11, 0.22, 0.33, 0.44);
1521 TEST(GeometryTest, ColorLinearToSRGB) {
1524 auto expected =
Color(1, 1, 1, 1);
1530 auto expected =
Color(0, 0, 0, 0);
1536 auto expected =
Color(0.484529, 0.665185, 0.797738, 0.8);
1541 TEST(GeometryTest, ColorSRGBToLinear) {
1544 auto expected =
Color(1, 1, 1, 1);
1550 auto expected =
Color(0, 0, 0, 0);
1556 auto expected =
Color(0.0331048, 0.132868, 0.318547, 0.8);
1561 #define _BLEND_MODE_NAME_CHECK(blend_mode) \
1562 case BlendMode::k##blend_mode: \
1563 ASSERT_STREQ(result, #blend_mode); \
1567 using BlendT = std::underlying_type_t<BlendMode>;
1575 TEST(GeometryTest, CanConvertBetweenDegressAndRadians) {
1602 ASSERT_EQ(r, expected);
1609 ASSERT_EQ(r, expected);
1615 Rect a(100, 100, 100, 100);
1617 auto u = a.
Union(b);
1618 auto expected =
Rect(0, 0, 200, 200);
1623 Rect a(100, 100, 100, 100);
1624 Rect b(10, 10, 0, 0);
1625 auto u = a.
Union(b);
1626 auto expected =
Rect(10, 10, 190, 190);
1631 Rect a(0, 0, 100, 100);
1632 Rect b(10, 10, 100, 100);
1633 auto u = a.
Union(b);
1634 auto expected =
Rect(0, 0, 110, 110);
1639 Rect a(0, 0, 100, 100);
1640 Rect b(100, 100, 100, 100);
1641 auto u = a.
Union(b);
1642 auto expected =
Rect(0, 0, 200, 200);
1647 TEST(GeometryTest, RectIntersection) {
1649 Rect a(100, 100, 100, 100);
1653 ASSERT_FALSE(u.has_value());
1657 Rect a(100, 100, 100, 100);
1658 Rect b(10, 10, 0, 0);
1660 ASSERT_FALSE(u.has_value());
1664 Rect a(0, 0, 100, 100);
1665 Rect b(10, 10, 100, 100);
1667 ASSERT_TRUE(u.has_value());
1668 auto expected =
Rect(10, 10, 90, 90);
1673 Rect a(0, 0, 100, 100);
1674 Rect b(100, 100, 100, 100);
1676 ASSERT_FALSE(u.has_value());
1681 Rect b(10, 10, 300, 300);
1696 TEST(GeometryTest, RectIntersectsWithRect) {
1698 Rect a(100, 100, 100, 100);
1704 Rect a(100, 100, 100, 100);
1705 Rect b(10, 10, 0, 0);
1710 Rect a(0, 0, 100, 100);
1711 Rect b(10, 10, 100, 100);
1716 Rect a(0, 0, 100, 100);
1717 Rect b(100, 100, 100, 100);
1723 Rect b(10, 10, 100, 100);
1737 Rect a(0, 0, 100, 100);
1738 Rect b(0, 0, 50, 50);
1740 ASSERT_TRUE(u.has_value());
1746 Rect a(0, 0, 100, 100);
1747 Rect b(-10, -10, 120, 120);
1749 ASSERT_FALSE(u.has_value());
1756 auto u = a.Cutout(b);
1758 ASSERT_TRUE(u.has_value());
1766 auto u = a.Cutout(b);
1768 ASSERT_TRUE(u.has_value());
1776 auto u = a.Cutout(b);
1778 ASSERT_TRUE(u.has_value());
1786 auto u = a.Cutout(b);
1788 ASSERT_TRUE(u.has_value());
1793 TEST(GeometryTest, RectContainsPoint) {
1796 Rect r(100, 100, 100, 100);
1802 Rect r(100, 100, 100, 100);
1807 Rect r(100, 100, 100, 100);
1812 Rect r(100, 100, 100, 100);
1824 TEST(GeometryTest, RectContainsRect) {
1826 Rect a(100, 100, 100, 100);
1830 Rect a(100, 100, 100, 100);
1835 Rect a(100, 100, 100, 100);
1836 Rect b(150, 150, 20, 20);
1840 Rect a(100, 100, 100, 100);
1841 Rect b(150, 150, 100, 100);
1845 Rect a(100, 100, 100, 100);
1846 Rect b(50, 50, 100, 100);
1850 Rect a(100, 100, 100, 100);
1851 Rect b(0, 0, 300, 300);
1856 Rect b(0, 0, 300, 300);
1861 TEST(GeometryTest, RectGetPoints) {
1863 Rect r(100, 200, 300, 400);
1874 ASSERT_EQ(points[0],
Point(-std::numeric_limits<float>::infinity(),
1875 -std::numeric_limits<float>::infinity()));
1876 ASSERT_EQ(points[1],
Point(std::numeric_limits<float>::infinity(),
1877 -std::numeric_limits<float>::infinity()));
1878 ASSERT_EQ(points[2],
Point(-std::numeric_limits<float>::infinity(),
1879 std::numeric_limits<float>::infinity()));
1880 ASSERT_EQ(points[3],
Point(std::numeric_limits<float>::infinity(),
1881 std::numeric_limits<float>::infinity()));
1892 TEST(GeometryTest, RectGetTransformedPoints) {
1893 Rect r(100, 200, 300, 400);
1901 TEST(GeometryTest, RectMakePointBounds) {
1903 std::vector<Point> points{{1, 5}, {4, -1}, {0, 6}};
1905 auto expected =
Rect(0, -1, 4, 7);
1909 std::vector<Point> points;
1911 ASSERT_FALSE(r.has_value());
1918 auto b = a.Expand(1);
1924 auto b = a.Expand(-1);
1931 auto b = a.Expand(1, 2, 3, 4);
1937 auto b = a.Expand(-1, -2, -3, -4);
1943 TEST(GeometryTest, RectGetPositive) {
1945 Rect r{100, 200, 300, 400};
1950 Rect r{100, 200, -100, -100};
1952 Rect expected(0, 100, 100, 100);
1960 auto actual = r.Scale(0);
1966 auto actual = r.Scale(-2);
1972 auto actual = r.Scale(
Point{0, 0});
1978 auto actual = r.Scale(
Size{-1, -2});
1984 TEST(GeometryTest, RectDirections) {
1987 ASSERT_EQ(r.GetLeft(), 1);
1988 ASSERT_EQ(r.GetTop(), 2);
1989 ASSERT_EQ(r.GetRight(), 3);
1990 ASSERT_EQ(r.GetBottom(), 4);
2001 auto actual = r.Project(r);
2013 TEST(GeometryTest, CubicPathComponentPolylineDoesNotIncludePointOne) {
2016 ASSERT_NE(polyline.front().x, 10);
2017 ASSERT_NE(polyline.front().y, 10);
2018 ASSERT_EQ(polyline.back().x, 40);
2019 ASSERT_EQ(polyline.back().y, 40);
2022 TEST(GeometryTest, PathCreatePolyLineDoesNotDuplicatePoints) {
2024 builder.
MoveTo({10, 10});
2025 builder.
LineTo({20, 20});
2026 builder.
LineTo({30, 30});
2027 builder.
MoveTo({40, 40});
2028 builder.
LineTo({50, 50});
2032 ASSERT_EQ(polyline.contours.size(), 2u);
2033 ASSERT_EQ(polyline.points.size(), 5u);
2034 ASSERT_EQ(polyline.points[0].x, 10);
2035 ASSERT_EQ(polyline.points[1].x, 20);
2036 ASSERT_EQ(polyline.points[2].x, 30);
2037 ASSERT_EQ(polyline.points[3].x, 40);
2038 ASSERT_EQ(polyline.points[4].x, 50);
2041 TEST(GeometryTest, PathBuilderSetsCorrectContourPropertiesForAddCommands) {
2089 .
AddCubicCurve({100, 100}, {100, 50}, {100, 150}, {200, 100})
2108 TEST(GeometryTest, PathCreatePolylineGeneratesCorrectContourData) {
2110 .
AddLine({100, 100}, {200, 100})
2116 .CreatePolyline(1.0f);
2117 ASSERT_EQ(polyline.
points.size(), 6u);
2118 ASSERT_EQ(polyline.
contours.size(), 2u);
2119 ASSERT_EQ(polyline.
contours[0].is_closed,
false);
2120 ASSERT_EQ(polyline.
contours[0].start_index, 0u);
2121 ASSERT_EQ(polyline.
contours[1].is_closed,
true);
2122 ASSERT_EQ(polyline.
contours[1].start_index, 2u);
2125 TEST(GeometryTest, PolylineGetContourPointBoundsReturnsCorrectRanges) {
2127 .
AddLine({100, 100}, {200, 100})
2133 .CreatePolyline(1.0f);
2134 size_t a1, a2, b1, b2;
2143 TEST(GeometryTest, PathAddRectPolylineHasCorrectContourData) {
2148 ASSERT_EQ(polyline.
contours.size(), 1u);
2149 ASSERT_TRUE(polyline.
contours[0].is_closed);
2150 ASSERT_EQ(polyline.
contours[0].start_index, 0u);
2151 ASSERT_EQ(polyline.
points.size(), 5u);
2159 TEST(GeometryTest, PathPolylineDuplicatesAreRemovedForSameContour) {
2172 .CreatePolyline(1.0f);
2173 ASSERT_EQ(polyline.
contours.size(), 2u);
2174 ASSERT_EQ(polyline.
contours[0].start_index, 0u);
2175 ASSERT_TRUE(polyline.
contours[0].is_closed);
2176 ASSERT_EQ(polyline.
contours[1].start_index, 4u);
2177 ASSERT_FALSE(polyline.
contours[1].is_closed);
2178 ASSERT_EQ(polyline.
points.size(), 7u);
2188 TEST(GeometryTest, MatrixPrinting) {
2190 std::stringstream stream;
2193 ASSERT_EQ(stream.str(), R
"((
2194 1.000000, 0.000000, 0.000000, 0.000000,
2195 0.000000, 1.000000, 0.000000, 0.000000,
2196 0.000000, 0.000000, 1.000000, 0.000000,
2197 0.000000, 0.000000, 0.000000, 1.000000,
2202 std::stringstream stream;
2206 ASSERT_EQ(stream.str(), R"((
2207 1.000000, 0.000000, 0.000000, 10.000000,
2208 0.000000, 1.000000, 0.000000, 20.000000,
2209 0.000000, 0.000000, 1.000000, 30.000000,
2210 0.000000, 0.000000, 0.000000, 1.000000,
2215 TEST(GeometryTest, PointPrinting) {
2217 std::stringstream stream;
2220 ASSERT_EQ(stream.str(), "(0, 0)");
2224 std::stringstream stream;
2227 ASSERT_EQ(stream.str(),
"(13, 37)");
2231 TEST(GeometryTest, Vector3Printing) {
2233 std::stringstream stream;
2236 ASSERT_EQ(stream.str(),
"(0, 0, 0)");
2240 std::stringstream stream;
2243 ASSERT_EQ(stream.str(),
"(1, 2, 3)");
2247 TEST(GeometryTest, Vector4Printing) {
2249 std::stringstream stream;
2252 ASSERT_EQ(stream.str(),
"(0, 0, 0, 1)");
2256 std::stringstream stream;
2259 ASSERT_EQ(stream.str(),
"(1, 2, 3, 4)");
2263 TEST(GeometryTest, ColorPrinting) {
2265 std::stringstream stream;
2268 ASSERT_EQ(stream.str(),
"(0, 0, 0, 0)");
2272 std::stringstream stream;
2273 Color m(1, 2, 3, 4);
2275 ASSERT_EQ(stream.str(),
"(1, 2, 3, 4)");
2290 std::vector<Scalar> stops = {0.0, 1.0};
2295 ASSERT_EQ(gradient.texture_size, 2u);
2302 std::vector<Scalar> stops = {0.0, 0.25, 0.25, 1.0};
2305 ASSERT_EQ(gradient.texture_size, 5u);
2313 std::vector<Scalar> stops = {0.0, 0.33, 0.66, 1.0};
2318 ASSERT_EQ(gradient.texture_size, 4u);
2324 std::vector<Scalar> stops = {0.0, 0.25, 1.0};
2328 std::vector<Color> lerped_colors = {
2336 ASSERT_EQ(gradient.texture_size, 5u);
2341 std::vector<Color> colors = {};
2342 std::vector<Scalar> stops = {};
2343 for (
auto i = 0u; i < 1025; i++) {
2345 stops.push_back(i / 1025.0);
2350 ASSERT_EQ(gradient.texture_size, 1024u);
2351 ASSERT_EQ(gradient.color_bytes.size(), 1024u * 4);
2355 TEST(GeometryTest, HalfConversions) {
2357 GTEST_SKIP() <<
"Half-precision floats (IEEE 754) are not portable and "
2358 "unavailable on Windows.";
2383 ASSERT_EQ(
Half(0.5f),
Half(0.5f16));
2384 ASSERT_EQ(
Half(0.5),
Half(0.5f16));
2386 #endif // FML_OS_WIN
2405 ASSERT_TRUE(path.GetContourComponentAtIndex(0, contour));
2406 ASSERT_TRUE(path.GetLinearComponentAtIndex(1, linear));
2407 ASSERT_TRUE(path.GetQuadraticComponentAtIndex(3, quad));
2408 ASSERT_TRUE(path.GetCubicComponentAtIndex(5, cubic));
2412 ASSERT_EQ(linear.
p1,
Point(1, 1));
2413 ASSERT_EQ(linear.
p2,
Point(11, 11));
2415 ASSERT_EQ(quad.
cp,
Point(16, 16));
2416 ASSERT_EQ(quad.
p1,
Point(11, 11));
2417 ASSERT_EQ(quad.
p2,
Point(21, 21));
2419 ASSERT_EQ(cubic.
cp1,
Point(26, 26));
2420 ASSERT_EQ(cubic.
cp2,
Point(-4, -4));
2421 ASSERT_EQ(cubic.
p1,
Point(21, 21));
2422 ASSERT_EQ(cubic.
p2,
Point(31, 31));
2425 TEST(GeometryTest, PathBuilderWillComputeBounds) {
2427 auto path_1 = builder.
AddLine({0, 0}, {1, 1}).TakePath();
2429 ASSERT_EQ(path_1.GetBoundingBox().value(),
Rect::MakeLTRB(0, 0, 1, 1));
2431 auto path_2 = builder.
AddLine({-1, -1}, {1, 1}).TakePath();
2434 ASSERT_EQ(path_2.GetBoundingBox().value(),
Rect::MakeLTRB(-1, -1, 1, 1));
2437 auto path_3 = builder.
AddLine({0, 0}, {1, 1})
2441 ASSERT_EQ(path_3.GetBoundingBox().value(),
Rect::MakeLTRB(0, 0, 100, 100));