diff --git a/src/openrct2-ui/interface/Graph.cpp b/src/openrct2-ui/interface/Graph.cpp index 19e876f07d..3435b2f9db 100644 --- a/src/openrct2-ui/interface/Graph.cpp +++ b/src/openrct2-ui/interface/Graph.cpp @@ -189,41 +189,6 @@ struct FinancialTooltipInfo const money32 money{}; }; -struct ScreenRect -{ - const ScreenCoordsXY LeftTop; - const ScreenCoordsXY RightBottom; - - int32_t GetLeft() const - { - return LeftTop.x; - } - int32_t GetTop() const - { - return LeftTop.y; - } - int32_t GetRight() const - { - return RightBottom.x; - } - int32_t GetBottom() const - { - return RightBottom.y; - } - int32_t GetWidth() const - { - return RightBottom.x - LeftTop.x; - } - int32_t GetHeight() const - { - return RightBottom.y - LeftTop.y; - } - bool Contains(const ScreenCoordsXY& coords) const - { - return coords.x >= GetLeft() && coords.x <= GetRight() && coords.y >= GetTop() && coords.y <= GetBottom(); - } -}; - static constexpr auto CHART_MAX_DATA_COUNT = 64; static constexpr auto CHART_MAX_INDEX = CHART_MAX_DATA_COUNT - 1; static constexpr auto CHART_DATA_WIDTH = 6; diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 734a5f6cee..a239feef95 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -610,12 +610,12 @@ struct TileCoordsXYZD : public TileCoordsXYZ }; /** - * Represents a rectangular range of the map using regular coordinates (32 per tile). + * Represents a range of the map using regular coordinates. */ -struct MapRange +template struct CoordsRange { - CoordsXY LeftTop; - CoordsXY RightBottom; + T LeftTop{ 0, 0 }; + T RightBottom{ 0, 0 }; int32_t GetLeft() const { @@ -634,15 +634,44 @@ struct MapRange return RightBottom.y; } - MapRange() - : MapRange(0, 0, 0, 0) + CoordsRange() = default; + CoordsRange(int32_t left, int32_t top, int32_t right, int32_t bottom) + : CoordsRange({ left, top }, { right, bottom }) { } - MapRange(int32_t left, int32_t top, int32_t right, int32_t bottom) - : LeftTop(left, top) - , RightBottom(right, bottom) + + CoordsRange(const T& leftTop, const T& rightBottom) + : LeftTop(leftTop) + , RightBottom(rightBottom) { } +}; + +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 RectRange +{ + using RectRange::RectRange; MapRange Normalise() const { @@ -652,3 +681,39 @@ struct MapRange return result; } }; + +/** + * Represents a line on the screen + */ + +struct ScreenLine : public CoordsRange +{ + ScreenLine(const ScreenCoordsXY& leftTop, const ScreenCoordsXY& rightBottom) + : CoordsRange(leftTop, rightBottom) + { + // Make sure one of the point coords change + assert((std::abs(GetLeft() - GetRight()) > 0) || (std::abs(GetTop() - GetBottom()) > 0)); + } +}; + +/** + * Represents a rectangular range on the screen + */ + +struct ScreenRect : public RectRange +{ + using RectRange::RectRange; + + int32_t GetWidth() const + { + return RightBottom.x - LeftTop.x; + } + int32_t GetHeight() const + { + return RightBottom.y - LeftTop.y; + } + bool Contains(const ScreenCoordsXY& coords) const + { + return coords.x >= GetLeft() && coords.x <= GetRight() && coords.y >= GetTop() && coords.y <= GetBottom(); + } +};