#include #include #include #include #include TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float) { SECTION("Type traits") { STATIC_CHECK(std::is_copy_constructible_v>); STATIC_CHECK(std::is_copy_assignable_v>); STATIC_CHECK(std::is_nothrow_move_constructible_v>); STATIC_CHECK(std::is_nothrow_move_assignable_v>); } SECTION("Construction") { SECTION("Default constructor") { constexpr sf::Rect rectangle; STATIC_CHECK(rectangle.position == sf::Vector2()); STATIC_CHECK(rectangle.size == sf::Vector2()); } SECTION("(Vector2, Vector2) constructor") { constexpr sf::Vector2 position(1, 2); constexpr sf::Vector2 dimension(3, 4); constexpr sf::Rect rectangle(position, dimension); STATIC_CHECK(rectangle.position == position); STATIC_CHECK(rectangle.size == dimension); } } SECTION("contains(Vector2)") { constexpr sf::Rect rectangle({0, 0}, {10, 10}); STATIC_CHECK(rectangle.contains(sf::Vector2(0, 0)) == true); STATIC_CHECK(rectangle.contains(sf::Vector2(9, 0)) == true); STATIC_CHECK(rectangle.contains(sf::Vector2(0, 9)) == true); STATIC_CHECK(rectangle.contains(sf::Vector2(9, 9)) == true); STATIC_CHECK(rectangle.contains(sf::Vector2(9, 10)) == false); STATIC_CHECK(rectangle.contains(sf::Vector2(10, 9)) == false); STATIC_CHECK(rectangle.contains(sf::Vector2(10, 10)) == false); STATIC_CHECK(rectangle.contains(sf::Vector2(15, 15)) == false); } SECTION("findIntersection()") { constexpr sf::Rect rectangle({0, 0}, {10, 10}); constexpr sf::Rect intersectingRectangle({5, 5}, {10, 10}); constexpr auto intersectionResult = rectangle.findIntersection(intersectingRectangle); STATIC_REQUIRE(intersectionResult.has_value()); STATIC_CHECK(*intersectionResult == sf::Rect({5, 5}, {5, 5})); constexpr sf::Rect nonIntersectingRectangle({-5, -5}, {5, 5}); STATIC_CHECK_FALSE(rectangle.findIntersection(nonIntersectingRectangle).has_value()); } SECTION("getCenter()") { STATIC_CHECK(sf::Rect({}, {}).getCenter() == sf::Vector2()); STATIC_CHECK(sf::Rect({1, 2}, {4, 6}).getCenter() == sf::Vector2(3, 5)); } SECTION("Operators") { SECTION("operator Rect") { STATIC_CHECK(!std::is_convertible_v); constexpr sf::FloatRect sourceRectangle({1.0f, 2.0f}, {3.0f, 4.0f}); constexpr sf::IntRect rectangle(sourceRectangle); STATIC_CHECK(rectangle.position == sf::Vector2i(1, 2)); STATIC_CHECK(rectangle.size == sf::Vector2i(3, 4)); } SECTION("operator==") { STATIC_CHECK(sf::Rect() == sf::Rect()); STATIC_CHECK(sf::Rect({1, 3}, {2, 5}) == sf::Rect({1, 3}, {2, 5})); STATIC_CHECK_FALSE(sf::Rect({1, 0}, {0, 0}) == sf::Rect({0, 0}, {0, 0})); STATIC_CHECK_FALSE(sf::Rect({0, 1}, {0, 0}) == sf::Rect({0, 0}, {0, 0})); STATIC_CHECK_FALSE(sf::Rect({0, 0}, {1, 0}) == sf::Rect({0, 0}, {0, 0})); STATIC_CHECK_FALSE(sf::Rect({0, 0}, {0, 1}) == sf::Rect({0, 0}, {0, 0})); } SECTION("operator!=") { STATIC_CHECK(sf::Rect({1, 0}, {0, 0}) != sf::Rect({0, 0}, {0, 0})); STATIC_CHECK(sf::Rect({0, 1}, {0, 0}) != sf::Rect({0, 0}, {0, 0})); STATIC_CHECK(sf::Rect({0, 0}, {1, 0}) != sf::Rect({0, 0}, {0, 0})); STATIC_CHECK(sf::Rect({0, 0}, {0, 1}) != sf::Rect({0, 0}, {0, 0})); STATIC_CHECK_FALSE(sf::Rect() != sf::Rect()); STATIC_CHECK_FALSE(sf::Rect({1, 3}, {2, 5}) != sf::Rect({1, 3}, {2, 5})); } } }