Remove Rect getPosition and getSize methods

This commit is contained in:
kimci86 2024-06-05 22:26:02 +02:00 committed by Vittorio Romeo
parent 7e5ed78219
commit c371bc6816
7 changed files with 7 additions and 56 deletions

View File

@ -104,26 +104,6 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr std::optional<Rect<T>> findIntersection(const Rect<T>& rectangle) const; constexpr std::optional<Rect<T>> findIntersection(const Rect<T>& rectangle) const;
////////////////////////////////////////////////////////////
/// \brief Get the position of the rectangle's top-left corner
///
/// \return Position of rectangle
///
/// \see getSize, getCenter
///
////////////////////////////////////////////////////////////
constexpr Vector2<T> getPosition() const;
////////////////////////////////////////////////////////////
/// \brief Get the size of the rectangle
///
/// \return Size of rectangle
///
/// \see getPosition, getCenter
///
////////////////////////////////////////////////////////////
constexpr Vector2<T> getSize() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the position of the center of the rectangle /// \brief Get the position of the center of the rectangle
/// ///

View File

@ -110,27 +110,11 @@ constexpr std::optional<Rect<T>> Rect<T>::findIntersection(const Rect<T>& rectan
} }
////////////////////////////////////////////////////////////
template <typename T>
constexpr Vector2<T> Rect<T>::getPosition() const
{
return Vector2<T>(position.x, position.y);
}
////////////////////////////////////////////////////////////
template <typename T>
constexpr Vector2<T> Rect<T>::getSize() const
{
return Vector2<T>(size.x, size.y);
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> template <typename T>
constexpr Vector2<T> Rect<T>::getCenter() const constexpr Vector2<T> Rect<T>::getCenter() const
{ {
return getPosition() + getSize() / T{2}; return position + size / T{2};
} }

View File

@ -308,7 +308,7 @@ Vector2f RenderTarget::mapPixelToCoords(const Vector2i& point, const View& view)
// First, convert from viewport coordinates to homogeneous coordinates // First, convert from viewport coordinates to homogeneous coordinates
const FloatRect viewport = FloatRect(getViewport(view)); const FloatRect viewport = FloatRect(getViewport(view));
const Vector2f normalized = Vector2f(-1, 1) + 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 // Then transform by the inverse of the view matrix
return view.getInverseTransform().transformPoint(normalized); return view.getInverseTransform().transformPoint(normalized);
@ -330,8 +330,8 @@ Vector2i RenderTarget::mapCoordsToPixel(const Vector2f& point, const View& view)
// Then convert to viewport coordinates // Then convert to viewport coordinates
const FloatRect viewport = FloatRect(getViewport(view)); const FloatRect viewport = FloatRect(getViewport(view));
return Vector2i((normalized.cwiseMul({1, -1}) + sf::Vector2f(1, 1)).cwiseDiv({2, 2}).cwiseMul(viewport.getSize()) + return Vector2i((normalized.cwiseMul({1, -1}) + sf::Vector2f(1, 1)).cwiseDiv({2, 2}).cwiseMul(viewport.size) +
viewport.getPosition()); viewport.position);
} }

View File

@ -273,8 +273,7 @@ void Shape::updateTexCoords()
const float yratio = m_insideBounds.size.y > 0 const float yratio = m_insideBounds.size.y > 0
? (m_vertices[i].position.y - m_insideBounds.position.y) / m_insideBounds.size.y ? (m_vertices[i].position.y - m_insideBounds.position.y) / m_insideBounds.size.y
: 0; : 0;
m_vertices[i].texCoords = convertedTextureRect.getPosition() + m_vertices[i].texCoords = convertedTextureRect.position + convertedTextureRect.size.cwiseMul({xratio, yratio});
convertedTextureRect.getSize().cwiseMul({xratio, yratio});
} }
} }

View File

@ -330,7 +330,7 @@ std::optional<Texture> Texture::loadFromImage(const Image& image, bool sRgb, con
rectangle.size.y = std::min(rectangle.size.y, height - rectangle.position.y); rectangle.size.y = std::min(rectangle.size.y, height - rectangle.position.y);
// Create the texture and upload the pixels // 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; const TransientContextLock lock;

View File

@ -34,7 +34,7 @@
namespace sf 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)
{ {
} }

View File

@ -91,18 +91,6 @@ TEMPLATE_TEST_CASE("[Graphics] sf::Rect", "", int, float)
STATIC_CHECK_FALSE(rectangle.findIntersection(nonIntersectingRectangle).has_value()); STATIC_CHECK_FALSE(rectangle.findIntersection(nonIntersectingRectangle).has_value());
} }
SECTION("getPosition()")
{
STATIC_CHECK(sf::Rect<TestType>({}, {}).getPosition() == sf::Vector2<TestType>());
STATIC_CHECK(sf::Rect<TestType>({1, 2}, {3, 4}).getPosition() == sf::Vector2<TestType>(1, 2));
}
SECTION("getSize()")
{
STATIC_CHECK(sf::Rect<TestType>({}, {}).getSize() == sf::Vector2<TestType>());
STATIC_CHECK(sf::Rect<TestType>({1, 2}, {3, 4}).getSize() == sf::Vector2<TestType>(3, 4));
}
SECTION("getCenter()") SECTION("getCenter()")
{ {
STATIC_CHECK(sf::Rect<TestType>({}, {}).getCenter() == sf::Vector2<TestType>()); STATIC_CHECK(sf::Rect<TestType>({}, {}).getCenter() == sf::Vector2<TestType>());