mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Add sf::Rect<T>::getCenter()
This commit is contained in:
parent
0d4c34cf9b
commit
d3a79e6282
@ -109,7 +109,7 @@ public:
|
||||
///
|
||||
/// \return Position of rectangle
|
||||
///
|
||||
/// \see getSize
|
||||
/// \see getSize, getCenter
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
constexpr Vector2<T> getPosition() const;
|
||||
@ -119,11 +119,21 @@ public:
|
||||
///
|
||||
/// \return Size of rectangle
|
||||
///
|
||||
/// \see getPosition
|
||||
/// \see getPosition, getCenter
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
constexpr Vector2<T> getSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the position of the center of the rectangle
|
||||
///
|
||||
/// \return Center of rectangle
|
||||
///
|
||||
/// \see getSize, getPosition
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
constexpr Vector2<T> getCenter() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -127,6 +127,14 @@ constexpr Vector2<T> Rect<T>::getSize() const
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
constexpr Vector2<T> Rect<T>::getCenter() const
|
||||
{
|
||||
return getPosition() + getSize() / T{2};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
constexpr bool operator==(const Rect<T>& left, const Rect<T>& right)
|
||||
|
@ -221,7 +221,7 @@ void Shape::update()
|
||||
m_insideBounds = m_vertices.getBounds();
|
||||
|
||||
// Compute the center and make it the first vertex
|
||||
m_vertices[0].position = m_insideBounds.getPosition() + m_insideBounds.getSize() / 2.f;
|
||||
m_vertices[0].position = m_insideBounds.getCenter();
|
||||
|
||||
// Color
|
||||
updateFillColors();
|
||||
|
@ -90,7 +90,7 @@ void View::setViewport(const FloatRect& viewport)
|
||||
////////////////////////////////////////////////////////////
|
||||
void View::reset(const FloatRect& rectangle)
|
||||
{
|
||||
m_center = rectangle.getPosition() + rectangle.getSize() / 2.f;
|
||||
m_center = rectangle.getCenter();
|
||||
m_size = rectangle.getSize();
|
||||
m_rotation = Angle::Zero;
|
||||
|
||||
|
@ -103,6 +103,12 @@ TEST_CASE("[Graphics] sf::Rect")
|
||||
STATIC_CHECK(sf::IntRect({1, 2}, {3, 4}).getSize() == sf::Vector2i(3, 4));
|
||||
}
|
||||
|
||||
SECTION("getCenter()")
|
||||
{
|
||||
STATIC_CHECK(sf::IntRect({}, {}).getCenter() == sf::Vector2i());
|
||||
STATIC_CHECK(sf::IntRect({1, 2}, {4, 6}).getCenter() == sf::Vector2i(3, 5));
|
||||
}
|
||||
|
||||
SECTION("Operators")
|
||||
{
|
||||
SECTION("operator==")
|
||||
|
Loading…
Reference in New Issue
Block a user