Navit SVN

/work/compile/navit/src/navit/coord.h

00001 
00020 #ifndef NAVIT_COORD_H
00021 #define NAVIT_COORD_H
00022 
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 #include <stdio.h>
00028 #include "config.h"
00029 #include "projection.h"
00030 
00031 #define coord_is_equal(a,b) ((a).x==(b).x && (a).y==(b).y)
00032 
00034 struct coord {
00035         int x; 
00036         int y; 
00037 };
00038 
00040 struct pcoord {
00041         enum projection pro;
00042         int x; 
00043         int y; 
00044 };
00045 
00046 struct coord_rect {
00047         struct coord lu;
00048         struct coord rl;
00049 };
00050 
00051 
00052 #ifdef AVOID_FLOAT
00053 
00058 typedef float navit_float;
00059 #define navit_sin(x) sinf(x)
00060 #define navit_cos(x) cosf(x)
00061 #define navit_tan(x) tanf(x)
00062 #define navit_atan(x) atanf(x)
00063 #define navit_acos(x) acosf(x)
00064 #define navit_asin(x) asinf(x)
00065 #define navit_sqrt(x) sqrtf(x)
00066 #else
00067 typedef  double navit_float;
00068 #define navit_sin(x) sin(x)
00069 #define navit_cos(x) cos(x)
00070 #define navit_tan(x) tan(x)
00071 #define navit_atan(x) atan(x)
00072 #define navit_acos(x) acos(x)
00073 #define navit_asin(x) asin(x)
00074 #define navit_sqrt(x) sqrt(x)
00075 #endif
00076 
00077 
00079 struct coord_d {
00080         double x; 
00081         double y; 
00082 };
00083 
00085 struct coord_geo {
00086         navit_float lng; 
00087         navit_float lat; 
00088 };
00089 
00091 struct coord_geo_cart {
00092         navit_float x; 
00093         navit_float y; 
00094         navit_float z; 
00095 };
00096 
00101 enum coord_format 
00102 {
00107         DEGREES_DECIMAL,
00108 
00113         DEGREES_MINUTES,
00118         DEGREES_MINUTES_SECONDS 
00119 };
00120 
00121 enum projection;
00122 struct attr;
00123 
00124 struct coord * coord_get(unsigned char **p);
00125 struct coord * coord_new(int x, int y);
00126 struct coord * coord_new_from_attrs(struct attr *parent, struct attr **attrs);
00127 void coord_destroy(struct coord *c);
00128 int coord_parse(const char *c_str, enum projection pro, struct coord *c_ret);
00129 int pcoord_parse(const char *c_str, enum projection pro, struct pcoord *c_ret);
00130 void coord_print(enum projection pro, struct coord *c, FILE *out);
00131 struct coord_rect * coord_rect_new(struct coord *lu, struct coord *rl);
00132 void coord_rect_destroy(struct coord_rect *r);
00133 int coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2);
00134 int coord_rect_contains(struct coord_rect *r, struct coord *c);
00135 void coord_rect_extend(struct coord_rect *r, struct coord *c);
00136 void coord_format(float lat,float lng, enum coord_format, char * buffer, int size);
00137 
00138 /* prototypes */
00139 enum coord_format;
00140 enum projection;
00141 struct attr;
00142 struct coord;
00143 struct coord_rect;
00144 struct pcoord;
00145 struct coord *coord_get(unsigned char **p);
00146 struct coord *coord_new(int x, int y);
00147 struct coord *coord_new_from_attrs(struct attr *parent, struct attr **attrs);
00148 void coord_destroy(struct coord *c);
00149 struct coord_rect *coord_rect_new(struct coord *lu, struct coord *rl);
00150 void coord_rect_destroy(struct coord_rect *r);
00151 int coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2);
00152 int coord_rect_contains(struct coord_rect *r, struct coord *c);
00153 void coord_rect_extend(struct coord_rect *r, struct coord *c);
00154 int coord_parse(const char *c_str, enum projection pro, struct coord *c_ret);
00155 int pcoord_parse(const char *c_str, enum projection pro, struct pcoord *pc_ret);
00156 void coord_print(enum projection pro, struct coord *c, FILE *out);
00157 void coord_format(float lat, float lng, enum coord_format fmt, char *buffer, int size);
00158 unsigned int coord_hash(const void *key);
00159 int coord_equal(const void *a, const void *b);
00160 /* end of prototypes */
00161 #ifdef __cplusplus
00162 }
00163 #endif
00164 #endif