@@ -2723,8 +2723,6 @@ void gdImageOpenPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
2723
2723
}
2724
2724
}
2725
2725
2726
- int gdCompareInt (const void * a , const void * b );
2727
-
2728
2726
/* THANKS to Kirsten Schulz for the polygon fixes! */
2729
2727
2730
2728
/* The intersection finding technique of this code could be improved
@@ -2736,6 +2734,8 @@ int gdCompareInt (const void *a, const void *b);
2736
2734
void gdImageFilledPolygon (gdImagePtr im , gdPointPtr p , int n , int c )
2737
2735
{
2738
2736
int i ;
2737
+ int j ;
2738
+ int index ;
2739
2739
int y ;
2740
2740
int miny , maxy , pmaxy ;
2741
2741
int x1 , y1 ;
@@ -2840,8 +2840,21 @@ void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
2840
2840
im -> polyInts [ints ++ ] = x2 ;
2841
2841
}
2842
2842
}
2843
- qsort (im -> polyInts , ints , sizeof (int ), gdCompareInt );
2844
-
2843
+ /*
2844
+ 2.0.26: polygons pretty much always have less than 100 points,
2845
+ and most of the time they have considerably less. For such trivial
2846
+ cases, insertion sort is a good choice. Also a good choice for
2847
+ future implementations that may wish to indirect through a table.
2848
+ */
2849
+ for (i = 1 ; (i < ints ); i ++ ) {
2850
+ index = im -> polyInts [i ];
2851
+ j = i ;
2852
+ while ((j > 0 ) && (im -> polyInts [j - 1 ] > index )) {
2853
+ im -> polyInts [j ] = im -> polyInts [j - 1 ];
2854
+ j -- ;
2855
+ }
2856
+ im -> polyInts [j ] = index ;
2857
+ }
2845
2858
for (i = 0 ; i < ints - 1 ; i += 2 ) {
2846
2859
gdImageLine (im , im -> polyInts [i ], y , im -> polyInts [i + 1 ], y , fill_color );
2847
2860
}
@@ -2853,11 +2866,6 @@ void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
2853
2866
}
2854
2867
}
2855
2868
2856
- int gdCompareInt (const void * a , const void * b )
2857
- {
2858
- return (* (const int * ) a ) - (* (const int * ) b );
2859
- }
2860
-
2861
2869
void gdImageSetStyle (gdImagePtr im , int * style , int noOfPixels )
2862
2870
{
2863
2871
if (im -> style ) {
0 commit comments