diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp index 4fba4b1a7..e834dfee1 100644 --- a/examples/island/Island.cpp +++ b/examples/island/Island.cpp @@ -152,8 +152,8 @@ int main() } // Center the status text - statusText.setPosition({(windowWidth - statusText.getLocalBounds().width) / 2.f, - (windowHeight - statusText.getLocalBounds().height) / 2.f}); + statusText.setPosition({(windowWidth - statusText.getLocalBounds().size.x) / 2.f, + (windowHeight - statusText.getLocalBounds().size.y) / 2.f}); // Set up an array of pointers to our settings for arrow navigation constexpr std::array settings = { diff --git a/include/SFML/Graphics/Rect.hpp b/include/SFML/Graphics/Rect.hpp index be2dd2811..b412774ca 100644 --- a/include/SFML/Graphics/Rect.hpp +++ b/include/SFML/Graphics/Rect.hpp @@ -137,10 +137,8 @@ public: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - T left{}; //!< Left coordinate of the rectangle - T top{}; //!< Top coordinate of the rectangle - T width{}; //!< Width of the rectangle - T height{}; //!< Height of the rectangle + Vector2 position{}; //!< Position of the top-left corner of the rectangle + Vector2 size{}; //!< Size of the rectangle }; //////////////////////////////////////////////////////////// diff --git a/include/SFML/Graphics/Rect.inl b/include/SFML/Graphics/Rect.inl index df9ede64f..175fc6fa7 100644 --- a/include/SFML/Graphics/Rect.inl +++ b/include/SFML/Graphics/Rect.inl @@ -37,11 +37,7 @@ constexpr Rect::Rect() = default; //////////////////////////////////////////////////////////// template -constexpr Rect::Rect(const Vector2& position, const Vector2& size) : -left(position.x), -top(position.y), -width(size.x), -height(size.y) +constexpr Rect::Rect(const Vector2& thePosition, const Vector2& theSize) : position(thePosition), size(theSize) { } @@ -49,11 +45,7 @@ height(size.y) //////////////////////////////////////////////////////////// template template -constexpr Rect::Rect(const Rect& rectangle) : -left(static_cast(rectangle.left)), -top(static_cast(rectangle.top)), -width(static_cast(rectangle.width)), -height(static_cast(rectangle.height)) +constexpr Rect::Rect(const Rect& rectangle) : position(rectangle.position), size(rectangle.size) { } @@ -69,10 +61,10 @@ constexpr bool Rect::contains(const Vector2& point) const // Rectangles with negative dimensions are allowed, so we must handle them correctly // Compute the real min and max of the rectangle on both axes - const T minX = min(left, static_cast(left + width)); - const T maxX = max(left, static_cast(left + width)); - const T minY = min(top, static_cast(top + height)); - const T maxY = max(top, static_cast(top + height)); + const T minX = min(position.x, static_cast(position.x + size.x)); + const T maxX = max(position.x, static_cast(position.x + size.x)); + const T minY = min(position.y, static_cast(position.y + size.y)); + const T maxY = max(position.y, static_cast(position.y + size.y)); return (point.x >= minX) && (point.x < maxX) && (point.y >= minY) && (point.y < maxY); } @@ -89,16 +81,16 @@ constexpr std::optional> Rect::findIntersection(const Rect& rectan // Rectangles with negative dimensions are allowed, so we must handle them correctly // Compute the min and max of the first rectangle on both axes - const T r1MinX = min(left, static_cast(left + width)); - const T r1MaxX = max(left, static_cast(left + width)); - const T r1MinY = min(top, static_cast(top + height)); - const T r1MaxY = max(top, static_cast(top + height)); + const T r1MinX = min(position.x, static_cast(position.x + size.x)); + const T r1MaxX = max(position.x, static_cast(position.x + size.x)); + const T r1MinY = min(position.y, static_cast(position.y + size.y)); + const T r1MaxY = max(position.y, static_cast(position.y + size.y)); // Compute the min and max of the second rectangle on both axes - const T r2MinX = min(rectangle.left, static_cast(rectangle.left + rectangle.width)); - const T r2MaxX = max(rectangle.left, static_cast(rectangle.left + rectangle.width)); - const T r2MinY = min(rectangle.top, static_cast(rectangle.top + rectangle.height)); - const T r2MaxY = max(rectangle.top, static_cast(rectangle.top + rectangle.height)); + const T r2MinX = min(rectangle.position.x, static_cast(rectangle.position.x + rectangle.size.x)); + const T r2MaxX = max(rectangle.position.x, static_cast(rectangle.position.x + rectangle.size.x)); + const T r2MinY = min(rectangle.position.y, static_cast(rectangle.position.y + rectangle.size.y)); + const T r2MaxY = max(rectangle.position.y, static_cast(rectangle.position.y + rectangle.size.y)); // Compute the intersection boundaries const T interLeft = max(r1MinX, r2MinX); @@ -122,7 +114,7 @@ constexpr std::optional> Rect::findIntersection(const Rect& rectan template constexpr Vector2 Rect::getPosition() const { - return Vector2(left, top); + return Vector2(position.x, position.y); } @@ -130,7 +122,7 @@ constexpr Vector2 Rect::getPosition() const template constexpr Vector2 Rect::getSize() const { - return Vector2(width, height); + return Vector2(size.x, size.y); } @@ -146,8 +138,7 @@ constexpr Vector2 Rect::getCenter() const template constexpr bool operator==(const Rect& left, const Rect& right) { - return (left.left == right.left) && (left.width == right.width) && (left.top == right.top) && - (left.height == right.height); + return (left.position == right.position) && (left.size == right.size); } diff --git a/include/SFML/Graphics/Transform.inl b/include/SFML/Graphics/Transform.inl index 6aee63b2d..dfe3c337c 100644 --- a/include/SFML/Graphics/Transform.inl +++ b/include/SFML/Graphics/Transform.inl @@ -104,10 +104,11 @@ constexpr Vector2f Transform::transformPoint(const Vector2f& point) const constexpr FloatRect Transform::transformRect(const FloatRect& rectangle) const { // Transform the 4 corners of the rectangle - const std::array points = {transformPoint({rectangle.left, rectangle.top}), - transformPoint({rectangle.left, rectangle.top + rectangle.height}), - transformPoint({rectangle.left + rectangle.width, rectangle.top}), - transformPoint({rectangle.left + rectangle.width, rectangle.top + rectangle.height})}; + const std::array points = {transformPoint({rectangle.position.x, rectangle.position.y}), + transformPoint({rectangle.position.x, rectangle.position.y + rectangle.size.y}), + transformPoint({rectangle.position.x + rectangle.size.x, rectangle.position.y}), + transformPoint( + {rectangle.position.x + rectangle.size.x, rectangle.position.y + rectangle.size.y})}; // Compute the bounding rectangle of the transformed points float left = points[0].x; diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index f9b69b641..0644ec4f7 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -566,16 +566,16 @@ Glyph Font::loadGlyph(std::uint32_t codePoint, unsigned int characterSize, bool // Make sure the texture data is positioned in the center // of the allocated texture rectangle - glyph.textureRect.left += static_cast(padding); - glyph.textureRect.top += static_cast(padding); - glyph.textureRect.width -= static_cast(2 * padding); - glyph.textureRect.height -= static_cast(2 * padding); + glyph.textureRect.position.x += static_cast(padding); + glyph.textureRect.position.y += static_cast(padding); + glyph.textureRect.size.x -= static_cast(2 * padding); + glyph.textureRect.size.y -= static_cast(2 * padding); // Compute the glyph's bounding box - glyph.bounds.left = static_cast(bitmapGlyph->left); - glyph.bounds.top = static_cast(-bitmapGlyph->top); - glyph.bounds.width = static_cast(bitmap.width); - glyph.bounds.height = static_cast(bitmap.rows); + glyph.bounds.position.x = static_cast(bitmapGlyph->left); + glyph.bounds.position.y = static_cast(-bitmapGlyph->top); + glyph.bounds.size.x = static_cast(bitmap.width); + glyph.bounds.size.y = static_cast(bitmap.rows); // Resize the pixel buffer to the new size and fill it with transparent white pixels m_pixelBuffer.resize(static_cast(width) * static_cast(height) * 4); @@ -623,10 +623,10 @@ Glyph Font::loadGlyph(std::uint32_t codePoint, unsigned int characterSize, bool } // Write the pixels to the texture - const unsigned int x = static_cast(glyph.textureRect.left) - padding; - const unsigned int y = static_cast(glyph.textureRect.top) - padding; - const unsigned int w = static_cast(glyph.textureRect.width) + 2 * padding; - const unsigned int h = static_cast(glyph.textureRect.height) + 2 * padding; + const unsigned int x = static_cast(glyph.textureRect.position.x) - padding; + const unsigned int y = static_cast(glyph.textureRect.position.y) - padding; + const unsigned int w = static_cast(glyph.textureRect.size.x) + 2 * padding; + const unsigned int h = static_cast(glyph.textureRect.size.y) + 2 * padding; page.texture.update(m_pixelBuffer.data(), {w, h}, {x, y}); } diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index be8c18d51..a09b2cdf8 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -389,13 +389,13 @@ void Image::createMaskFromColor(const Color& color, std::uint8_t alpha) return false; // Make sure the sourceRect components are non-negative before casting them to unsigned values - if (sourceRect.left < 0 || sourceRect.top < 0 || sourceRect.width < 0 || sourceRect.height < 0) + if (sourceRect.position.x < 0 || sourceRect.position.y < 0 || sourceRect.size.x < 0 || sourceRect.size.y < 0) return false; Rect srcRect(sourceRect); // Use the whole source image as srcRect if the provided source rectangle is empty - if (srcRect.width == 0 || srcRect.height == 0) + if (srcRect.size.x == 0 || srcRect.size.y == 0) { srcRect = Rect({0, 0}, source.m_size); } @@ -404,7 +404,7 @@ void Image::createMaskFromColor(const Color& color, std::uint8_t alpha) { // Checking the bottom right corner is enough because // left and top are non-negative and width and height are positive. - if (source.m_size.x < srcRect.left + srcRect.width || source.m_size.y < srcRect.top + srcRect.height) + if (source.m_size.x < srcRect.position.x + srcRect.size.x || source.m_size.y < srcRect.position.y + srcRect.size.y) return false; } @@ -413,14 +413,14 @@ void Image::createMaskFromColor(const Color& color, std::uint8_t alpha) return false; // Then find the valid size of the destination rectangle - const Vector2u dstSize(std::min(m_size.x - dest.x, srcRect.width), std::min(m_size.y - dest.y, srcRect.height)); + const Vector2u dstSize(std::min(m_size.x - dest.x, srcRect.size.x), std::min(m_size.y - dest.y, srcRect.size.y)); // Precompute as much as possible const std::size_t pitch = static_cast(dstSize.x) * 4; const unsigned int srcStride = source.m_size.x * 4; const unsigned int dstStride = m_size.x * 4; - const std::uint8_t* srcPixels = source.m_pixels.data() + (srcRect.left + srcRect.top * source.m_size.x) * 4; + const std::uint8_t* srcPixels = source.m_pixels.data() + (srcRect.position.x + srcRect.position.y * source.m_size.x) * 4; std::uint8_t* dstPixels = m_pixels.data() + (dest.x + dest.y * m_size.x) * 4; // Copy the pixels diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index dec7c6a60..4c2a24c01 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -279,8 +279,8 @@ IntRect RenderTarget::getViewport(const View& view) const const auto [width, height] = Vector2f(getSize()); const FloatRect& viewport = view.getViewport(); - return IntRect(Rect({std::lround(width * viewport.left), std::lround(height * viewport.top)}, - {std::lround(width * viewport.width), std::lround(height * viewport.height)})); + return IntRect(Rect({std::lround(width * viewport.position.x), std::lround(height * viewport.position.y)}, + {std::lround(width * viewport.size.x), std::lround(height * viewport.size.y)})); } @@ -290,8 +290,8 @@ IntRect RenderTarget::getScissor(const View& view) const const auto [width, height] = Vector2f(getSize()); const FloatRect& scissor = view.getScissor(); - return IntRect(Rect({std::lround(width * scissor.left), std::lround(height * scissor.top)}, - {std::lround(width * scissor.width), std::lround(height * scissor.height)})); + return IntRect(Rect({std::lround(width * scissor.position.x), std::lround(height * scissor.position.y)}, + {std::lround(width * scissor.size.x), std::lround(height * scissor.size.y)})); } @@ -656,8 +656,8 @@ void RenderTarget::applyCurrentView() { // Set the viewport const IntRect viewport = getViewport(m_view); - const int viewportTop = static_cast(getSize().y) - (viewport.top + viewport.height); - glCheck(glViewport(viewport.left, viewportTop, viewport.width, viewport.height)); + const int viewportTop = static_cast(getSize().y) - (viewport.position.y + viewport.size.y); + glCheck(glViewport(viewport.position.x, viewportTop, viewport.size.x, viewport.size.y)); // Set the scissor rectangle and enable/disable scissor testing if (m_view.getScissor() == FloatRect({0, 0}, {1, 1})) @@ -671,8 +671,8 @@ void RenderTarget::applyCurrentView() else { const IntRect pixelScissor = getScissor(m_view); - const int scissorTop = static_cast(getSize().y) - (pixelScissor.top + pixelScissor.height); - glCheck(glScissor(pixelScissor.left, scissorTop, pixelScissor.width, pixelScissor.height)); + const int scissorTop = static_cast(getSize().y) - (pixelScissor.position.y + pixelScissor.size.y); + glCheck(glScissor(pixelScissor.position.x, scissorTop, pixelScissor.size.x, pixelScissor.size.y)); if (!m_cache.scissorEnabled) { diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index ef2bace33..f9ee8150e 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -267,11 +267,11 @@ void Shape::updateTexCoords() for (std::size_t i = 0; i < m_vertices.getVertexCount(); ++i) { - const float xratio = m_insideBounds.width > 0 - ? (m_vertices[i].position.x - m_insideBounds.left) / m_insideBounds.width + const float xratio = m_insideBounds.size.x > 0 + ? (m_vertices[i].position.x - m_insideBounds.position.x) / m_insideBounds.size.x : 0; - const float yratio = m_insideBounds.height > 0 - ? (m_vertices[i].position.y - m_insideBounds.top) / m_insideBounds.height + 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}); diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index 5718fed21..6c8a80645 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -128,10 +128,10 @@ void Sprite::draw(RenderTarget& target, RenderStates states) const //////////////////////////////////////////////////////////// void Sprite::updateVertices() { - const auto left = static_cast(m_textureRect.left); - const auto top = static_cast(m_textureRect.top); - const auto width = static_cast(m_textureRect.width); - const auto height = static_cast(m_textureRect.height); + const auto left = static_cast(m_textureRect.position.x); + const auto top = static_cast(m_textureRect.position.y); + const auto width = static_cast(m_textureRect.size.x); + const auto height = static_cast(m_textureRect.size.y); const auto right = float{left + width}; const auto bottom = float{top + height}; diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index 518e535d4..78f7c7536 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -65,15 +65,15 @@ void addGlyphQuad(sf::VertexArray& vertices, sf::Vector2f position, const sf::Co { const float padding = 1.0; - const float left = glyph.bounds.left - padding; - const float top = glyph.bounds.top - padding; - const float right = glyph.bounds.left + glyph.bounds.width + padding; - const float bottom = glyph.bounds.top + glyph.bounds.height + padding; + const float left = glyph.bounds.position.x - padding; + const float top = glyph.bounds.position.y - padding; + const float right = glyph.bounds.position.x + glyph.bounds.size.x + padding; + const float bottom = glyph.bounds.position.y + glyph.bounds.size.y + padding; - const float u1 = static_cast(glyph.textureRect.left) - padding; - const float v1 = static_cast(glyph.textureRect.top) - padding; - const float u2 = static_cast(glyph.textureRect.left + glyph.textureRect.width) + padding; - const float v2 = static_cast(glyph.textureRect.top + glyph.textureRect.height) + padding; + const float u1 = static_cast(glyph.textureRect.position.x) - padding; + const float v1 = static_cast(glyph.textureRect.position.y) - padding; + const float u2 = static_cast(glyph.textureRect.position.x + glyph.textureRect.size.x) + padding; + const float v2 = static_cast(glyph.textureRect.position.y + glyph.textureRect.size.y) + padding; vertices.append({{position.x + left - italicShear * top, position.y + top}, color, {u1, v1}}); vertices.append({{position.x + right - italicShear * top, position.y + top}, color, {u2, v1}}); @@ -478,10 +478,10 @@ void Text::ensureGeometryUpdate() const addGlyphQuad(m_vertices, Vector2f(x, y), m_fillColor, glyph, italicShear); // Update the current bounds - const float left = glyph.bounds.left; - const float top = glyph.bounds.top; - const float right = glyph.bounds.left + glyph.bounds.width; - const float bottom = glyph.bounds.top + glyph.bounds.height; + const float left = glyph.bounds.position.x; + const float top = glyph.bounds.position.y; + const float right = glyph.bounds.position.x + glyph.bounds.size.x; + const float bottom = glyph.bounds.position.y + glyph.bounds.size.y; minX = std::min(minX, x + left - italicShear * bottom); maxX = std::max(maxX, x + right - italicShear * top); @@ -521,10 +521,10 @@ void Text::ensureGeometryUpdate() const } // Update the bounding rectangle - m_bounds.left = minX; - m_bounds.top = minY; - m_bounds.width = maxX - minX; - m_bounds.height = maxY - minY; + m_bounds.position.x = minX; + m_bounds.position.y = minY; + m_bounds.size.x = maxX - minX; + m_bounds.size.y = maxY - minY; } } // namespace sf diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 2ddaab46e..a49b4d56d 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -303,8 +303,8 @@ std::optional Texture::loadFromImage(const Image& image, bool sRgb, con const auto [width, height] = Vector2i(image.getSize()); // Load the entire image if the source area is either empty or contains the whole image - if (area.width == 0 || (area.height == 0) || - ((area.left <= 0) && (area.top <= 0) && (area.width >= width) && (area.height >= height))) + if (area.size.x == 0 || (area.size.y == 0) || + ((area.position.x <= 0) && (area.position.y <= 0) && (area.size.x >= width) && (area.size.y >= height))) { // Load the entire image if (auto texture = sf::Texture::create(image.getSize(), sRgb)) @@ -323,11 +323,11 @@ std::optional Texture::loadFromImage(const Image& image, bool sRgb, con // Load a sub-area of the image // Adjust the rectangle to the size of the image - IntRect rectangle = area; - 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); + IntRect rectangle = area; + rectangle.position.x = std::max(rectangle.position.x, 0); + rectangle.position.y = std::max(rectangle.position.y, 0); + rectangle.size.x = std::min(rectangle.size.x, width - rectangle.position.x); + 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)) @@ -338,11 +338,11 @@ std::optional Texture::loadFromImage(const Image& image, bool sRgb, con const priv::TextureSaver save; // Copy the pixels to the texture, row by row - const std::uint8_t* pixels = image.getPixelsPtr() + 4 * (rectangle.left + (width * rectangle.top)); + const std::uint8_t* pixels = image.getPixelsPtr() + 4 * (rectangle.position.x + (width * rectangle.position.y)); glCheck(glBindTexture(GL_TEXTURE_2D, texture->m_texture)); - for (int i = 0; i < rectangle.height; ++i) + for (int i = 0; i < rectangle.size.y; ++i) { - glCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, rectangle.width, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels)); + glCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, rectangle.size.x, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels)); pixels += 4 * width; } diff --git a/src/SFML/Graphics/View.cpp b/src/SFML/Graphics/View.cpp index b5e77ab01..39e221d32 100644 --- a/src/SFML/Graphics/View.cpp +++ b/src/SFML/Graphics/View.cpp @@ -84,12 +84,12 @@ void View::setViewport(const FloatRect& viewport) //////////////////////////////////////////////////////////// void View::setScissor(const FloatRect& scissor) { - assert(scissor.left >= 0.0f && scissor.left <= 1.0f && "scissor.left must lie within [0, 1]"); - assert(scissor.top >= 0.0f && scissor.top <= 1.0f && "scissor.top must lie within [0, 1]"); - assert(scissor.width >= 0.0f && "scissor.width must lie within [0, 1]"); - assert(scissor.height >= 0.0f && "scissor.height must lie within [0, 1]"); - assert(scissor.left + scissor.width <= 1.0f && "scissor.left + scissor.width must lie within [0, 1]"); - assert(scissor.top + scissor.height <= 1.0f && "scissor.top + scissor.height must lie within [0, 1]"); + assert(scissor.position.x >= 0.0f && scissor.position.x <= 1.0f && "scissor.position.x must lie within [0, 1]"); + assert(scissor.position.y >= 0.0f && scissor.position.y <= 1.0f && "scissor.position.y must lie within [0, 1]"); + assert(scissor.size.x >= 0.0f && "scissor.size.x must lie within [0, 1]"); + assert(scissor.size.y >= 0.0f && "scissor.size.y must lie within [0, 1]"); + assert(scissor.position.x + scissor.size.x <= 1.0f && "scissor.position.x + scissor.size.x must lie within [0, 1]"); + assert(scissor.position.y + scissor.size.y <= 1.0f && "scissor.position.y + scissor.size.y must lie within [0, 1]"); m_scissor = scissor; } diff --git a/test/Graphics/Rect.test.cpp b/test/Graphics/Rect.test.cpp index 0b9aeb9cb..11bad1f25 100644 --- a/test/Graphics/Rect.test.cpp +++ b/test/Graphics/Rect.test.cpp @@ -22,19 +22,19 @@ TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float) SECTION("Default constructor") { constexpr sf::Rect rectangle; - STATIC_CHECK(rectangle.left == 0); - STATIC_CHECK(rectangle.top == 0); - STATIC_CHECK(rectangle.width == 0); - STATIC_CHECK(rectangle.height == 0); + STATIC_CHECK(rectangle.position.x == 0); + STATIC_CHECK(rectangle.position.y == 0); + STATIC_CHECK(rectangle.size.x == 0); + STATIC_CHECK(rectangle.size.y == 0); } SECTION("(left, top, width, height) constructor") { constexpr sf::Rect rectangle({1, 2}, {3, 4}); - STATIC_CHECK(rectangle.left == 1); - STATIC_CHECK(rectangle.top == 2); - STATIC_CHECK(rectangle.width == 3); - STATIC_CHECK(rectangle.height == 4); + STATIC_CHECK(rectangle.position.x == 1); + STATIC_CHECK(rectangle.position.y == 2); + STATIC_CHECK(rectangle.size.x == 3); + STATIC_CHECK(rectangle.size.y == 4); } SECTION("(Vector2, Vector2) constructor") @@ -43,10 +43,10 @@ TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float) constexpr sf::Vector2 dimension(3, 4); constexpr sf::Rect rectangle(position, dimension); - STATIC_CHECK(rectangle.left == 1); - STATIC_CHECK(rectangle.top == 2); - STATIC_CHECK(rectangle.width == 3); - STATIC_CHECK(rectangle.height == 4); + STATIC_CHECK(rectangle.position.x == 1); + STATIC_CHECK(rectangle.position.y == 2); + STATIC_CHECK(rectangle.size.x == 3); + STATIC_CHECK(rectangle.size.y == 4); } SECTION("Conversion constructor") @@ -54,10 +54,10 @@ TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float) constexpr sf::FloatRect sourceRectangle({1.0f, 2.0f}, {3.0f, 4.0f}); constexpr sf::IntRect rectangle(sourceRectangle); - STATIC_CHECK(rectangle.left == static_cast(sourceRectangle.left)); - STATIC_CHECK(rectangle.top == static_cast(sourceRectangle.top)); - STATIC_CHECK(rectangle.width == static_cast(sourceRectangle.width)); - STATIC_CHECK(rectangle.height == static_cast(sourceRectangle.height)); + STATIC_CHECK(rectangle.position.x == static_cast(sourceRectangle.position.x)); + STATIC_CHECK(rectangle.position.y == static_cast(sourceRectangle.position.y)); + STATIC_CHECK(rectangle.size.x == static_cast(sourceRectangle.size.x)); + STATIC_CHECK(rectangle.size.y == static_cast(sourceRectangle.size.y)); } } @@ -82,10 +82,10 @@ TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float) constexpr auto intersectionResult = rectangle.findIntersection(intersectingRectangle); STATIC_REQUIRE(intersectionResult.has_value()); - STATIC_CHECK(intersectionResult->top == 5); - STATIC_CHECK(intersectionResult->left == 5); - STATIC_CHECK(intersectionResult->width == 5); - STATIC_CHECK(intersectionResult->height == 5); + STATIC_CHECK(intersectionResult->position.x == 5); + STATIC_CHECK(intersectionResult->position.y == 5); + STATIC_CHECK(intersectionResult->size.x == 5); + STATIC_CHECK(intersectionResult->size.y == 5); constexpr sf::Rect nonIntersectingRectangle({-5, -5}, {5, 5}); STATIC_CHECK_FALSE(rectangle.findIntersection(nonIntersectingRectangle).has_value()); diff --git a/test/TestUtilities/GraphicsUtil.cpp b/test/TestUtilities/GraphicsUtil.cpp index 05ed0688d..0addfc64c 100644 --- a/test/TestUtilities/GraphicsUtil.cpp +++ b/test/TestUtilities/GraphicsUtil.cpp @@ -92,7 +92,7 @@ std::ostream& operator<<(std::ostream& os, const Rect& rect) { const auto flags = os.flags(); setStreamPrecision(os, std::numeric_limits::max_digits10); - os << "(left=" << rect.left << ", top=" << rect.top << ", width=" << rect.width << ", height=" << rect.height << ")"; + os << "(position=" << rect.position << ", size=" << rect.size << ")"; os.flags(flags); return os; } diff --git a/test/TestUtilities/GraphicsUtil.hpp b/test/TestUtilities/GraphicsUtil.hpp index 0ae41b31e..9e6ad685d 100644 --- a/test/TestUtilities/GraphicsUtil.hpp +++ b/test/TestUtilities/GraphicsUtil.hpp @@ -32,6 +32,5 @@ bool operator==(const sf::Transform& lhs, const Approx& rhs); template bool operator==(const sf::Rect& lhs, const Approx>& rhs) { - return lhs.left == Approx(rhs.value.left) && lhs.top == Approx(rhs.value.top) && - lhs.width == Approx(rhs.value.width) && lhs.height == Approx(rhs.value.height); + return lhs.position == Approx(rhs.value.position) && lhs.size == Approx(rhs.value.size); }