Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 76 additions & 14 deletions impeller/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1616,32 +1616,94 @@ TEST(GeometryTest, VerticesConstructorAndGetters) {
}

TEST(GeometryTest, MatrixPrinting) {
std::stringstream stream;

Matrix m;

stream << m;

ASSERT_EQ(stream.str(), R"((
{
std::stringstream stream;
Matrix m;
stream << m;
ASSERT_EQ(stream.str(), R"((
1.000000, 0.000000, 0.000000, 0.000000,
0.000000, 1.000000, 0.000000, 0.000000,
0.000000, 0.000000, 1.000000, 0.000000,
0.000000, 0.000000, 0.000000, 1.000000,
))");
}

stream.str("");
stream.clear();

m = Matrix::MakeTranslation(Vector3(10, 20, 30));

stream << m;
{
std::stringstream stream;
Matrix m = Matrix::MakeTranslation(Vector3(10, 20, 30));
stream << m;

ASSERT_EQ(stream.str(), R"((
ASSERT_EQ(stream.str(), R"((
1.000000, 0.000000, 0.000000, 10.000000,
0.000000, 1.000000, 0.000000, 20.000000,
0.000000, 0.000000, 1.000000, 30.000000,
0.000000, 0.000000, 0.000000, 1.000000,
))");
}
}

TEST(GeometryTest, PointPrinting) {
{
std::stringstream stream;
Point m;
stream << m;
ASSERT_EQ(stream.str(), "(0, 0)");
}

{
std::stringstream stream;
Point m(13, 37);
stream << m;
ASSERT_EQ(stream.str(), "(13, 37)");
}
}

TEST(GeometryTest, Vector3Printing) {
{
std::stringstream stream;
Vector3 m;
stream << m;
ASSERT_EQ(stream.str(), "(0, 0, 0)");
}

{
std::stringstream stream;
Vector3 m(1, 2, 3);
stream << m;
ASSERT_EQ(stream.str(), "(1, 2, 3)");
}
}

TEST(GeometryTest, Vector4Printing) {
{
std::stringstream stream;
Vector4 m;
stream << m;
ASSERT_EQ(stream.str(), "(0, 0, 0, 1)");
}

{
std::stringstream stream;
Vector4 m(1, 2, 3, 4);
stream << m;
ASSERT_EQ(stream.str(), "(1, 2, 3, 4)");
}
}

TEST(GeometryTest, ColorPrinting) {
{
std::stringstream stream;
Color m;
stream << m;
ASSERT_EQ(stream.str(), "(0, 0, 0, 0)");
}

{
std::stringstream stream;
Color m(1, 2, 3, 4);
stream << m;
ASSERT_EQ(stream.str(), "(1, 2, 3, 4)");
}
}

TEST(GeometryTest, Gradient) {
Expand Down
14 changes: 14 additions & 0 deletions impeller/geometry/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,17 @@ static_assert(sizeof(Vector3) == 3 * sizeof(Scalar));
static_assert(sizeof(Vector4) == 4 * sizeof(Scalar));

} // namespace impeller

namespace std {

inline std::ostream& operator<<(std::ostream& out, const impeller::Vector3& p) {
out << "(" << p.x << ", " << p.y << ", " << p.z << ")";
return out;
}

inline std::ostream& operator<<(std::ostream& out, const impeller::Vector4& p) {
out << "(" << p.x << ", " << p.y << ", " << p.z << ", " << p.w << ")";
return out;
}

} // namespace std