File: line.h

package info (click to toggle)
pgsphere 1.1.1%2B2020-10-20-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,700 kB
  • sloc: ansic: 12,032; sql: 6,091; cpp: 853; makefile: 216; perl: 168; yacc: 145; xml: 66; lex: 55; sh: 1
file content (293 lines) | stat: -rw-r--r-- 7,347 bytes parent folder | download | duplicates (3)
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#ifndef __PGS_LINE_H__
#define __PGS_LINE_H__

#include "circle.h"

/* Spherical line declarations. */

/*
 * Spherical line data structures.
 */
typedef struct
{
	float8	phi,	/* the first rotation angle around z axis */
			theta,	/* the second rotation angle around x axis */
			psi;	/* the last rotation angle around z axis */
	float8	length;	/* the length of the line */
} SLine;

/* PGS_RELATIONSHIPS Object relationships */

/* PGS_CIRCLE_LINE_REL Circle and line */
#define PGS_CIRCLE_LINE_AVOID	0	/* circle avoids line */
#define PGS_CIRCLE_CONT_LINE	1	/* circle contains line */
#define PGS_CIRCLE_LINE_OVER	2	/* circle overlaps line */

/* PGS_LINE_LINE_REL Line and line */
#define PGS_LINE_AVOID			1	/* line avoids other line */
#define PGS_LINE_EQUAL			2	/* lines are equal */
#define PGS_LINE_CONT_LINE		3	/* line contains line */
#define PGS_LINE_CROSS			4	/* lines cross each other */
#define PGS_LINE_CONNECT		5	/* line are "connected" */
#define PGS_LINE_OVER			6	/* lines overlap each other */

/*
 * Makes a line with the starting point 'pbeg' and the ending point 'pend'. Result
 * is placed into sl.
 *
 * Returns false if the distance between the 'pbeg' and the 'pend' is 180deg.
 */
bool	sline_from_points(SLine *sl, const SPoint *pbeg, const SPoint *pend);

/*
 * Returns a meridian line of a given longitude in radians. The result is placed
 * into 'sl'.
 */
void	sline_meridian(SLine *sl, float8 lng);

/*
 * Returns the starting point of a line 'l'. Result is placed into 'p'.
 */
void	sline_begin(SPoint *p, const SLine *l);

/*
 * Returns the ending point of a line 'l'. Result is placed into 'p'.
 */
void	sline_end(SPoint *p, const SLine *l);

/*
 * Puts the minimum and the maximum latitudes of a spherical line 's1' into 'minlat'
 * and 'maxlat'.
 */
void	sline_min_max_lat(const SLine *sl, float8 *minlat, float8 *maxlat);

/*
 * Calculates spherical points with a latitude 'lat' on a spherical line.
 *
 * Returns the number of found points or <0 if undefined.
 */
int32	sphereline_latitude_points(const SLine *sl, float8 lat, SPoint *p1, SPoint *p2);

/*
 * Returns true if two lines are equal.
 */
bool	sline_eq(const SLine *l1, const SLine *l2);

/*
 * Returns the relationship between a line and a circle as PGS_CIRCLE_LINE_REL
 * int8 value.
 */
int8	sphereline_circle_pos(const SLine *sl, const SCIRCLE *sc);

/*
 * Assuming that a line and a circle overlap, this function returns true
 * if the line and the circle are touching. Make sure that the line and the
 * circle overlap before calling this function! Otherwise, the result will be
 * undefined.
 *
 * See sphereline_circle_pos (const SLine *, const SCIRCLE *)
 */
bool	sline_circle_touch(const SLine *sl, const SCIRCLE *sc);

/*
 * Returns the relationship between two lines as PGS_LINE_LINE_REL int8 value.
 */
int8	sline_sline_pos(const SLine *l1, const SLine *l2);

/*
 * Checks whether a point is on a line.
 */
bool	spoint_at_sline(const SPoint *p, const SLine *sl);

/*
 * Returns the Euler transformation of a line.
 *
 * See spheretrans_from_line(PG_FUNCTION_ARGS)
 */
void	sphereline_to_euler(SEuler *se, const SLine *sl);

/*
 * Returns the inverse Euler transformation of a line.
 *
 * See spheretrans_from_line(PG_FUNCTION_ARGS)
 */
void	sphereline_to_euler_inv(SEuler *se, const SLine *sl);

/*
 * Transforms a line using an Euler transformation.
 *
 * out - pointer to the resulting line
 * in  - pointer to the original line
 * se  - pointer to the Euler transformation
 *
 * See spheretrans_line (PG_FUNCTION_ARGS)
 */
void	euler_sline_trans(SLine *out, const SLine *in, const SEuler *se);

