SFML/test/TestUtilities/GraphicsUtil.hpp
Chris Thrasher 2adc3c0e23 Increase precision of sf::Rect<T> operator<<
This has been a recurring problem. I had to add similar code to the
sf::Angle operator<< because I was getting tiny floating point
differences that after rounding were imperceptable.
2022-04-08 16:46:51 +02:00

37 lines
1.1 KiB
C++

// Header for SFML unit tests.
//
// For a new graphics module test case, include this header.
// This ensures that string conversions are visible and can be used by doctest for debug output.
#ifndef SFML_TESTUTILITIES_GRAPHICS_HPP
#define SFML_TESTUTILITIES_GRAPHICS_HPP
#include "WindowUtil.hpp"
#include <SFML/Graphics/Rect.hpp>
#include <iomanip>
#include <limits>
namespace sf
{
struct BlendMode;
class Color;
class Transform;
std::ostream& operator <<(std::ostream& os, const BlendMode& blendMode);
std::ostream& operator <<(std::ostream& os, const Color& color);
std::ostream& operator <<(std::ostream& os, const Transform& transform);
template <typename T>
std::ostream& operator <<(std::ostream& os, const sf::Rect<T>& rect)
{
const auto flags = os.flags();
os << std::fixed << std::setprecision(std::numeric_limits<T>::max_digits10);
os << "(left=" << rect.left << ", top=" << rect.top << ", width=" << rect.width << ", height=" << rect.height << ")";
os.flags(flags);
return os;
}
}
#endif // SFML_TESTUTILITIES_GRAPHICS_HPP