Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fc87b5c

Browse files
authored
[Impeller] Add missing stream ops (#37034)
1 parent 701c6e6 commit fc87b5c

File tree

2 files changed

+90
-14
lines changed

2 files changed

+90
-14
lines changed

impeller/geometry/geometry_unittests.cc

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,32 +1616,94 @@ TEST(GeometryTest, VerticesConstructorAndGetters) {
16161616
}
16171617

16181618
TEST(GeometryTest, MatrixPrinting) {
1619-
std::stringstream stream;
1620-
1621-
Matrix m;
1622-
1623-
stream << m;
1624-
1625-
ASSERT_EQ(stream.str(), R"((
1619+
{
1620+
std::stringstream stream;
1621+
Matrix m;
1622+
stream << m;
1623+
ASSERT_EQ(stream.str(), R"((
16261624
1.000000, 0.000000, 0.000000, 0.000000,
16271625
0.000000, 1.000000, 0.000000, 0.000000,
16281626
0.000000, 0.000000, 1.000000, 0.000000,
16291627
0.000000, 0.000000, 0.000000, 1.000000,
16301628
))");
1629+
}
16311630

1632-
stream.str("");
1633-
stream.clear();
1634-
1635-
m = Matrix::MakeTranslation(Vector3(10, 20, 30));
1636-
1637-
stream << m;
1631+
{
1632+
std::stringstream stream;
1633+
Matrix m = Matrix::MakeTranslation(Vector3(10, 20, 30));
1634+
stream << m;
16381635

1639-
ASSERT_EQ(stream.str(), R"((
1636+
ASSERT_EQ(stream.str(), R"((
16401637
1.000000, 0.000000, 0.000000, 10.000000,
16411638
0.000000, 1.000000, 0.000000, 20.000000,
16421639
0.000000, 0.000000, 1.000000, 30.000000,
16431640
0.000000, 0.000000, 0.000000, 1.000000,
16441641
))");
1642+
}
1643+
}
1644+
1645+
TEST(GeometryTest, PointPrinting) {
1646+
{
1647+
std::stringstream stream;
1648+
Point m;
1649+
stream << m;
1650+
ASSERT_EQ(stream.str(), "(0, 0)");
1651+
}
1652+
1653+
{
1654+
std::stringstream stream;
1655+
Point m(13, 37);
1656+
stream << m;
1657+
ASSERT_EQ(stream.str(), "(13, 37)");
1658+
}
1659+
}
1660+
1661+
TEST(GeometryTest, Vector3Printing) {
1662+
{
1663+
std::stringstream stream;
1664+
Vector3 m;
1665+
stream << m;
1666+
ASSERT_EQ(stream.str(), "(0, 0, 0)");
1667+
}
1668+
1669+
{
1670+
std::stringstream stream;
1671+
Vector3 m(1, 2, 3);
1672+
stream << m;
1673+
ASSERT_EQ(stream.str(), "(1, 2, 3)");
1674+
}
1675+
}
1676+
1677+
TEST(GeometryTest, Vector4Printing) {
1678+
{
1679+
std::stringstream stream;
1680+
Vector4 m;
1681+
stream << m;
1682+
ASSERT_EQ(stream.str(), "(0, 0, 0, 1)");
1683+
}
1684+
1685+
{
1686+
std::stringstream stream;
1687+
Vector4 m(1, 2, 3, 4);
1688+
stream << m;
1689+
ASSERT_EQ(stream.str(), "(1, 2, 3, 4)");
1690+
}
1691+
}
1692+
1693+
TEST(GeometryTest, ColorPrinting) {
1694+
{
1695+
std::stringstream stream;
1696+
Color m;
1697+
stream << m;
1698+
ASSERT_EQ(stream.str(), "(0, 0, 0, 0)");
1699+
}
1700+
1701+
{
1702+
std::stringstream stream;
1703+
Color m(1, 2, 3, 4);
1704+
stream << m;
1705+
ASSERT_EQ(stream.str(), "(1, 2, 3, 4)");
1706+
}
16451707
}
16461708

16471709
TEST(GeometryTest, Gradient) {

impeller/geometry/vector.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,17 @@ static_assert(sizeof(Vector3) == 3 * sizeof(Scalar));
247247
static_assert(sizeof(Vector4) == 4 * sizeof(Scalar));
248248

249249
} // namespace impeller
250+
251+
namespace std {
252+
253+
inline std::ostream& operator<<(std::ostream& out, const impeller::Vector3& p) {
254+
out << "(" << p.x << ", " << p.y << ", " << p.z << ")";
255+
return out;
256+
}
257+
258+
inline std::ostream& operator<<(std::ostream& out, const impeller::Vector4& p) {
259+
out << "(" << p.x << ", " << p.y << ", " << p.z << ", " << p.w << ")";
260+
return out;
261+
}
262+
263+
} // namespace std

0 commit comments

Comments
 (0)