From f725fff2dad526b55f3bc5386f54ef0d565f99ec Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 6 Jul 2020 09:42:11 -0300 Subject: [PATCH] Clarify CoordsRange-derived interface methods (#12127) --- src/openrct2/core/DataSerialiserTraits.h | 12 +++--- src/openrct2/drawing/NewDrawing.cpp | 10 ++--- src/openrct2/world/Location.hpp | 53 ++++++++++++++++-------- 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h index a05382668e..372fe18c98 100644 --- a/src/openrct2/core/DataSerialiserTraits.h +++ b/src/openrct2/core/DataSerialiserTraits.h @@ -401,10 +401,10 @@ template<> struct DataSerializerTraits { static void encode(IStream* stream, const MapRange& v) { - stream->WriteValue(ByteSwapBE(v.LeftTop.x)); - stream->WriteValue(ByteSwapBE(v.LeftTop.y)); - stream->WriteValue(ByteSwapBE(v.RightBottom.x)); - stream->WriteValue(ByteSwapBE(v.RightBottom.y)); + stream->WriteValue(ByteSwapBE(v.GetLeft())); + stream->WriteValue(ByteSwapBE(v.GetTop())); + stream->WriteValue(ByteSwapBE(v.GetRight())); + stream->WriteValue(ByteSwapBE(v.GetBottom())); } static void decode(IStream* stream, MapRange& v) { @@ -418,8 +418,8 @@ template<> struct DataSerializerTraits { char coords[128] = {}; snprintf( - coords, sizeof(coords), "MapRange(l = %d, t = %d, r = %d, b = %d)", v.LeftTop.x, v.LeftTop.y, v.RightBottom.x, - v.RightBottom.y); + coords, sizeof(coords), "MapRange(l = %d, t = %d, r = %d, b = %d)", v.GetLeft(), v.GetTop(), v.GetRight(), + v.GetBottom()); stream->Write(coords, strlen(coords)); } diff --git a/src/openrct2/drawing/NewDrawing.cpp b/src/openrct2/drawing/NewDrawing.cpp index 5cc8bbf952..c7cb46b193 100644 --- a/src/openrct2/drawing/NewDrawing.cpp +++ b/src/openrct2/drawing/NewDrawing.cpp @@ -227,23 +227,23 @@ void gfx_draw_dashed_line( constexpr int32_t precisionFactor = 1000; const int32_t dashedLineLength = std::hypot( - screenLine.GetRight() - screenLine.GetLeft(), screenLine.GetBottom() - screenLine.GetTop()); + screenLine.GetX2() - screenLine.GetX1(), screenLine.GetY2() - screenLine.GetY1()); const int32_t lineSegmentCount = dashedLineLength / dashedLineSegmentLength / 2; if (lineSegmentCount == 0) { return; } - const int32_t lineXDist = std::abs(screenLine.GetRight() - screenLine.GetLeft()); - const int32_t lineYDist = std::abs(screenLine.GetBottom() - screenLine.GetTop()); + const int32_t lineXDist = std::abs(screenLine.GetX2() - screenLine.GetX1()); + const int32_t lineYDist = std::abs(screenLine.GetY2() - screenLine.GetY1()); const int32_t dxPrecise = precisionFactor * lineXDist / lineSegmentCount / 2; const int32_t dyPrecise = precisionFactor * lineYDist / lineSegmentCount / 2; IDrawingContext* dc = drawingEngine->GetDrawingContext(dpi); for (int32_t i = 0, x, y; i < lineSegmentCount; ++i) { - x = screenLine.GetLeft() + dxPrecise * i * 2 / precisionFactor; - y = screenLine.GetTop() + dyPrecise * i * 2 / precisionFactor; + x = screenLine.GetX1() + dxPrecise * i * 2 / precisionFactor; + y = screenLine.GetY1() + dyPrecise * i * 2 / precisionFactor; dc->DrawLine(color, x, y, x + dxPrecise / precisionFactor, y + dyPrecise / precisionFactor); } } diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index bcdc06ddbd..c7567e14cf 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -614,35 +614,35 @@ struct TileCoordsXYZD : public TileCoordsXYZ */ template struct CoordsRange { - T LeftTop{ 0, 0 }; - T RightBottom{ 0, 0 }; + T Point1{ 0, 0 }; + T Point2{ 0, 0 }; - int32_t GetLeft() const + int32_t GetX1() const { - return LeftTop.x; + return Point1.x; } - int32_t GetTop() const + int32_t GetY1() const { - return LeftTop.y; + return Point1.y; } - int32_t GetRight() const + int32_t GetX2() const { - return RightBottom.x; + return Point2.x; } - int32_t GetBottom() const + int32_t GetY2() const { - return RightBottom.y; + return Point2.y; } CoordsRange() = default; - CoordsRange(int32_t left, int32_t top, int32_t right, int32_t bottom) - : CoordsRange({ left, top }, { right, bottom }) + CoordsRange(int32_t x1, int32_t y1, int32_t x2, int32_t y2) + : CoordsRange({ x1, y1 }, { x2, y2 }) { } - CoordsRange(const T& leftTop, const T& rightBottom) - : LeftTop(leftTop) - , RightBottom(rightBottom) + CoordsRange(const T& pointOne, const T& pointTwo) + : Point1(pointOne) + , Point2(pointTwo) { } }; @@ -651,6 +651,23 @@ template struct RectRange : public CoordsRange { using CoordsRange::CoordsRange; + int32_t GetLeft() const + { + return CoordsRange::GetX1(); + } + int32_t GetTop() const + { + return CoordsRange::GetY1(); + } + int32_t GetRight() const + { + return CoordsRange::GetX2(); + } + int32_t GetBottom() const + { + return CoordsRange::GetY2(); + } + RectRange(int32_t left, int32_t top, int32_t right, int32_t bottom) : RectRange({ left, top }, { right, bottom }) { @@ -689,7 +706,7 @@ struct ScreenLine : public CoordsRange : CoordsRange(leftTop, rightBottom) { // Make sure one of the point coords change - assert((std::abs(GetLeft() - GetRight()) > 0) || (std::abs(GetTop() - GetBottom()) > 0)); + assert((std::abs(GetX1() - GetX2()) > 0) || (std::abs(GetY1() - GetY2()) > 0)); } }; @@ -703,11 +720,11 @@ struct ScreenRect : public RectRange int32_t GetWidth() const { - return RightBottom.x - LeftTop.x; + return GetRight() - GetLeft(); } int32_t GetHeight() const { - return RightBottom.y - LeftTop.y; + return GetBottom() - GetTop(); } bool Contains(const ScreenCoordsXY& coords) const {