From 79c2aadbcce5a1f828d79171dc15b251bbe5bccb Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Fri, 31 Dec 2021 12:52:52 -0700 Subject: [PATCH] Remove redundant 4-param sf::Rect constructor --- examples/shader/Shader.cpp | 2 +- include/SFML/Graphics/Image.hpp | 2 +- include/SFML/Graphics/Rect.hpp | 14 -------------- include/SFML/Graphics/Rect.inl | 16 ++-------------- src/SFML/Graphics/Font.cpp | 6 +++--- src/SFML/Graphics/RenderTarget.cpp | 10 +++++----- src/SFML/Graphics/Shape.cpp | 2 +- src/SFML/Graphics/Sprite.cpp | 5 ++--- src/SFML/Graphics/Transform.cpp | 2 +- src/SFML/Graphics/VertexArray.cpp | 2 +- src/SFML/Graphics/View.cpp | 8 ++++---- test/Graphics/Rect.cpp | 24 ++++++++++++------------ 12 files changed, 33 insertions(+), 60 deletions(-) diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index bf983788..6e3e72fc 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -208,7 +208,7 @@ public: // Load the moving entities for (int i = 0; i < 6; ++i) { - sf::Sprite entity(m_entityTexture, sf::IntRect(96 * i, 0, 96, 96)); + sf::Sprite entity(m_entityTexture, sf::IntRect({96 * i, 0}, {96, 96})); m_entities.push_back(entity); } diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index 31cb2239..8437cade 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -214,7 +214,7 @@ public: /// \param applyAlpha Should the copy take into account the source transparency? /// //////////////////////////////////////////////////////////// - void copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect = IntRect(0, 0, 0, 0), bool applyAlpha = false); + void copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect = IntRect({0, 0}, {0, 0}), bool applyAlpha = false); //////////////////////////////////////////////////////////// /// \brief Change the color of a pixel diff --git a/include/SFML/Graphics/Rect.hpp b/include/SFML/Graphics/Rect.hpp index e53ce242..12c648e7 100644 --- a/include/SFML/Graphics/Rect.hpp +++ b/include/SFML/Graphics/Rect.hpp @@ -51,20 +51,6 @@ public: //////////////////////////////////////////////////////////// constexpr Rect(); - //////////////////////////////////////////////////////////// - /// \brief Construct the rectangle from its coordinates - /// - /// Be careful, the last two parameters are the width - /// and height, not the right and bottom coordinates! - /// - /// \param rectLeft Left coordinate of the rectangle - /// \param rectTop Top coordinate of the rectangle - /// \param rectWidth Width of the rectangle - /// \param rectHeight Height of the rectangle - /// - //////////////////////////////////////////////////////////// - constexpr Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight); - //////////////////////////////////////////////////////////// /// \brief Construct the rectangle from position and size /// diff --git a/include/SFML/Graphics/Rect.inl b/include/SFML/Graphics/Rect.inl index c1644621..75b667f1 100644 --- a/include/SFML/Graphics/Rect.inl +++ b/include/SFML/Graphics/Rect.inl @@ -35,18 +35,6 @@ height(0) } -//////////////////////////////////////////////////////////// -template -constexpr Rect::Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight) : -left (rectLeft), -top (rectTop), -width (rectWidth), -height(rectHeight) -{ - -} - - //////////////////////////////////////////////////////////// template constexpr Rect::Rect(const Vector2& position, const Vector2& size) : @@ -131,12 +119,12 @@ constexpr bool Rect::intersects(const Rect& rectangle, Rect& intersecti // If the intersection is valid (positive non zero area), then there is an intersection if ((interLeft < interRight) && (interTop < interBottom)) { - intersection = Rect(interLeft, interTop, interRight - interLeft, interBottom - interTop); + intersection = Rect({interLeft, interTop}, {interRight - interLeft, interBottom - interTop}); return true; } else { - intersection = Rect(0, 0, 0, 0); + intersection = Rect({0, 0}, {0, 0}); return false; } } diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 70a88b42..ba5916e1 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -731,7 +731,7 @@ IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height) if (!newTexture.create(textureWidth * 2, textureHeight * 2)) { err() << "Failed to create new page texture" << std::endl; - return IntRect(0, 0, 2, 2); + return IntRect({0, 0}, {2, 2}); } newTexture.setSmooth(m_isSmooth); @@ -742,7 +742,7 @@ IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height) { // Oops, we've reached the maximum texture size... err() << "Failed to add a new character to the font: the maximum texture size has been reached" << std::endl; - return IntRect(0, 0, 2, 2); + return IntRect({0, 0}, {2, 2}); } } @@ -753,7 +753,7 @@ IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height) } // Find the glyph's rectangle on the selected row - IntRect rect(Rect(row->width, row->top, width, height)); + IntRect rect(Rect({row->width, row->top}, {width, height})); // Update the row informations row->width += width; diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index c7d1f3d5..00abc221 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -202,10 +202,10 @@ IntRect RenderTarget::getViewport(const View& view) const float height = static_cast(getSize().y); const FloatRect& viewport = view.getViewport(); - return IntRect(static_cast(0.5f + width * viewport.left), - static_cast(0.5f + height * viewport.top), - static_cast(0.5f + width * viewport.width), - static_cast(0.5f + height * viewport.height)); + return IntRect({static_cast(0.5f + width * viewport.left), + static_cast(0.5f + height * viewport.top)}, + {static_cast(0.5f + width * viewport.width), + static_cast(0.5f + height * viewport.height)}); } @@ -555,7 +555,7 @@ void RenderTarget::resetGLStates() void RenderTarget::initialize() { // Setup the default and current views - m_defaultView.reset(FloatRect(0, 0, static_cast(getSize().x), static_cast(getSize().y))); + m_defaultView.reset(FloatRect({0, 0}, Vector2f(getSize()))); m_view = m_defaultView; // Set GL states only on first draw, so that we don't pollute user's states diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index 43ab2e7e..16329e71 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -66,7 +66,7 @@ void Shape::setTexture(const Texture* texture, bool resetRect) { // Recompute the texture area if requested, or if there was no texture & rect before if (resetRect || (!m_texture && (m_textureRect == IntRect()))) - setTextureRect(IntRect(0, 0, static_cast(texture->getSize().x), static_cast(texture->getSize().y))); + setTextureRect(IntRect({0, 0}, Vector2i(texture->getSize()))); } // Assign the new texture diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index 926cf7ee..3b94af9d 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -68,8 +68,7 @@ void Sprite::setTexture(const Texture& texture, bool resetRect) // Recompute the texture area if requested, or if there was no valid texture & rect before if (resetRect || (!m_texture && (m_textureRect == sf::IntRect()))) { - Vector2i size = Vector2i(texture.getSize()); - setTextureRect(IntRect(0, 0, size.x, size.y)); + setTextureRect(IntRect({0, 0}, Vector2i(texture.getSize()))); } // Assign the new texture @@ -127,7 +126,7 @@ FloatRect Sprite::getLocalBounds() const auto width = static_cast(std::abs(m_textureRect.width)); auto height = static_cast(std::abs(m_textureRect.height)); - return FloatRect(0.f, 0.f, width, height); + return FloatRect({0.f, 0.f}, {width, height}); } diff --git a/src/SFML/Graphics/Transform.cpp b/src/SFML/Graphics/Transform.cpp index 89f08678..77c8a90a 100644 --- a/src/SFML/Graphics/Transform.cpp +++ b/src/SFML/Graphics/Transform.cpp @@ -127,7 +127,7 @@ FloatRect Transform::transformRect(const FloatRect& rectangle) const else if (points[i].y > bottom) bottom = points[i].y; } - return FloatRect(left, top, right - left, bottom - top); + return FloatRect({left, top}, {right - left, bottom - top}); } diff --git a/src/SFML/Graphics/VertexArray.cpp b/src/SFML/Graphics/VertexArray.cpp index 06aeb889..aebc1d35 100644 --- a/src/SFML/Graphics/VertexArray.cpp +++ b/src/SFML/Graphics/VertexArray.cpp @@ -130,7 +130,7 @@ FloatRect VertexArray::getBounds() const bottom = position.y; } - return FloatRect(left, top, right - left, bottom - top); + return FloatRect({left, top}, {right - left, bottom - top}); } else { diff --git a/src/SFML/Graphics/View.cpp b/src/SFML/Graphics/View.cpp index 87c4e50f..343dd2c1 100644 --- a/src/SFML/Graphics/View.cpp +++ b/src/SFML/Graphics/View.cpp @@ -36,11 +36,11 @@ View::View() : m_center (), m_size (), m_rotation (0), -m_viewport (0, 0, 1, 1), +m_viewport ({0, 0}, {1, 1}), m_transformUpdated (false), m_invTransformUpdated(false) { - reset(FloatRect(0, 0, 1000, 1000)); + reset(FloatRect({0, 0}, {1000, 1000})); } @@ -49,7 +49,7 @@ View::View(const FloatRect& rectangle) : m_center (), m_size (), m_rotation (0), -m_viewport (0, 0, 1, 1), +m_viewport ({0, 0}, {1, 1}), m_transformUpdated (false), m_invTransformUpdated(false) { @@ -62,7 +62,7 @@ View::View(const Vector2f& center, const Vector2f& size) : m_center (center), m_size (size), m_rotation (0), -m_viewport (0, 0, 1, 1), +m_viewport ({0, 0}, {1, 1}), m_transformUpdated (false), m_invTransformUpdated(false) { diff --git a/test/Graphics/Rect.cpp b/test/Graphics/Rect.cpp index 987fc725..6aa54c45 100644 --- a/test/Graphics/Rect.cpp +++ b/test/Graphics/Rect.cpp @@ -17,7 +17,7 @@ TEST_CASE("sf::Rect class template - [graphics]") SUBCASE("(left, top, width, height) constructor") { - sf::IntRect rectangle(1, 2, 3, 4); + sf::IntRect rectangle({1, 2}, {3, 4}); CHECK(rectangle.left == 1); CHECK(rectangle.top == 2); CHECK(rectangle.width == 3); @@ -38,7 +38,7 @@ TEST_CASE("sf::Rect class template - [graphics]") SUBCASE("Conversion constructor") { - sf::FloatRect sourceRectangle(1.0f, 2.0f, 3.0f, 4.0f); + sf::FloatRect sourceRectangle({1.0f, 2.0f}, {3.0f, 4.0f}); sf::IntRect rectangle(sourceRectangle); CHECK(rectangle.left == static_cast(sourceRectangle.left)); @@ -52,7 +52,7 @@ TEST_CASE("sf::Rect class template - [graphics]") { SUBCASE("contains(Vector2)") { - sf::IntRect rectangle(0, 0, 10, 10); + sf::IntRect rectangle({0, 0}, {10, 10}); CHECK(rectangle.contains(sf::Vector2i(0, 0)) == true); CHECK(rectangle.contains(sf::Vector2i(9, 0)) == true); @@ -69,9 +69,9 @@ TEST_CASE("sf::Rect class template - [graphics]") { SUBCASE("intersects(Rect)") { - sf::IntRect rectangle(0, 0, 10, 10); - sf::IntRect intersectingRectangle(5, 5, 10, 10); - sf::IntRect nonIntersectingRectangle(-5, -5, 5, 5); + sf::IntRect rectangle({0, 0}, {10, 10}); + sf::IntRect intersectingRectangle({5, 5}, {10, 10}); + sf::IntRect nonIntersectingRectangle({-5, -5}, {5, 5}); CHECK(rectangle.intersects(intersectingRectangle) == true); CHECK(rectangle.intersects(nonIntersectingRectangle) == false); @@ -79,9 +79,9 @@ TEST_CASE("sf::Rect class template - [graphics]") SUBCASE("intersects(Rect, Rect)") { - sf::IntRect rectangle(0, 0, 10, 10); - sf::IntRect intersectingRectangle(5, 5, 10, 10); - sf::IntRect nonIntersectingRectangle(-5, -5, 5, 5); + sf::IntRect rectangle({0, 0}, {10, 10}); + sf::IntRect intersectingRectangle({5, 5}, {10, 10}); + sf::IntRect nonIntersectingRectangle({-5, -5}, {5, 5}); sf::IntRect intersectionResult; CHECK(rectangle.intersects(intersectingRectangle, intersectionResult) == true); @@ -96,9 +96,9 @@ TEST_CASE("sf::Rect class template - [graphics]") SUBCASE("Comparison operations") { - sf::IntRect firstRectangle(1, 3, 2, 5); - sf::IntRect secondRectangle(1, 3, 2, 5); - sf::IntRect differentRectangle(3, 1, 5, 2); + sf::IntRect firstRectangle({1, 3}, {2, 5}); + sf::IntRect secondRectangle({1, 3}, {2, 5}); + sf::IntRect differentRectangle({3, 1}, {5, 2}); CHECK(firstRectangle == secondRectangle); CHECK(firstRectangle != differentRectangle);