File tree Expand file tree Collapse file tree 1 file changed +3
-4
lines changed
chapters/computational_geometry/gift_wrapping/graham_scan/code/c Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change 1
1
#include <math.h>
2
- #include <stdbool.h>
3
2
#include <stddef.h>
4
3
#include <stdio.h>
5
4
#include <stdlib.h>
@@ -22,8 +21,8 @@ int cmp_points(const void *a, const void *b) {
22
21
}
23
22
}
24
23
25
- bool is_left_of (struct point a , struct point b , struct point c ) {
26
- return (b .x - a .x ) * (c .y - a .y ) < (b .y - a .y ) * (c .x - a .x );
24
+ double ccw (struct point a , struct point b , struct point c ) {
25
+ return (b .x - a .x ) * (c .y - a .y ) - (b .y - a .y ) * (c .x - a .x );
27
26
}
28
27
29
28
double polar_angle (struct point origin , struct point p ) {
@@ -73,7 +72,7 @@ size_t graham_scan(struct point *points, size_t size) {
73
72
74
73
size_t m = 1 ;
75
74
for (size_t i = 2 ; i <= size ; ++ i ) {
76
- while (is_left_of (tmp_points [m - 1 ], tmp_points [m ], tmp_points [i ])) {
75
+ while (ccw (tmp_points [m - 1 ], tmp_points [m ], tmp_points [i ]) <= 0 ) {
77
76
if (m > 1 ) {
78
77
m -- ;
79
78
continue ;
You can’t perform that action at this time.
0 commit comments