/*
 * Puts the center of a line 'sl' into point 'c'.
 */
void	sline_center(SPoint *c, const SLine *sl);

/*
 * The input function for spherical line.
 */
Datum	sphereline_in(PG_FUNCTION_ARGS);

/*
 * Create a line from a spherical point.
 */
Datum	sphereline_from_point(PG_FUNCTION_ARGS);

/*
 * This function creates a spherical line using a starting point
 * and an ending point. The distance between the points must not be
 * equal to 180deg.
 */
Datum	sphereline_from_points(PG_FUNCTION_ARGS);

/*
 * This function creates a spherical line using a given Euler transformation
 * and the length of a line. If the length is less than zero, an error occurs.
 * If the length is larger than 360deg, it is set to 360deg.
 */
Datum	sphereline_from_trans(PG_FUNCTION_ARGS);

/*
 * This function creates a meridian running from south to north.
 * The float8 param provides the longitude in radians.
 */
Datum	sphereline_meridian(PG_FUNCTION_ARGS);

/*
 * Swaps the starting point and the ending point of a line.
 */
Datum	sphereline_swap_beg_end(PG_FUNCTION_ARGS);

/*
 * Turns the line while preserving the starting & ending points.
 */
Datum	sphereline_turn(PG_FUNCTION_ARGS);

/*
 * Returns the beginning of a line.
 */
Datum	sphereline_begin(PG_FUNCTION_ARGS);

/*
 * Returns the ending of a line.
 */
Datum	sphereline_end(PG_FUNCTION_ARGS);

/*
 * Returns the length of a line in radians.
 */
Datum	sphereline_length(PG_FUNCTION_ARGS);

/*
 * Checks whether a line contains a point.
 */
Datum	sphereline_cont_point(PG_FUNCTION_ARGS);

/*
 * Checks whether a line doesn't contain a point.
 */
Datum	sphereline_cont_point_neg(PG_FUNCTION_ARGS);

/*
 * Checks whether a line contains a point.
 */
Datum	sphereline_cont_point_com(PG_FUNCTION_ARGS);

/*
 * Checks whether a line doesn't contain a point.
 */
Datum	sphereline_cont_point_com_neg(PG_FUNCTION_ARGS);

/*
 * Checks whether a circle contains a line.
 */
Datum	spherecircle_cont_line(PG_FUNCTION_ARGS);

/*
 * Checks whether a circle doesn't contain a line.
 */
Datum	spherecircle_cont_line_neg(PG_FUNCTION_ARGS);

/*
 * Checks whether a circle contains a line.
 */
Datum	spherecircle_cont_line_com(PG_FUNCTION_ARGS);

/*
 * Checks whether a circle doesn't contain a line.
 */
Datum	spherecircle_cont_line_com_neg(PG_FUNCTION_ARGS);

/*
 * Checks whether a circle and a line overlap.
 */
Datum	sphereline_overlap_circle(PG_FUNCTION_ARGS);

/*
 * Checks whether circle and a line don't overlap.
 */
Datum	sphereline_overlap_circle_neg(PG_FUNCTION_ARGS);

/*
 * Checks whether a circle and a line overlap.
 */
Datum	sphereline_overlap_circle_com(PG_FUNCTION_ARGS);

/*
 * Checks whether circle and a line don't overlap.
 */
Datum	sphereline_overlap_circle_com_neg(PG_FUNCTION_ARGS);

/*
 * Checks whether two lines are equal.
 */
Datum	sphereline_equal(PG_FUNCTION_ARGS);

/*
 * Checks whether two lines are not equal.
 */
Datum	sphereline_equal_neg(PG_FUNCTION_ARGS);

/*
 * Checks whether two lines cross each other.
 */
Datum	sphereline_crosses(PG_FUNCTION_ARGS);

/*
 * Checks whether two lines don't cross each other.
 */
Datum	sphereline_crosses_neg(PG_FUNCTION_ARGS);

/*
 * Checks whether two lines overlap.
 */
Datum	sphereline_overlap(PG_FUNCTION_ARGS);

/*
 * Checks whether two lines are overlap.
 */
Datum	sphereline_overlap_neg(PG_FUNCTION_ARGS);

/*
 * Returns an Euler transformation. An inverse transformation with it puts
 * the line into equator beginning at (0,0) and ending at (0,length).
 */
Datum	spheretrans_from_line(PG_FUNCTION_ARGS);

/*
 * Transforms a line with an Euler transformation.
 */
Datum	spheretrans_line(PG_FUNCTION_ARGS);

/*
 * Transforms a line with an inverse Euler transformation.
 */
Datum	spheretrans_line_inverse(PG_FUNCTION_ARGS);

#endif