| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0d4c34c commit d3a79e6
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -109,7 +109,7 @@ class Rect | |||
| 109 | 109 | /// | |
| 110 | 110 | /// \return Position of rectangle | |
| 111 | 111 | /// | |
| 112 | - /// \see getSize | ||
| 112 | + /// \see getSize, getCenter | ||
| 113 | 113 | /// | |
| 114 | 114 | //////////////////////////////////////////////////////////// | |
| 115 | 115 | constexpr Vector2<T> getPosition() const; | |
@@ -119,11 +119,21 @@ class Rect | |||
| 119 | 119 | /// | |
| 120 | 120 | /// \return Size of rectangle | |
| 121 | 121 | /// | |
| 122 | - /// \see getPosition | ||
| 122 | + /// \see getPosition, getCenter | ||
| 123 | 123 | /// | |
| 124 | 124 | //////////////////////////////////////////////////////////// | |
| 125 | 125 | constexpr Vector2<T> getSize() const; | |
| 126 | 126 | ||
| 127 | + //////////////////////////////////////////////////////////// | ||
| 128 | + /// \brief Get the position of the center of the rectangle | ||
| 129 | + /// | ||
| 130 | + /// \return Center of rectangle | ||
| 131 | + /// | ||
| 132 | + /// \see getSize, getPosition | ||
| 133 | + /// | ||
| 134 | + //////////////////////////////////////////////////////////// | ||
| 135 | + constexpr Vector2<T> getCenter() const; | ||
| 136 | + | ||
| 127 | 137 | //////////////////////////////////////////////////////////// | |
| 128 | 138 | // Member data | |
| 129 | 139 | //////////////////////////////////////////////////////////// | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,6 +127,14 @@ constexpr Vector2<T> Rect<T>::getSize() const | |||
| 127 | 127 | } | |
| 128 | 128 | ||
| 129 | 129 | ||
| 130 | + //////////////////////////////////////////////////////////// | ||
| 131 | + template <typename T> | ||
| 132 | + constexpr Vector2<T> Rect<T>::getCenter() const | ||
| 133 | + { | ||
| 134 | + return getPosition() + getSize() / T{2}; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + | ||
| 130 | 138 | //////////////////////////////////////////////////////////// | |
| 131 | 139 | template <typename T> | |
| 132 | 140 | constexpr bool operator==(const Rect<T>& left, const Rect<T>& right) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -221,7 +221,7 @@ void Shape::update() | |||
| 221 | 221 | m_insideBounds = m_vertices.getBounds(); | |
| 222 | 222 | ||
| 223 | 223 | // Compute the center and make it the first vertex | |
| 224 | - m_vertices[0].position = m_insideBounds.getPosition() + m_insideBounds.getSize() / 2.f; | ||
| 224 | + m_vertices[0].position = m_insideBounds.getCenter(); | ||
| 225 | 225 | ||
| 226 | 226 | // Color | |
| 227 | 227 | updateFillColors(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,7 +90,7 @@ void View::setViewport(const FloatRect& viewport) | |||
| 90 | 90 | //////////////////////////////////////////////////////////// | |
| 91 | 91 | void View::reset(const FloatRect& rectangle) | |
| 92 | 92 | { | |
| 93 | - m_center = rectangle.getPosition() + rectangle.getSize() / 2.f; | ||
| 93 | + m_center = rectangle.getCenter(); | ||
| 94 | 94 | m_size = rectangle.getSize(); | |
| 95 | 95 | m_rotation = Angle::Zero; | |
| 96 | 96 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,6 +103,12 @@ TEST_CASE("[Graphics] sf::Rect") | |||
| 103 | 103 | STATIC_CHECK(sf::IntRect({1, 2}, {3, 4}).getSize() == sf::Vector2i(3, 4)); | |
| 104 | 104 | } | |
| 105 | 105 | ||
| 106 | + SECTION("getCenter()") | ||
| 107 | + { | ||
| 108 | + STATIC_CHECK(sf::IntRect({}, {}).getCenter() == sf::Vector2i()); | ||
| 109 | + STATIC_CHECK(sf::IntRect({1, 2}, {4, 6}).getCenter() == sf::Vector2i(3, 5)); | ||
| 110 | + } | ||
| 111 | + | ||
| 106 | 112 | SECTION("Operators") | |
| 107 | 113 | { | |
| 108 | 114 | SECTION("operator==") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments