Skip to content

Commit 3435256

Browse files
authored
Merge pull request #3144 from mzivic7/fix_int_aalines_pixel
Missing pixels in `aalines` when using integer coordinates
2 parents 76adc02 + cb78167 commit 3435256

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src_c/draw.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ aalines(PyObject *self, PyObject *arg, PyObject *kwargs)
283283
float x, y;
284284
int l, t;
285285
int extra_px;
286+
int disable_endpoints;
286287
int steep_prev;
287288
int steep_curr;
288289
PyObject *blend = NULL;
@@ -387,13 +388,15 @@ aalines(PyObject *self, PyObject *arg, PyObject *kwargs)
387388
fabs(pts_prev[2] - pts_prev[0]) < fabs(pts_prev[3] - pts_prev[1]);
388389
steep_curr = fabs(xlist[2] - pts[2]) < fabs(ylist[2] - pts[1]);
389390
extra_px = steep_prev > steep_curr;
391+
disable_endpoints =
392+
!((roundf(pts[2]) == pts[2]) && (roundf(pts[3]) == pts[3]));
390393
if (closed) {
391-
draw_aaline(surf, color, pts[0], pts[1], pts[2], pts[3], drawn_area, 1,
392-
1, extra_px);
394+
draw_aaline(surf, color, pts[0], pts[1], pts[2], pts[3], drawn_area,
395+
disable_endpoints, disable_endpoints, extra_px);
393396
}
394397
else {
395398
draw_aaline(surf, color, pts[0], pts[1], pts[2], pts[3], drawn_area, 0,
396-
1, extra_px);
399+
disable_endpoints, extra_px);
397400
}
398401

399402
for (loop = 2; loop < length - 1; ++loop) {
@@ -408,12 +411,14 @@ aalines(PyObject *self, PyObject *arg, PyObject *kwargs)
408411
fabs(pts_prev[2] - pts_prev[0]) < fabs(pts_prev[3] - pts_prev[1]);
409412
steep_curr = fabs(pts[2] - pts[0]) < fabs(pts[3] - pts[1]);
410413
extra_px = steep_prev != steep_curr;
414+
disable_endpoints =
415+
!((roundf(pts[2]) == pts[2]) && (roundf(pts[3]) == pts[3]));
411416
pts_prev[0] = pts[0];
412417
pts_prev[1] = pts[1];
413418
pts_prev[2] = pts[2];
414419
pts_prev[3] = pts[3];
415-
draw_aaline(surf, color, pts[0], pts[1], pts[2], pts[3], drawn_area, 1,
416-
1, extra_px);
420+
draw_aaline(surf, color, pts[0], pts[1], pts[2], pts[3], drawn_area,
421+
disable_endpoints, disable_endpoints, extra_px);
417422
}
418423

419424
/* Last line - if open, add endpoint pixels. */
@@ -425,17 +430,19 @@ aalines(PyObject *self, PyObject *arg, PyObject *kwargs)
425430
fabs(pts_prev[2] - pts_prev[0]) < fabs(pts_prev[3] - pts_prev[1]);
426431
steep_curr = fabs(pts[2] - pts[0]) < fabs(pts[3] - pts[1]);
427432
extra_px = steep_prev != steep_curr;
433+
disable_endpoints =
434+
!((roundf(pts[2]) == pts[2]) && (roundf(pts[3]) == pts[3]));
428435
pts_prev[0] = pts[0];
429436
pts_prev[1] = pts[1];
430437
pts_prev[2] = pts[2];
431438
pts_prev[3] = pts[3];
432439
if (closed) {
433-
draw_aaline(surf, color, pts[0], pts[1], pts[2], pts[3], drawn_area, 1,
434-
1, extra_px);
440+
draw_aaline(surf, color, pts[0], pts[1], pts[2], pts[3], drawn_area,
441+
disable_endpoints, disable_endpoints, extra_px);
435442
}
436443
else {
437-
draw_aaline(surf, color, pts[0], pts[1], pts[2], pts[3], drawn_area, 1,
438-
0, extra_px);
444+
draw_aaline(surf, color, pts[0], pts[1], pts[2], pts[3], drawn_area,
445+
disable_endpoints, 0, extra_px);
439446
}
440447

441448
if (closed && length > 2) {
@@ -447,8 +454,10 @@ aalines(PyObject *self, PyObject *arg, PyObject *kwargs)
447454
fabs(pts_prev[2] - pts_prev[0]) < fabs(pts_prev[3] - pts_prev[1]);
448455
steep_curr = fabs(pts[2] - pts[0]) < fabs(pts[3] - pts[1]);
449456
extra_px = steep_prev != steep_curr;
450-
draw_aaline(surf, color, pts[0], pts[1], pts[2], pts[3], drawn_area, 1,
451-
1, extra_px);
457+
disable_endpoints =
458+
!((roundf(pts[2]) == pts[2]) && (roundf(pts[3]) == pts[3]));
459+
draw_aaline(surf, color, pts[0], pts[1], pts[2], pts[3], drawn_area,
460+
disable_endpoints, disable_endpoints, extra_px);
452461
}
453462

454463
PyMem_Free(xlist);

0 commit comments

Comments
 (0)