]> pd.if.org Git - isea/blob - t/projtri.c
Initial checkin.
[isea] / t / projtri.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <math.h>
5
6 #include "tap.h"
7 #include "isea.h"
8
9 #include "testing.h"
10
11 #include "cities.pt"
12
13 void iso(struct hex *h) {
14         hex_iso(h);
15         printf("iso(%d,%d,%d)", h->x, h->y, h->z);
16 }
17 void xy(struct hex *h) {
18         hex_xy(h);
19         printf("xy(%d,%d)", h->x, h->y);
20 }
21
22 struct dgg {
23         int triangle;
24         double x, y;
25         char *data;
26 }  dgg[] = {
27 {5, 0.5485949, 0.1666408, "49900 Corvallis"},
28 {5, 0.5498729, 0.1533820, "42300 Aloha"},
29 {5, 0.5485337, 0.1538048, "41700 Tigard"},
30 {5, 0.5469778, 0.1653373, "41400 Albany"},
31 {5, 0.5477250, 0.1538168, "35700 LakeOswego"},
32 {5, 0.5484942, 0.1602033, "32600 Keizer"},
33 {5, 0.5514087, 0.1580878, "26800 MacMinnville"},
34 {5, 0.5463249, 0.1543639, "26100 OregonCity"},
35 {5, 0.5366604, 0.1942501, "23300 GrantsPass"},
36 {5, 0.5482398, 0.1544470, "23100 Tualatin"},
37 {5, 0.5468969, 0.1541197, "22500 WestLinn"},
38 {5, 0.5471126, 0.1531509, "20700 Milwaukie"},
39 {5, 0.5338688, 0.1458412, "20600 CitrusPark"},
40 {5, 0.5477809, 0.1577168, "20400 Woodburn"},
41 {5, 0.5415903, 0.1843270, "20300 Roseburg"},
42 {0, 0.0, 0.0, NULL}
43 };
44
45 int main(void) {
46         int i, j;
47
48         char isea[64], sahr[64];
49         struct isea_dgg g;
50         struct isea_pt xy;
51         struct isea_geo ll;
52
53         isea_grid_init(&g);
54         g.output = ISEA_PROJTRI;
55         g.radius = ISEA_SCALE;
56
57         i=0;
58         while (cities[i].data) i++;
59
60         plan_tests(i * 3);
61
62         for (j=0; j<i; j++) {
63                 ll.lon = cities[j].lon * M_PI / 180.0;
64                 ll.lat = cities[j].lat * M_PI / 180.0;
65                 xy = isea_forward(&g, &ll);
66                 sprintf(isea, "%.7f", xy.x);
67                 sprintf(sahr, "%.7f", dgg[j].x);
68                 ok(!strcmp(isea,sahr), "projtri X (%f, %f %s) %s != %s",
69                                 cities[j].lon, cities[j].lat, cities[j].data,
70                                 isea, sahr,
71                                 xy.x, dgg[j].x);
72                 ok(!strcmp(isea,sahr), "projtri Y (%f, %f %s) %f != %f",
73                                 cities[j].lon, cities[j].lat, cities[j].data,
74                                 xy.y, dgg[j].y);
75                 ok(g.triangle-1 == dgg[j].triangle,
76                                 "projtri T (%f, %f %s) %d != %d",
77                                 cities[j].lon, cities[j].lat, cities[j].data,
78                                 g.triangle-1, dgg[j].triangle);
79         }
80
81         return exit_status();
82
83 }