diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 19f751cb5d..1b2d720e6d 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -103,20 +103,38 @@ static void PaintSessionAddPSToQuadrant(PaintSession& session, PaintStruct* ps) static constexpr bool ImageWithinDPI(const ScreenCoordsXY& imagePos, const G1Element& g1, const DrawPixelInfo& dpi) { - int32_t left = dpi.zoom_level.ApplyInversedTo(imagePos.x + g1.x_offset); - int32_t bottom = dpi.zoom_level.ApplyInversedTo(imagePos.y + g1.y_offset); + int32_t left = imagePos.x + g1.x_offset; + int32_t bottom = imagePos.y + g1.y_offset; - int32_t right = dpi.zoom_level.ApplyInversedTo(imagePos.x + g1.x_offset + g1.width); - int32_t top = dpi.zoom_level.ApplyInversedTo(imagePos.y + g1.y_offset + g1.height); + int32_t right = left + g1.width; + int32_t top = bottom + g1.height; - if (right <= dpi.ScreenX()) - return false; - if (top <= dpi.ScreenY()) - return false; - if (left >= dpi.ScreenX() + dpi.ScreenWidth()) - return false; - if (bottom >= dpi.ScreenY() + dpi.ScreenHeight()) - return false; + // mber: It is possible to use only the bottom else block here if you change <= and >= to simply < and >. + // However, since this is used to cull paint structs, I'd prefer to keep the condition strict and calculate + // the culling differently for minifying and magnifying. + auto zoom = dpi.zoom_level; + if (zoom > ZoomLevel{ 0 }) + { + if (right <= dpi.WorldX()) + return false; + if (top <= dpi.WorldY()) + return false; + if (left >= dpi.WorldX() + dpi.WorldWidth()) + return false; + if (bottom >= dpi.WorldY() + dpi.WorldHeight()) + return false; + } + else + { + if (zoom.ApplyInversedTo(right) <= dpi.ScreenX()) + return false; + if (zoom.ApplyInversedTo(top) <= dpi.ScreenY()) + return false; + if (zoom.ApplyInversedTo(left) >= dpi.ScreenX() + dpi.ScreenWidth()) + return false; + if (zoom.ApplyInversedTo(bottom) >= dpi.ScreenY() + dpi.ScreenHeight()) + return false; + } return true; }