Skip to content

Commit

Permalink
polylib: make winding printable for debugging/testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwa committed Sep 19, 2024
1 parent f5d105b commit 68a5b55
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/common/polylib.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <stdexcept>
#include <optional>

#include <fmt/ostream.h>

#include <tbb/scalable_allocator.h>

namespace polylib
Expand Down Expand Up @@ -1278,8 +1280,25 @@ public:

return result;
}

// gtest support
// also, makes printable via fmt since we include fmt/ostream.h
friend std::ostream& operator<<(std::ostream& os, const winding_base_t &winding) {
os << "{";
for (size_t i = 0; i < winding.size(); ++i) {
os << "(" << winding[i] << ")";
if ((i + 1) < winding.size())
os << ", ";
}
os << "}";
return os;
}
};

// fmt support
template<class T>
struct fmt::formatter<winding_base_t<T>> : fmt::ostream_formatter {};

// the default amount of points to keep on stack
constexpr size_t STACK_POINTS_ON_WINDING = MAX_POINTS_ON_WINDING / 4;

Expand Down
10 changes: 10 additions & 0 deletions tests/test_light.cc
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,16 @@ TEST(mathlib, clampTexcoord)
EXPECT_EQ(127, clamp_texcoord(-129.0f, 128));
}

TEST(mathlib, windingFormat)
{
const polylib::winding_t poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}};

const char *exp = "{(0 0 0), (0 64 0), (64 64 0), (64 0 0)}";

EXPECT_EQ(exp, testing::PrintToString(poly));
EXPECT_EQ(exp, fmt::format("{}", poly));
}

TEST(Settings, delayDefault)
{
light_t light;
Expand Down

0 comments on commit 68a5b55

Please sign in to comment.