From f90d3239e512bf35d5699a7d3fb4f6e1b6794e94 Mon Sep 17 00:00:00 2001 From: Juliano Leal Goncalves Date: Sun, 27 Jun 2021 00:28:36 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20'Center()'=20method=20on=20'R?= =?UTF-8?q?ectangle'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/engine/rectangle.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/engine/rectangle.hpp b/Source/engine/rectangle.hpp index 0dcc5b312..7a4c46f6d 100644 --- a/Source/engine/rectangle.hpp +++ b/Source/engine/rectangle.hpp @@ -16,6 +16,14 @@ struct Rectangle { && point.y >= this->position.y && point.y < (this->position.y + this->size.height); } + + /** + * @brief Computes the center of this rectangle in integer coordinates. Values are truncated towards zero. + */ + constexpr Point Center() const + { + return position + Displacement(size / 2); + } }; } // namespace devilution