From b5195f77c4f5bbdd5bc57fc92b18079f0f25331a Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Tue, 30 Jun 2020 09:44:28 -0300 Subject: [PATCH] Reuse Rectangle definitions for ScreenRect and MapRange --- src/openrct2/world/Location.hpp | 46 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 54c0a02eb1..a239feef95 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -647,25 +647,31 @@ template struct CoordsRange } }; +template struct RectRange : public CoordsRange +{ + using CoordsRange::CoordsRange; + + RectRange(int32_t left, int32_t top, int32_t right, int32_t bottom) + : RectRange({ left, top }, { right, bottom }) + { + } + + RectRange(const T& leftTop, const T& rightBottom) + : CoordsRange(leftTop, rightBottom) + { + // Make sure it's a rectangle + assert(std::abs(CoordsRange::GetLeft() - CoordsRange::GetRight()) > 0); + assert(std::abs(CoordsRange::GetTop() - CoordsRange::GetBottom()) > 0); + } +}; + /** * Represents a rectangular range of the map using regular coordinates (32 per tile). */ -struct MapRange : public CoordsRange +struct MapRange : public RectRange { - using CoordsRange::CoordsRange; - MapRange(int32_t left, int32_t top, int32_t right, int32_t bottom) - : MapRange({ left, top }, { right, bottom }) - { - } - - MapRange(const CoordsXY& leftTop, const CoordsXY& rightBottom) - : CoordsRange(leftTop, rightBottom) - { - // Make sure it's a rectangle - assert(std::abs(GetLeft() - GetRight()) > 0); - assert(std::abs(GetTop() - GetBottom()) > 0); - } + using RectRange::RectRange; MapRange Normalise() const { @@ -694,16 +700,10 @@ struct ScreenLine : public CoordsRange * Represents a rectangular range on the screen */ -struct ScreenRect : public CoordsRange +struct ScreenRect : public RectRange { - ScreenRect(const ScreenCoordsXY& leftTop, const ScreenCoordsXY& rightBottom) - : CoordsRange(leftTop, rightBottom) - { - // Make sure it's a rectangle - assert(std::abs(GetLeft() - GetRight()) > 0); - assert(std::abs(GetTop() - GetBottom()) > 0); - } - + using RectRange::RectRange; + int32_t GetWidth() const { return RightBottom.x - LeftTop.x;