From 2fa488cfa9d28916cb38d663a1d08871bcf2b847 Mon Sep 17 00:00:00 2001 From: MacDue Date: Tue, 2 Jan 2024 20:33:34 +0000 Subject: [PATCH] LibGfx: Skip horizontal edges in path rasterizer Only the vertical parts of edges are plotted (then accumulated horizontally). Fully horizontal edges won't be plotted (and just result in NaNs). --- Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp b/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp index e878d70bb1..6a39cfec27 100644 --- a/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp +++ b/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp @@ -70,16 +70,19 @@ static Vector prepare_edges(ReadonlySpan lines, unsigne if (max_y < top_clip) continue; - float start_x = p0.x(); - float end_x = p1.x(); - + auto start_x = p0.x(); + auto end_x = p1.x(); auto dx = end_x - start_x; auto dy = max_y - min_y; + + if (dy == 0) + continue; + auto dxdy = dx / dy; // Trim off the non-visible portions of the edge. if (min_y < top_clip) { - start_x += (top_clip - min_y) * dxdy; + start_x += dxdy * (top_clip - min_y); min_y = top_clip; } if (max_y > bottom_clip) {