1 parent cc01c3a commit 0bba382Copy full SHA for 0bba382
1 file changed
src/hagl_polygon.c
@@ -115,19 +115,15 @@ void hagl_fill_polygon(
115
j = i;
116
}
117
118
- /* Sort the nodes, via a simple “Bubble” sort. */
119
- int16_t i = 0;
120
- while (i < count - 1) {
121
- if (nodes[i] > nodes[i + 1]) {
122
- int16_t swap = nodes[i];
123
- nodes[i] = nodes[i + 1];
124
- nodes[i + 1] = swap;
125
- if (i) {
126
- i--;
127
- }
128
- } else {
129
- i++;
+ /* Sort the nodes, via insertion sort. */
+ for (int16_t i = 1; i < count; i++) {
+ int16_t key = nodes[i];
+ int16_t j = i - 1;
+ while (j >= 0 && nodes[j] > key) {
+ nodes[j + 1] = nodes[j];
+ j--;
130
+ nodes[j + 1] = key;
131
132
133
/* Draw lines between nodes. */
0 commit comments