1 #ifndef __PGS_ELLIPSE_H__
2 #define __PGS_ELLIPSE_H__
3 
4 #include "line.h"
5 
6 /* Ellipse declarations */
7 
8 /*
9  * Spherical ellipse data structure. A spherical ellipse is represented using
10  * two radii and an Euler transformation (ZXZ-axis). The "untransformed" ellipse
11  * is located on equator at position (0,0). The large radius is along equator.
12  */
13 typedef struct
14 {
15 	/*
16 	 * rad[0] is the large radius, rad[1] is the small radius of an ellipse in
17 	 * radians
18 	 */
19 	float8		rad[2];
20 
21 	float8		phi,	/* the first rotation angle around z axis */
22 				theta,	/* the second rotation angle around x axis */
23 				psi;	/* the last rotation angle around z axis */
24 } SELLIPSE;
25 
26 /*
27  * PGS_RELATIONSHIPS
28  */
29 
30 /* PGS_ELLIPSE_LINE_REL Ellipse and line */
31 #define PGS_ELLIPSE_LINE_AVOID		0	/* ellipse avoids line */
32 #define PGS_ELLIPSE_CONT_LINE		1	/* ellipse contains line */
33 #define PGS_ELLIPSE_LINE_OVER		2	/* ellipse overlaps line */
34 
35 /* PGS_ELLIPSE_CIRCLE_REL Ellipse and circle */
36 #define PGS_ELLIPSE_CIRCLE_AVOID	0	/* ellipse avoids circle */
37 #define PGS_CIRCLE_CONT_ELLIPSE		1	/* circle contains ellipse */
38 #define PGS_ELLIPSE_CONT_CIRCLE		2	/* ellipse contains circle */
39 #define PGS_ELLIPSE_CIRCLE_EQUAL	3	/* ellipse equals circle */
40 #define PGS_ELLIPSE_CIRCLE_OVER		4	/* ellipse overlaps circle */
41 
42 /* PGS_ELLIPSE_ELLIPSE_REL Ellipse and ellipse */
43 #define PGS_ELLIPSE_AVOID			0	/* ellipse avoids other ellipse */
44 #define PGS_ELLIPSE_CONT			1	/* ellipse contains other ellipse */
45 #define PGS_ELLIPSE_OVER			2	/* ellipse overlaps other ellipse */
46 
47 /*
48  * Checks whether two ellipses are equal .
49  */
50 bool	sellipse_eq(const SELLIPSE *e1, const SELLIPSE *e2);
51 
52 /*
53  * Returns the center of an ellipse.
54  */
55 void	sellipse_center(SPoint *sp, const SELLIPSE *e);
56 
57 /*
58  * Checks whether a ellipse contains point.
59  */
60 bool	sellipse_cont_point(const SELLIPSE *se, const SPoint *sp);
61 
62 /*
63  * Returns the large axis of an ellipse as line.
64  */
65 bool	sellipse_line(SLine *sl, const SELLIPSE *e);
66 
67 /*
68  * Relationship between a line and an ellipse as PGS_ELLIPSE_LINE_REL int8 value.
69  */
70 int8	sellipse_line_pos(const SELLIPSE *se, const SLine *sl);
71 
72 /*
73  * Relationship between a circle and an ellipse as PGS_ELLIPSE_CIRCLE_REL int8 value.
74  */
75 int8	sellipse_circle_pos(const SELLIPSE *se, const SCIRCLE *sc);
76 
77 /*
78  * Returns the Euler transformation of an ellipse.
79  */
80 void	sellipse_trans(SEuler *se, const SELLIPSE *e);
81 
82 /*
83  * Input of the spherical ellipse.
84  */
85 Datum	sphereellipse_in(PG_FUNCTION_ARGS);
86 
87 /*
88  * Input of the spherical ellipse from center, axes and inclination.
89  */
90 Datum	sphereellipse_infunc(PG_FUNCTION_ARGS);
91 
92 /*
93  * Returns the inclination of an ellipse.
94  */
95 Datum	sphereellipse_incl(PG_FUNCTION_ARGS);
96 
97 /*
98  * Returns the length of the major axis of an ellipse.
99  */
100 Datum	sphereellipse_rad1(PG_FUNCTION_ARGS);
101 
102 /*
103  * Returns the length of the minor axis of an ellipse.
104  */
105 Datum	sphereellipse_rad2(PG_FUNCTION_ARGS);
106 
107 /*
108  * Returns the center of an ellipse.
109  */
110 Datum	sphereellipse_center(PG_FUNCTION_ARGS);
111 
112 /*
113  * Returns the Euler transformation of an ellipse.
114  */
115 Datum	sphereellipse_trans(PG_FUNCTION_ARGS);
116 
117 /*
118  * Casts a spherical ellipse as circle. The created circle is the boundary
119  * circle of ellipse. The diameter of returned circle is equal to length of
120  * major axis of ellipse.
121   */
122 Datum	sphereellipse_circle(PG_FUNCTION_ARGS);
123 
124 /*
125  * Casts a spherical point to an ellipse.
126  */
127 Datum	spherepoint_ellipse(PG_FUNCTION_ARGS);
128 
129 /*
130  * Casts a spherical circle to an ellipse.
131  */
132 Datum	spherecircle_ellipse(PG_FUNCTION_ARGS);
133 
134 /*
135  * Checks whether two ellipses are equal.
136  */
137 Datum	sphereellipse_equal(PG_FUNCTION_ARGS);
138 
139 /*
140  * Checks whether two ellipses are not equal.
141  */
142 Datum	sphereellipse_equal_neg(PG_FUNCTION_ARGS);
143 
144 /*
145  * Checks whether an ellipse contains a point.
146  */
147 Datum	sphereellipse_cont_point(PG_FUNCTION_ARGS);
148 
149 /*
150  * Checks whether an ellipse doesn't contain a point.
151  */
152 Datum	sphereellipse_cont_point_neg(PG_FUNCTION_ARGS);
153 
154 /*
155  * Checks whether an ellipse contains a point.
156  */
157 Datum	sphereellipse_cont_point_com(PG_FUNCTION_ARGS);
158 
159 /*
160  * Checks whether an ellipse doesn't contain a point.
161  */
162 Datum	sphereellipse_cont_point_com_neg(PG_FUNCTION_ARGS);
163 
164 /*
165  * Checks whether an ellipse contains a line.
166  */
167 Datum	sphereellipse_cont_line(PG_FUNCTION_ARGS);
168 
169 /*
170  * Checks whether an ellipse doesn't contain a line.
171  */
172 Datum	sphereellipse_cont_line_neg(PG_FUNCTION_ARGS);
173 
174 /*
175  * Checks whether an ellipse contains a line.
176  */
177 Datum	sphereellipse_cont_line_com(PG_FUNCTION_ARGS);
178 
179 /*
180  * Checks whether an ellipse doesn't contain a line.
181  */
182 Datum	sphereellipse_cont_line_com_neg(PG_FUNCTION_ARGS);
183 
184 /*
185  * Checks whether an ellipse and a line overlap.
186  */
187 Datum	sphereellipse_overlap_line(PG_FUNCTION_ARGS);
188 
189 /*
190  * Checks whether an ellipse and a line don't overlap.
191  */
192 Datum	sphereellipse_overlap_line_neg(PG_FUNCTION_ARGS);
193 
194 /*
195  * Checks whether an ellipse and a line overlap.
196  */
197 Datum	sphereellipse_overlap_line_com(PG_FUNCTION_ARGS);
198 
199 /*
200  * Checks whether an ellipse and a line don't overlap.
201  */
202 Datum	sphereellipse_overlap_line_com_neg(PG_FUNCTION_ARGS);
203 
204 /*
205  * Checks whether an ellipse contains a circle.
206  */
207 Datum	sphereellipse_cont_circle(PG_FUNCTION_ARGS);
208 
209 /*
210  * Checks whether an ellipse doesn't contain a circle.
211  */
212 Datum	sphereellipse_cont_circle_neg(PG_FUNCTION_ARGS);
213 
214 /*
215  * Checks whether an ellipse contains a circle.
216  */
217 Datum	sphereellipse_cont_circle_com(PG_FUNCTION_ARGS);
218 
219 /*
220  * Checks whether an ellipse doesn't contain a circle.
221  */
222 Datum	sphereellipse_cont_circle_com_neg(PG_FUNCTION_ARGS);
223 
224 /*
225  * Checks whether a circle contains an ellipse.
226  */
227 Datum	spherecircle_cont_ellipse(PG_FUNCTION_ARGS);
228 
229 /*
230  * Checks whether a circle doesn't contain an ellipse.
231  */
232 Datum	spherecircle_cont_ellipse_neg(PG_FUNCTION_ARGS);
233 
234 /*
235  * Checks whether a circle contains an ellipse.
236  */
237 Datum	spherecircle_cont_ellipse_com(PG_FUNCTION_ARGS);
238 
239 /*
240  * Checks whether a circle doesn't contain an ellipse.
241  */
242 Datum	spherecircle_cont_ellipse_com_neg(PG_FUNCTION_ARGS);
243 
244 /*
245  * Checks whether a circle and an ellipse overlap.
246  */
247 Datum	sphereellipse_overlap_circle(PG_FUNCTION_ARGS);
248 
249 /*
250  * Checks whether a circle and an ellipse don't overlap.
251  */
252 Datum	sphereellipse_overlap_circle_neg(PG_FUNCTION_ARGS);
253 
254 /*
255  * Checks whether a circle and an ellipse overlap.
256  */
257 Datum	sphereellipse_overlap_circle_com(PG_FUNCTION_ARGS);
258 
259 /*
260  * Checks whether a circle and an ellipse don't overlap.
261  */
262 Datum	sphereellipse_overlap_circle_com_neg(PG_FUNCTION_ARGS);
263 
264 /*
265  * Checks whether an ellipse contains other ellipse.
266  */
267 Datum	sphereellipse_cont_ellipse(PG_FUNCTION_ARGS);
268 
269 /*
270  * Checks whether an ellipse doesn't contain other ellipse.
271  */
272 Datum	sphereellipse_cont_ellipse_neg(PG_FUNCTION_ARGS);
273 
274 /*
275  * Checks whether an ellipse is contained by other ellipse.
276  */
277 Datum	sphereellipse_cont_ellipse_com(PG_FUNCTION_ARGS);
278 
279 /*
280  * Checks whether an ellipse isn't contained by other ellipse.
281  */
282 Datum	sphereellipse_cont_ellipse_com_neg(PG_FUNCTION_ARGS);
283 
284 /*
285  * Checks whether two ellipses overlap.
286  */
287 Datum	sphereellipse_overlap_ellipse(PG_FUNCTION_ARGS);
288 
289 /*
290  * Checks whether two ellipses don't overlap.
291  */
292 Datum	sphereellipse_overlap_ellipse_neg(PG_FUNCTION_ARGS);
293 
294 /*
295  * Transforms an ellipse using an Euler transformation.
296  */
297 Datum	spheretrans_ellipse(PG_FUNCTION_ARGS);
298 
299 /*
300  * Transforms an ellipse using an Euler transformation.
301  */
302 Datum	spheretrans_ellipse_inv(PG_FUNCTION_ARGS);
303 
304 #endif
305