From c91757308dfb6f109c9e31149dab7dbe6365042c Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Mon, 11 Dec 2023 07:47:54 +0100 Subject: [PATCH] figments: surface: handle swapped start/end positions --- lib/Figments/Surface.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Figments/Surface.cpp b/lib/Figments/Surface.cpp index 5676f1d..d05a35d 100644 --- a/lib/Figments/Surface.cpp +++ b/lib/Figments/Surface.cpp @@ -54,17 +54,20 @@ void Surface::paintShader(Surface::Shader shader) { PerfCounter _("paintShader"); - const uint16_t width = end.x - start.x + 1; - const uint16_t height = end.y - start.y + 1; + uint8_t startX = min(start.x, end.x); + uint8_t startY = min(start.y, end.y); + uint8_t endX = max(start.x, end.x); + uint8_t endY = max(start.y, end.y); + const uint16_t width = endX - startX + 1; + const uint16_t height = endY - startY + 1; const uint8_t xMod = 255 / width; const uint8_t yMod = 255 / height; for(auto x = 0; x < width; x++) { for(auto y = 0; y < height; y++) { - PhysicalCoordinates coords{x + start.x, y + start.y}; + PhysicalCoordinates coords{x + startX, y + startY}; VirtualCoordinates virtCoords{m_display->coordinateMapping()->physicalToVirtualCoords(coords)}; VirtualCoordinates surfaceCoords{xMod * x, yMod * y}; - //Log.notice("width=%d height=%d vx=%d vy=%d sx=%d sy=%d x=%d y=%d px=%d py=%d", width, height, start.x, start.y, x, y, coords.x, coords.y); - // 256 = 1.0 + //Log.notice("width=%d height=%d vx=%d vy=%d sx=%d sy=%d x=%d y=%d px=%d py=%d", width, height, startX, startY, x, y, coords.x, coords.y); // 256 = 1.0 // 128 = 0.0 // 0 = 1.0 shader(m_display->pixelAt(coords), virtCoords, coords, surfaceCoords);