]> pd.if.org Git - hexagon/blob - t/center.c
rework library to use structs
[hexagon] / t / center.c
1 #include <math.h>
2
3 #include "hexagon.h"
4
5 #include "ctap.h"
6
7 #define EPS 0.00000001
8
9 int main(void) {
10         int x, y;
11         struct HL_hex start;
12         struct HL_point center;
13         double stride;
14
15         stride = 1.5 / sqrt(3.0);
16
17         plan(6);
18
19         x = 0; y = 0;
20         start = HL_hex_xy(x,y);
21         center = HL_hexcenter(start);
22         is_double(center.x, x * stride, EPS, "%d %d center X", x, y);
23         is_double(center.y, 0.0, EPS, "%d %d center Y", x, y);
24
25         x = 1; y = 1;
26         start = HL_hex_xy(x,y);
27         center = HL_hexcenter(start);
28         is_double(center.x, x * stride, EPS, "%d %d center X", x, y);
29         is_double(center.y, 0.5, EPS, "%d %d center Y", x, y);
30
31
32         x = 2; y = 2;
33         start = HL_hex_xy(x,y);
34         center = HL_hexcenter(start);
35         is_double(center.x, x * stride, EPS, "%d %d center X", x, y);
36         is_double(center.y, 2.0, EPS, "%d %d center Y", x, y);
37
38         return 0;
39 }