1 #ifndef __PGS_LINE_H__
2 #define __PGS_LINE_H__
3 
4 #include "circle.h"
5 
6 /* Spherical line declarations. */
7 
8 /*
9  * Spherical line data structures.
10  */
11 typedef struct
12 {
13 	float8	phi,	/* the first rotation angle around z axis */
14 			theta,	/* the second rotation angle around x axis */
15 			psi;	/* the last rotation angle around z axis */
16 	float8	length;	/* the length of the line */
17 } SLine;
18 
19 /* PGS_RELATIONSHIPS Object relationships */
20 
21 /* PGS_CIRCLE_LINE_REL Circle and line */
22 #define PGS_CIRCLE_LINE_AVOID	0	/* circle avoids line */
23 #define PGS_CIRCLE_CONT_LINE	1	/* circle contains line */
24 #define PGS_CIRCLE_LINE_OVER	2	/* circle overlaps line */
25 
26 /* PGS_LINE_LINE_REL Line and line */
27 #define PGS_LINE_AVOID			1	/* line avoids other line */
28 #define PGS_LINE_EQUAL			2	/* lines are equal */
29 #define PGS_LINE_CONT_LINE		3	/* line contains line */
30 #define PGS_LINE_CROSS			4	/* lines cross each other */
31 #define PGS_LINE_CONNECT		5	/* line are "connected" */
32 #define PGS_LINE_OVER			6	/* lines overlap each other */
33 
34 /*
35  * Makes a line with the starting point 'pbeg' and the ending point 'pend'. Result
36  * is placed into sl.
37  *
38  * Returns false if the distance between the 'pbeg' and the 'pend' is 180deg.
39  */
40 bool	sline_from_points(SLine *sl, const SPoint *pbeg, const SPoint *pend);
41 
42 /*
43  * Returns a meridian line of a given longitude in radians. The result is placed
44  * into 'sl'.
45  */
46 void	sline_meridian(SLine *sl, float8 lng);
47 
48 /*
49  * Returns the starting point of a line 'l'. Result is placed into 'p'.
50  */
51 void	sline_begin(SPoint *p, const SLine *l);
52 
53 /*
54  * Returns the ending point of a line 'l'. Result is placed into 'p'.
55  */
56 void	sline_end(SPoint *p, const SLine *l);
57 
58 /*
59  * Puts the minimum and the maximum latitudes of a spherical line 's1' into 'minlat'
60  * and 'maxlat'.
61  */
62 void	sline_min_max_lat(const SLine *sl, float8 *minlat, float8 *maxlat);
63 
64 /*
65  * Calculates spherical points with a latitude 'lat' on a spherical line.
66  *
67  * Returns the number of found points or <0 if undefined.
68  */
69 int32	sphereline_latitude_points(const SLine *sl, float8 lat, SPoint *p1, SPoint *p2);
70 
71 /*
72  * Returns true if two lines are equal.
73  */
74 bool	sline_eq(const SLine *l1, const SLine *l2);
75 
76 /*
77  * Returns the relationship between a line and a circle as PGS_CIRCLE_LINE_REL
78  * int8 value.
79  */
80 int8	sphereline_circle_pos(const SLine *sl, const SCIRCLE *sc);
81 
82 /*
83  * Assuming that a line and a circle overlap, this function returns true
84  * if the line and the circle are touching. Make sure that the line and the
85  * circle overlap before calling this function! Otherwise, the result will be
86  * undefined.
87  *
88  * See sphereline_circle_pos (const SLine *, const SCIRCLE *)
89  */
90 bool	sline_circle_touch(const SLine *sl, const SCIRCLE *sc);
91 
92 /*
93  * Returns the relationship between two lines as PGS_LINE_LINE_REL int8 value.
94  */
95 int8	sline_sline_pos(const SLine *l1, const SLine *l2);
96 
97 /*
98  * Checks whether a point is on a line.
99  */
100 bool	spoint_at_sline(const SPoint *p, const SLine *sl);
101 
102 /*
103  * Returns the Euler transformation of a line.
104  *
105  * See spheretrans_from_line(PG_FUNCTION_ARGS)
106  */
107 void	sphereline_to_euler(SEuler *se, const SLine *sl);
108 
109 /*
110  * Returns the inverse Euler transformation of a line.
111  *
112  * See spheretrans_from_line(PG_FUNCTION_ARGS)
113  */
114 void	sphereline_to_euler_inv(SEuler *se, const SLine *sl);
115 
116 /*
117  * Transforms a line using an Euler transformation.
118  *
119  * out - pointer to the resulting line
120  * in  - pointer to the original line
121  * se  - pointer to the Euler transformation
122  *
123  * See spheretrans_line (PG_FUNCTION_ARGS)
124  */
125 void	euler_sline_trans(SLine *out, const SLine *in, const SEuler *se);
126 
127 /*
128  * Puts the center of a line 'sl' into point 'c'.
129  */
130 void	sline_center(SPoint *c, const SLine *sl);
131 
132 /*
133  * The input function for spherical line.
134  */
135 Datum	sphereline_in(PG_FUNCTION_ARGS);
136 
137 /*
138  * Create a line from a spherical point.
139  */
140 Datum	sphereline_from_point(PG_FUNCTION_ARGS);
141 
142 /*
143  * This function creates a spherical line using a starting point
144  * and an ending point. The distance between the points must not be
145  * equal to 180deg.
146  */
147 Datum	sphereline_from_points(PG_FUNCTION_ARGS);
148 
149 /*
150  * This function creates a spherical line using a given Euler transformation
151  * and the length of a line. If the length is less than zero, an error occurs.
152  * If the length is larger than 360deg, it is set to 360deg.
153  */
154 Datum	sphereline_from_trans(PG_FUNCTION_ARGS);
155 
156 /*
157  * This function creates a meridian running from south to north.
158  * The float8 param provides the longitude in radians.
159  */
160 Datum	sphereline_meridian(PG_FUNCTION_ARGS);
161 
162 /*
163  * Swaps the starting point and the ending point of a line.
164  */
165 Datum	sphereline_swap_beg_end(PG_FUNCTION_ARGS);
166 
167 /*
168  * Turns the line while preserving the starting & ending points.
169  */
170 Datum	sphereline_turn(PG_FUNCTION_ARGS);
171 
172 /*
173  * Returns the beginning of a line.
174  */
175 Datum	sphereline_begin(PG_FUNCTION_ARGS);
176 
177 /*
178  * Returns the ending of a line.
179  */
180 Datum	sphereline_end(PG_FUNCTION_ARGS);
181 
182 /*
183  * Returns the length of a line in radians.
184  */
185 Datum	sphereline_length(PG_FUNCTION_ARGS);
186 
187 /*
188  * Checks whether a line contains a point.
189  */
190 Datum	sphereline_cont_point(PG_FUNCTION_ARGS);
191 
192 /*
193  * Checks whether a line doesn't contain a point.
194  */
195 Datum	sphereline_cont_point_neg(PG_FUNCTION_ARGS);
196 
197 /*
198  * Checks whether a line contains a point.
199  */
200 Datum	sphereline_cont_point_com(PG_FUNCTION_ARGS);
201 
202 /*
203  * Checks whether a line doesn't contain a point.
204  */
205 Datum	sphereline_cont_point_com_neg(PG_FUNCTION_ARGS);
206 
207 /*
208  * Checks whether a circle contains a line.
209  */
210 Datum	spherecircle_cont_line(PG_FUNCTION_ARGS);
211 
212 /*
213  * Checks whether a circle doesn't contain a line.
214  */
215 Datum	spherecircle_cont_line_neg(PG_FUNCTION_ARGS);
216 
217 /*
218  * Checks whether a circle contains a line.
219  */
220 Datum	spherecircle_cont_line_com(PG_FUNCTION_ARGS);
221 
222 /*
223  * Checks whether a circle doesn't contain a line.
224  */
225 Datum	spherecircle_cont_line_com_neg(PG_FUNCTION_ARGS);
226 
227 /*
228  * Checks whether a circle and a line overlap.
229  */
230 Datum	sphereline_overlap_circle(PG_FUNCTION_ARGS);
231 
232 /*
233  * Checks whether circle and a line don't overlap.
234  */
235 Datum	sphereline_overlap_circle_neg(PG_FUNCTION_ARGS);
236 
237 /*
238  * Checks whether a circle and a line overlap.
239  */
240 Datum	sphereline_overlap_circle_com(PG_FUNCTION_ARGS);
241 
242 /*
243  * Checks whether circle and a line don't overlap.
244  */
245 Datum	sphereline_overlap_circle_com_neg(PG_FUNCTION_ARGS);
246 
247 /*
248  * Checks whether two lines are equal.
249  */
250 Datum	sphereline_equal(PG_FUNCTION_ARGS);
251 
252 /*
253  * Checks whether two lines are not equal.
254  */
255 Datum	sphereline_equal_neg(PG_FUNCTION_ARGS);
256 
257 /*
258  * Checks whether two lines cross each other.
259  */
260 Datum	sphereline_crosses(PG_FUNCTION_ARGS);
261 
262 /*
263  * Checks whether two lines don't cross each other.
264  */
265 Datum	sphereline_crosses_neg(PG_FUNCTION_ARGS);
266 
267 /*
268  * Checks whether two lines overlap.
269  */
270 Datum	sphereline_overlap(PG_FUNCTION_ARGS);
271 
272 /*
273  * Checks whether two lines are overlap.
274  */
275 Datum	sphereline_overlap_neg(PG_FUNCTION_ARGS);
276 
277 /*
278  * Returns an Euler transformation. An inverse transformation with it puts
279  * the line into equator beginning at (0,0) and ending at (0,length).
280  */
281 Datum	spheretrans_from_line(PG_FUNCTION_ARGS);
282 
283 /*
284  * Transforms a line with an Euler transformation.
285  */
286 Datum	spheretrans_line(PG_FUNCTION_ARGS);
287 
288 /*
289  * Transforms a line with an inverse Euler transformation.
290  */
291 Datum	spheretrans_line_inverse(PG_FUNCTION_ARGS);
292 
293 #endif
294