@@ -450,7 +450,8 @@ polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill, hline_handler h
450
450
int edge_count = 0 ;
451
451
int ymin = im -> ysize - 1 ;
452
452
int ymax = 0 ;
453
- int i ;
453
+ int i , j , k ;
454
+ float adjacent_line_x , adjacent_line_x_other_edge ;
454
455
455
456
if (n <= 0 ) {
456
457
return 0 ;
@@ -493,16 +494,48 @@ polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill, hline_handler h
493
494
return -1 ;
494
495
}
495
496
for (; ymin <= ymax ; ymin ++ ) {
496
- int j = 0 ;
497
+ j = 0 ;
497
498
for (i = 0 ; i < edge_count ; i ++ ) {
498
499
Edge * current = edge_table [i ];
499
500
if (ymin >= current -> ymin && ymin <= current -> ymax ) {
500
501
xx [j ++ ] = (ymin - current -> y0 ) * current -> dx + current -> x0 ;
501
- }
502
- /* Needed to draw consistent polygons */
503
- if (ymin == current -> ymax && ymin < ymax ) {
504
- xx [j ] = xx [j - 1 ];
505
- j ++ ;
502
+
503
+ if (ymin == current -> ymax && ymin < ymax ) {
504
+ // Needed to draw consistent polygons
505
+ xx [j ] = xx [j - 1 ];
506
+ j ++ ;
507
+ } else if (current -> dx != 0 && roundf (xx [j - 1 ]) == xx [j - 1 ]) {
508
+ // Connect discontiguous corners
509
+ for (k = 0 ; k < i ; k ++ ) {
510
+ Edge * other_edge = edge_table [k ];
511
+ if ((current -> dx > 0 && other_edge -> dx <= 0 ) ||
512
+ (current -> dx < 0 && other_edge -> dx >= 0 )) {
513
+ continue ;
514
+ }
515
+ // Check if the two edges join to make a corner
516
+ if (xx [j - 1 ] == (ymin - other_edge -> y0 ) * other_edge -> dx + other_edge -> x0 ) {
517
+ // Determine points from the edges on the next row
518
+ // Or if this is the last row, check the previous row
519
+ int offset = ymin == ymax ? -1 : 1 ;
520
+ adjacent_line_x = (ymin + offset - current -> y0 ) * current -> dx + current -> x0 ;
521
+ adjacent_line_x_other_edge = (ymin + offset - other_edge -> y0 ) * other_edge -> dx + other_edge -> x0 ;
522
+ if (ymin == current -> ymax ) {
523
+ if (current -> dx > 0 ) {
524
+ xx [k ] = fmax (adjacent_line_x , adjacent_line_x_other_edge ) + 1 ;
525
+ } else {
526
+ xx [k ] = fmin (adjacent_line_x , adjacent_line_x_other_edge ) - 1 ;
527
+ }
528
+ } else {
529
+ if (current -> dx > 0 ) {
530
+ xx [k ] = fmin (adjacent_line_x , adjacent_line_x_other_edge );
531
+ } else {
532
+ xx [k ] = fmax (adjacent_line_x , adjacent_line_x_other_edge ) + 1 ;
533
+ }
534
+ }
535
+ break ;
536
+ }
537
+ }
538
+ }
506
539
}
507
540
}
508
541
qsort (xx , j , sizeof (float ), x_cmp );
0 commit comments