Skip to content

Commit

Permalink
Fix gaps in aaline
Browse files Browse the repository at this point in the history
  • Loading branch information
mzivic7 committed Oct 9, 2024
1 parent 7a29397 commit ef6e656
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src_c/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ static void
draw_line(SDL_Surface *surf, int x1, int y1, int x2, int y2, Uint32 color,
int *drawn_area);
void
line_width_corners(float from_x, float from_y, float to_x, float to_y,
int width, float *x1, float *y1, float *x2, float *y2,
float *x3, float *y3, float *x4, float *y4);
line_width_corners(int from_x, int from_y, int to_x, int to_y, int width,
float *x1, float *y1, float *x2, float *y2, float *x3,
float *y3, float *x4, float *y4);
static void
draw_aaline(SDL_Surface *surf, Uint32 color, float startx, float starty,
float endx, float endy, int *drawn_area,
Expand Down Expand Up @@ -172,8 +172,8 @@ aaline(PyObject *self, PyObject *arg, PyObject *kwargs)

if (width > 1) {
float x1, y1, x2, y2, x3, y3, x4, y4;
line_width_corners(startx, starty, endx, endy, width, &x1, &y1, &x2,
&y2, &x3, &y3, &x4, &y4);
line_width_corners((int)startx, (int)starty, (int)endx, (int)endy,
width, &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
draw_line_width(surf, color, (int)startx, (int)starty, (int)endx,
(int)endy, width, drawn_area);
draw_aaline(surf, color, x1, y1, x2, y2, drawn_area, 0, 0, 0);
Expand Down Expand Up @@ -1869,14 +1869,14 @@ draw_line_width(SDL_Surface *surf, Uint32 color, int x1, int y1, int x2,
// Calculates 4 points, representing corners of draw_line_width()
// first two points assemble left line and second two - right line
void
line_width_corners(float from_x, float from_y, float to_x, float to_y,
int width, float *x1, float *y1, float *x2, float *y2,
float *x3, float *y3, float *x4, float *y4)
line_width_corners(int from_x, int from_y, int to_x, int to_y, int width,
float *x1, float *y1, float *x2, float *y2, float *x3,
float *y3, float *x4, float *y4)
{
float aa_width = (float)width / 2;
float extra_width = (1.0f - (width % 2)) / 2;
// "steep" is same as "xinc" in draw_line_width
int steep = abs((int)to_x - (int)from_x) <= abs((int)to_y - (int)from_y);
int steep = abs(to_x - from_x) <= abs(to_y - from_y);

if (steep) {
*x1 = from_x + extra_width + aa_width;
Expand Down

0 comments on commit ef6e656

Please sign in to comment.