From b1db28258c33f230820d994d41d745ea175b21f6 Mon Sep 17 00:00:00 2001 From: Chris Marchesi Date: Wed, 24 Apr 2024 11:11:33 -0700 Subject: [PATCH] FillPlotter: drop incomplete polygons There may be situations where a polygon is incomplete (only 2 or less corners plotted). We can just drop these cases. This will get unit tested with the rest of the work in #15. --- src/internal/FillPlotter.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/internal/FillPlotter.zig b/src/internal/FillPlotter.zig index e2c845b..0056c2f 100644 --- a/src/internal/FillPlotter.zig +++ b/src/internal/FillPlotter.zig @@ -31,7 +31,16 @@ pub fn plot( for (nodes.items, 0..) |node, i| { switch (node) { .move_to => |n| { - if (current_polygon) |poly| try result.append(poly); + if (current_polygon) |poly| { + // Only append this polygon if it's useful (has more than 2 + // corners). Otherwise, get rid of it. + if (poly.corners.len > 2) { + try result.append(poly); + } else { + poly.deinit(); + current_polygon = null; + } + } // Check if this is the last node, and no-op if it is, as this // is the auto-added move_to node that is given after