… | |
… | |
31 | |
31 | |
32 | static inline int |
32 | static inline int |
33 | intmax (int a, int b) |
33 | intmax (int a, int b) |
34 | { |
34 | { |
35 | return a > b ? a : b; |
35 | return a > b ? a : b; |
|
|
36 | } |
|
|
37 | |
|
|
38 | static inline int |
|
|
39 | get_u16 (const U8 *ptr) |
|
|
40 | { |
|
|
41 | return ptr[0] | (ptr[1] << 8); |
36 | } |
42 | } |
37 | |
43 | |
38 | MODULE = Geo::LatLon2Place PACKAGE = Geo::LatLon2Place |
44 | MODULE = Geo::LatLon2Place PACKAGE = Geo::LatLon2Place |
39 | |
45 | |
40 | PROTOTYPES: ENABLE |
46 | PROTOTYPES: ENABLE |
… | |
… | |
80 | unsigned char key[4] = { |
86 | unsigned char key[4] = { |
81 | rx, rx >> 8, |
87 | rx, rx >> 8, |
82 | y, y >> 8, |
88 | y, y >> 8, |
83 | }; |
89 | }; |
84 | |
90 | |
85 | printf ("x,y %4d,%4d blat %d %d %g %02x%02x%02x%02x %d\n", rx, y, blat, (int)glat, TORAD(glat), key[0],key[1],key[2],key[3], sizeof(key)); |
91 | //printf ("x,y %4d,%4d blat %d %d %g %02x%02x%02x%02x %d\n", rx, y, blat, (int)glat, TORAD(glat), key[0],key[1],key[2],key[3], sizeof(key)); |
86 | |
92 | |
87 | if (cdb_find (db, key, sizeof (key)) <= 0) |
93 | if (cdb_find (db, key, sizeof (key)) <= 0) |
88 | continue; |
94 | continue; |
89 | |
95 | |
90 | int len = cdb_datalen (db); |
96 | int len = cdb_datalen (db); |
… | |
… | |
92 | |
98 | |
93 | while (len > 0) |
99 | while (len > 0) |
94 | { |
100 | { |
95 | int datalen = ptr[5]; |
101 | int datalen = ptr[5]; |
96 | |
102 | |
97 | double plat = ptr[0] | (ptr[1] << 8) * ( 90. / 32767.); |
103 | double plat = get_u16 (ptr + 0) * ( 90. / 32767.); |
98 | double plon = ptr[2] | (ptr[3] << 8) * (180. / 32767.); |
104 | double plon = get_u16 (ptr + 2) * (180. / 32767.); |
99 | int w = ptr[4]; |
105 | int w = ptr[4]; |
100 | |
106 | |
101 | double dx = TORAD (lon - plon) * coslat; |
107 | double dx = TORAD (lon - plon) * coslat; |
102 | double dy = TORAD (lat - plat); |
108 | double dy = TORAD (lat - plat); |
103 | double d2 = (dx * dx + dy * dy) * w; |
109 | double d2 = (dx * dx + dy * dy) * w; |
104 | printf ("%g,%g %g %.*s\n", plat,plon,d2, datalen,ptr+6); |
110 | //printf ("%g,%g %g %.*s\n", plat,plon,d2, datalen,ptr+6); |
105 | |
111 | |
106 | if (d2 < mind) |
112 | if (d2 < mind) |
107 | { |
113 | { |
108 | mind = d2; |
114 | mind = d2; |
109 | resptr = ptr; |
115 | resptr = ptr; |
… | |
… | |
127 | |
133 | |
128 | int |
134 | int |
129 | cdb_init (SV *self, int fd) |
135 | cdb_init (SV *self, int fd) |
130 | CODE: |
136 | CODE: |
131 | sv_upgrade (self, SVt_PV); |
137 | sv_upgrade (self, SVt_PV); |
|
|
138 | sv_grow (self, sizeof (struct cdb)); |
132 | SvCUR_set (self, sizeof (struct cdb)); |
139 | SvCUR_set (self, sizeof (struct cdb)); |
133 | SvPOK_only (self); |
140 | SvPOK_only (self); |
134 | RETVAL = cdb_init ((struct cdb *)SvPVX (self), fd); |
141 | RETVAL = cdb_init ((struct cdb *)SvPVX (self), fd); |
135 | OUTPUT: RETVAL |
142 | OUTPUT: RETVAL |
136 | |
143 | |