summaryrefslogtreecommitdiff
path: root/navit/coord.h
blob: f3601830d8dc890557551d887a25fb669401333b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
 * Navit, a modular navigation system.
 * Copyright (C) 2005-2008 Navit Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

#ifndef NAVIT_COORD_H
#define NAVIT_COORD_H


#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include "config.h"
#include "projection.h"

#define coord_is_equal(a,b) ((a).x==(b).x && (a).y==(b).y)

/*! A integer mercator coordinate */
struct coord {
	int x; /*!< X-Value */
	int y; /*!< Y-Value */
};

/**
 * @brief An integer mercator coordinate packed with a text label
 *
 * This structure holds information about an item (coordinates & label) on a map. This can be
 * used in a list as group of points to display as search results on a map.
 * It is used to structure input data for function navit_populate_search_results_map()
 */
struct lcoord {
    struct coord c;	/*!< The coordinates for this item */
    char *label;	/*!< A label to associate to this item */
};

/*! A integer mercator coordinate carrying its projection */
struct pcoord {
	enum projection pro;
	int x; /*!< X-Value */
	int y; /*!< Y-Value */
};

struct coord_rect {
	struct coord lu;
	struct coord rl;
};


#ifdef AVOID_FLOAT
/**
 * On platforms where we are trying to avoid floats, sometimes we can't.
 * It is better on these platforms to use single precision floating points
 * over double precision ones since performance is much better.
 */
typedef float navit_float;
#define navit_sin(x) sinf(x)
#define navit_cos(x) cosf(x)
#define navit_tan(x) tanf(x)
#define navit_atan(x) atanf(x)
#define navit_acos(x) acosf(x)
#define navit_asin(x) asinf(x)
#define navit_sqrt(x) sqrtf(x)
#else
typedef  double navit_float;
#define navit_sin(x) sin(x)
#define navit_cos(x) cos(x)
#define navit_tan(x) tan(x)
#define navit_atan(x) atan(x)
#define navit_acos(x) acos(x)
#define navit_asin(x) asin(x)
#define navit_sqrt(x) sqrt(x)
#endif


//! A double mercator coordinate
struct coord_d {
	double x; /*!< X-Value */
	double y; /*!< Y-Value */
};

//! A WGS84 coordinate
struct coord_geo {
	navit_float lng; /*!< Longitude */
	navit_float lat; /*!< Latitude */
};

//! A cartesian coordinate
struct coord_geo_cart {
	navit_float x; /*!< X-Value */
	navit_float y; /*!< Y-Value */
	navit_float z; /*!< Z-Value */
};

/**
 * An enumeration of formats for printing geographic coordinates in.
 *
 */
enum coord_format
{
	/**
	 * Degrees with absolute decimal places (positive or negative)
	 * ie -20.500000 -110.500000
	 */
	DEGREES_DECIMAL_ABSOLUTE,

	/**
	 * Degrees with decimal places (positive with heading)
	 * ie 20.500000°N 110.500000°E
	 */
	DEGREES_DECIMAL,

	/**
	 * Degrees and minutes.
	 * ie 20°30.0000' N 110°30.0000' E
	 */
	DEGREES_MINUTES,

	/**
	 * Degrees, minutes and seconds.
	 * ie 20°30'30.00" N 110°30'30.00" E
	 */
	DEGREES_MINUTES_SECONDS,

	/**
	 * Degrees, minutes and seconds, brief
	 * ie 20°30'30"N 110°30'30"E
	 */
	DEGREES_MINUTES_SECONDS_BRIEF
};

enum projection;
struct attr;

struct coord * coord_get(unsigned char **p);
struct coord * coord_new(int x, int y);
struct coord * coord_new_from_attrs(struct attr *parent, struct attr **attrs);
void coord_destroy(struct coord *c);
int coord_parse(const char *c_str, enum projection pro, struct coord *c_ret);
int pcoord_parse(const char *c_str, enum projection pro, struct pcoord *c_ret);
void coord_print(enum projection pro, struct coord *c, FILE *out);
struct coord_rect * coord_rect_new(struct coord *lu, struct coord *rl);
void coord_rect_destroy(struct coord_rect *r);
int coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2);
int coord_rect_contains(struct coord_rect *r, struct coord *c);
void coord_rect_extend(struct coord_rect *r, struct coord *c);
void coord_format_with_sep(float lat,float lng, enum coord_format fmt, char *buffer, int size, const char *sep);
void coord_format(float lat,float lng, enum coord_format fmt, char *buffer, int size);
void coord_geo_format_short(const struct coord_geo *gc, char *buffer, int size, char *sep);
void pcoord_format_degree_short(const struct pcoord *pc, char *buffer, int size, char *sep);
void pcoord_format_absolute(const struct pcoord *pc, char *buffer, int size, char *sep);
char *coordinates_geo(const struct coord_geo *gc, char sep);

/* prototypes */
enum coord_format;
enum projection;
struct attr;
struct coord;
struct coord_rect;
struct pcoord;
struct coord *coord_get(unsigned char **p);
struct coord *coord_new(int x, int y);
struct coord *coord_new_from_attrs(struct attr *parent, struct attr **attrs);
void coord_destroy(struct coord *c);
struct coord_rect *coord_rect_new(struct coord *lu, struct coord *rl);
void coord_rect_destroy(struct coord_rect *r);
int coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2);
int coord_rect_contains(struct coord_rect *r, struct coord *c);
void coord_rect_extend(struct coord_rect *r, struct coord *c);
int coord_parse(const char *c_str, enum projection pro, struct coord *c_ret);
int pcoord_parse(const char *c_str, enum projection pro, struct pcoord *pc_ret);
void coord_print(enum projection pro, struct coord *c, FILE *out);
void coord_format(float lat, float lng, enum coord_format fmt, char *buffer, int size);
unsigned int coord_hash(const void *key);
int coord_equal(const void *a, const void *b);
/* end of prototypes */
#ifdef __cplusplus
}
#endif
#endif