1 #include "coordinate-system.h"
6 struct TestCoordinate {
11 // Test data extracted from example on page
12 // http://developer.reittiopas.fi/pages/fi/http-get-interface.php
13 struct TestCoordinate testData[] = {
14 { 2556686, 6682815, 25.02051, 60.2528 },
15 { 2546340, 6675352, 24.832, 60.18713 },
16 { 2557985, 6685213, 25.04465, 60.27414 },
17 { 2556532, 6682578, 25.01767, 60.2507 },
18 { 2524959, 6686629, 24.44804, 60.2902 },
19 { 2559094, 6693721, 25.06718, 60.35033 },
20 { 2556861, 6683030, 25.02373, 60.25471 },
21 { 2556888, 6682971, 25.0242, 60.25417 },
22 { 2560257, 6698983, 25.08981, 60.39737 },
23 { 2562518, 6686969, 25.12709, 60.28923 },
24 { 2536615, 6673635, 24.65643, 60.1727 },
25 { 2559118, 6693833, 25.06764, 60.35133 },
26 { 2559182, 6693629, 25.06874, 60.34949 },
27 { 2556947, 6682640, 25.02518, 60.25119 },
28 { 2556822, 6682723, 25.02294, 60.25196 },
29 { 2559089, 6693605, 25.06705, 60.34929 },
30 { 2546445, 6675512, 24.83393, 60.18855 },
31 { 2556964, 6682609, 25.02547, 60.25091 },
32 { 2556740, 6682861, 25.0215, 60.25321 },
33 { 2559002, 6694007, 25.06559, 60.35291 }};
36 int testKKJxytoWGS84lola() {
41 for (i = 0; i < sizeof(testData) / sizeof(struct TestCoordinate); ++i) {
42 KKJxy_to_WGS84lola(testData[i].x, testData[i].y, &lon, &lat);
44 if (fabs(testData[i].lon - lon) < 0.001 && fabs(testData[i].lat - lat) < 0.001) {
47 printf("Got: (%f, %f), expected: (%f, %f)\n", lon, lat, testData[i].lon, testData[i].lat);
56 int testWGS84lolatoKKJxy() {
61 for (i = 0; i < sizeof(testData) / sizeof(struct TestCoordinate); ++i) {
62 WGS84lola_to_KKJxy(testData[i].lon, testData[i].lat, &x, &y);
64 if (abs(testData[i].x - x) < 2 && abs(testData[i].y - y) < 2) {
67 printf("Got: (%u, %u), expected: (%u, %u)\n", x, y, testData[i].x, testData[i].y);
77 int main(int argc, char* argv[]) {
80 // Test transforming from KKJxy to WGS84lonlat
81 testResult = testKKJxytoWGS84lola();
83 if (testResult == 0) {
84 printf("All tests in testKKJxytoWGS84lola passed\n");
87 // Test transforming from WGS84lonlat to KKJxy
88 testResult = testWGS84lolatoKKJxy();
90 if (testResult == 0) {
91 printf("All tests in testWGS84lolatoKKJxy passed\n");