Fixed rendering diagonal lines within a viewport

The drawing uses the origin of the viewport as the coordinate origin, so we only need to clip against the size of the viewport.

Also added a unit test to catch this case in the future
This commit is contained in:
Sam Lantinga 2024-01-19 16:28:00 -08:00
parent 8d9c7d8ebe
commit 6a00ae7e58
2 changed files with 50 additions and 6 deletions

View file

@ -2776,6 +2776,8 @@ static int RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, i
just want a basic safety against generating millions of points for
massive lines. */
GetRenderViewportInPixels(renderer, &viewport);
viewport.x = 0;
viewport.y = 0;
if (!SDL_GetRectAndLineIntersection(&viewport, &x1, &y1, &x2, &y2)) {
return 0;
}