triangleraster
triangleraster copied to clipboard
Failing on triangles with both short sides on the left
Hey Josh,
thanks a lot for the code, I'm using it to rasterize triangles in a Delaunay triangulation. I discovered an issue in the case of triangles with both short sides on the left; the spans in this case reach from x1 to x2, where x1 > x2 and so no pixels are drawn in:
https://github.com/joshb/triangleraster/blob/263d823a5f262c512181b4ecbb7a0188178b52a2/Rasterizer.cpp#L118
The failure cases are exemplified in the image below (black triangles: failure case, gray: successfully rasterized)

I've fixed it by simply swapping the range limits if x2>x1.
Hey there,
That's cool! Glad to hear you found it useful. It's been a while since I worked on this, but it looks like the Span constructor ensures that X1 is less than X2, so I think that case should already be handled in the original code (it probably does make more sense to do the swapping when drawing the span, though)