From aa3d0b7ba5ea260ccdd8ef758df1a356f2d321d1 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 26 Feb 2024 13:21:21 -0700 Subject: [PATCH] Use `std::{min|max}` A new clang-tidy-18 check led me to this. These files already use so we might as well use these functions where appropriate. --- src/SFML/Graphics/Text.cpp | 3 +-- src/SFML/Graphics/Texture.cpp | 12 ++++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index c188ccc0c..4ded96815 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -276,8 +276,7 @@ float Text::getOutlineThickness() const Vector2f Text::findCharacterPos(std::size_t index) const { // Adjust the index if it's out of range - if (index > m_string.getSize()) - index = m_string.getSize(); + index = std::min(index, m_string.getSize()); // Precompute the variables needed by the algorithm const bool isBold = m_style & Bold; diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index aafa0d17e..59e821ff1 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -313,14 +313,10 @@ bool Texture::loadFromImage(const Image& image, const IntRect& area) // Adjust the rectangle to the size of the image IntRect rectangle = area; - if (rectangle.left < 0) - rectangle.left = 0; - if (rectangle.top < 0) - rectangle.top = 0; - if (rectangle.left + rectangle.width > width) - rectangle.width = width - rectangle.left; - if (rectangle.top + rectangle.height > height) - rectangle.height = height - rectangle.top; + rectangle.left = std::max(rectangle.left, 0); + rectangle.top = std::max(rectangle.top, 0); + rectangle.width = std::min(rectangle.width, width - rectangle.left); + rectangle.height = std::min(rectangle.height, height - rectangle.top); // Create the texture and upload the pixels if (create(Vector2u(rectangle.getSize())))