All seemed well, I found a few things online which (poorly) explained how to solve the single point/maxima issues and got that working. Bezier curves and straight lines work as you'd expect really. Here's an example screenshot of a non-simple path.
However, I then tried to draw a simple left/right arrow like below (this is from Photoshop, not a screenshot) and it stopped working. The shape is a single polygon with lines between each vertex as you'd expect it to be.
Here’s a diagram showing what the scanline should be doing. Green represents pixels where it will start filling, red where it will stop filling and orange where it will start and stop on the same pixel (i.e. it will only fill that one pixel).
However, everything I try messes up, here's what ends up happening (I can't show what it renders because it just crashes).
The above diagram will produce an error because on line 3 and line 5 there are an odd number of start/stop points, so it will draw between x = 1 and x = 4, and then start drawing again at x = 6, but it doesn't have an end point. The reason for this is at the intersection where the triangle section meets the rectangle it places a point as it’s a vertex with a change in slope.
When I plot the the points of a line the first pixel is ignored unless it’s a maxima (orange pixels), which is what most things online say to do. Hence, only one point is made at the intersection between the triangle section and rectangle.
If I make intersections with horizontal lines always place a start/stop point (orange) it draws correctly with the below points.
While this works for a right arrow, if I then change the shape to, for example, a left arrow it then breaks again.
Essentially, it in situations where the right angle is the first pixel it needs to start the scanline, but in situations where it's between and start and end point it needs to be ignored. Using the slopes alone this doesn't work, I can't tell if it's a convex or concave. Every way I can think of to get around this seems super hacky and specific and probably breaks something else, so does does anyone have any ideas, documents or code which might help?
I'm quite happy to completely redo the code, but it will need to support straight lines and bezier curves.
Here's the current code: https://github.com/oeed/Silica/blob/828fafbefe871a31052c93b6b0f29f18bf4f8897/src/classes/Graphics/Path.lua#L294