From c371bc68167743d08778428f8c9dc32ec783557d Mon Sep 17 00:00:00 2001 From: kimci86 Date: Wed, 5 Jun 2024 22:26:02 +0200 Subject: [PATCH] Remove Rect getPosition and getSize methods --- include/SFML/Graphics/Rect.hpp | 20 -------------------- include/SFML/Graphics/Rect.inl | 18 +----------------- src/SFML/Graphics/RenderTarget.cpp | 6 +++--- src/SFML/Graphics/Shape.cpp | 3 +-- src/SFML/Graphics/Texture.cpp | 2 +- src/SFML/Graphics/View.cpp | 2 +- test/Graphics/Rect.test.cpp | 12 ------------ 7 files changed, 7 insertions(+), 56 deletions(-) diff --git a/include/SFML/Graphics/Rect.hpp b/include/SFML/Graphics/Rect.hpp index b412774ca..150e5ea61 100644 --- a/include/SFML/Graphics/Rect.hpp +++ b/include/SFML/Graphics/Rect.hpp @@ -104,26 +104,6 @@ public: //////////////////////////////////////////////////////////// constexpr std::optional> findIntersection(const Rect& rectangle) const; - //////////////////////////////////////////////////////////// - /// \brief Get the position of the rectangle's top-left corner - /// - /// \return Position of rectangle - /// - /// \see getSize, getCenter - /// - //////////////////////////////////////////////////////////// - constexpr Vector2 getPosition() const; - - //////////////////////////////////////////////////////////// - /// \brief Get the size of the rectangle - /// - /// \return Size of rectangle - /// - /// \see getPosition, getCenter - /// - //////////////////////////////////////////////////////////// - constexpr Vector2 getSize() const; - //////////////////////////////////////////////////////////// /// \brief Get the position of the center of the rectangle /// diff --git a/include/SFML/Graphics/Rect.inl b/include/SFML/Graphics/Rect.inl index 175fc6fa7..c68a27f53 100644 --- a/include/SFML/Graphics/Rect.inl +++ b/include/SFML/Graphics/Rect.inl @@ -110,27 +110,11 @@ constexpr std::optional> Rect::findIntersection(const Rect& rectan } -//////////////////////////////////////////////////////////// -template -constexpr Vector2 Rect::getPosition() const -{ - return Vector2(position.x, position.y); -} - - -//////////////////////////////////////////////////////////// -template -constexpr Vector2 Rect::getSize() const -{ - return Vector2(size.x, size.y); -} - - //////////////////////////////////////////////////////////// template constexpr Vector2 Rect::getCenter() const { - return getPosition() + getSize() / T{2}; + return position + size / T{2}; } diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 4c2a24c01..dd9dc81eb 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -308,7 +308,7 @@ Vector2f RenderTarget::mapPixelToCoords(const Vector2i& point, const View& view) // First, convert from viewport coordinates to homogeneous coordinates const FloatRect viewport = FloatRect(getViewport(view)); const Vector2f normalized = Vector2f(-1, 1) + - Vector2f(2, -2).cwiseMul(Vector2f(point) - viewport.getPosition()).cwiseDiv(viewport.getSize()); + Vector2f(2, -2).cwiseMul(Vector2f(point) - viewport.position).cwiseDiv(viewport.size); // Then transform by the inverse of the view matrix return view.getInverseTransform().transformPoint(normalized); @@ -330,8 +330,8 @@ Vector2i RenderTarget::mapCoordsToPixel(const Vector2f& point, const View& view) // Then convert to viewport coordinates const FloatRect viewport = FloatRect(getViewport(view)); - return Vector2i((normalized.cwiseMul({1, -1}) + sf::Vector2f(1, 1)).cwiseDiv({2, 2}).cwiseMul(viewport.getSize()) + - viewport.getPosition()); + return Vector2i((normalized.cwiseMul({1, -1}) + sf::Vector2f(1, 1)).cwiseDiv({2, 2}).cwiseMul(viewport.size) + + viewport.position); } diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index f9ee8150e..34176283f 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -273,8 +273,7 @@ void Shape::updateTexCoords() const float yratio = m_insideBounds.size.y > 0 ? (m_vertices[i].position.y - m_insideBounds.position.y) / m_insideBounds.size.y : 0; - m_vertices[i].texCoords = convertedTextureRect.getPosition() + - convertedTextureRect.getSize().cwiseMul({xratio, yratio}); + m_vertices[i].texCoords = convertedTextureRect.position + convertedTextureRect.size.cwiseMul({xratio, yratio}); } } diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index a49b4d56d..1281580bc 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -330,7 +330,7 @@ std::optional Texture::loadFromImage(const Image& image, bool sRgb, con rectangle.size.y = std::min(rectangle.size.y, height - rectangle.position.y); // Create the texture and upload the pixels - if (auto texture = sf::Texture::create(Vector2u(rectangle.getSize()), sRgb)) + if (auto texture = sf::Texture::create(Vector2u(rectangle.size), sRgb)) { const TransientContextLock lock; diff --git a/src/SFML/Graphics/View.cpp b/src/SFML/Graphics/View.cpp index 39e221d32..4e9c65292 100644 --- a/src/SFML/Graphics/View.cpp +++ b/src/SFML/Graphics/View.cpp @@ -34,7 +34,7 @@ namespace sf { //////////////////////////////////////////////////////////// -View::View(const FloatRect& rectangle) : m_center(rectangle.getCenter()), m_size(rectangle.getSize()) +View::View(const FloatRect& rectangle) : m_center(rectangle.getCenter()), m_size(rectangle.size) { } diff --git a/test/Graphics/Rect.test.cpp b/test/Graphics/Rect.test.cpp index 11bad1f25..c17ec462b 100644 --- a/test/Graphics/Rect.test.cpp +++ b/test/Graphics/Rect.test.cpp @@ -91,18 +91,6 @@ TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float) STATIC_CHECK_FALSE(rectangle.findIntersection(nonIntersectingRectangle).has_value()); } - SECTION("getPosition()") - { - STATIC_CHECK(sf::Rect({}, {}).getPosition() == sf::Vector2()); - STATIC_CHECK(sf::Rect({1, 2}, {3, 4}).getPosition() == sf::Vector2(1, 2)); - } - - SECTION("getSize()") - { - STATIC_CHECK(sf::Rect({}, {}).getSize() == sf::Vector2()); - STATIC_CHECK(sf::Rect({1, 2}, {3, 4}).getSize() == sf::Vector2(3, 4)); - } - SECTION("getCenter()") { STATIC_CHECK(sf::Rect({}, {}).getCenter() == sf::Vector2());