1 #ifndef __PGS_POLYGON_H__ 2 #define __PGS_POLYGON_H__ 3 4 #include "ellipse.h" 5 6 /* Polygon declarations */ 7 8 9 /* 10 * The definition of spherical polygon using a list of 11 * spherical points. 12 */ 13 typedef struct 14 { 15 int32 size; /* total size in bytes */ 16 int32 npts; /* count of points */ 17 SPoint p[1]; /* variable length array of SPoints */ 18 } SPOLY; 19 20 21 /* Polygon and ellipse */ 22 #define PGS_ELLIPSE_POLY_AVOID 0 /* ellipse avoids polygon */ 23 #define PGS_POLY_CONT_ELLIPSE 1 /* polygon contains ellipse */ 24 #define PGS_ELLIPSE_CONT_POLY 2 /* ellipse contains polygon */ 25 #define PGS_ELLIPSE_POLY_OVER 3 /* ellipse overlaps polygon */ 26 27 /* Polygon and circle */ 28 #define PGS_CIRCLE_POLY_AVOID 0 /* circle avoids polygon */ 29 #define PGS_POLY_CONT_CIRCLE 1 /* polygon contains circle */ 30 #define PGS_CIRCLE_CONT_POLY 2 /* circle contains polygon */ 31 #define PGS_CIRCLE_POLY_OVER 3 /* circle overlap polygon */ 32 33 /* Polygon and line */ 34 #define PGS_LINE_POLY_AVOID 0 /* line avoids polygon */ 35 #define PGS_POLY_CONT_LINE 1 /* polygon contains line */ 36 #define PGS_LINE_POLY_OVER 2 /* line overlap polygon */ 37 38 /* Polygon and polygon */ 39 #define PGS_POLY_AVOID 0 /* polygon avoids other polygon */ 40 #define PGS_POLY_CONT 1 /* polygon contains other polygon */ 41 #define PGS_POLY_OVER 2 /* polygons overlap */ 42 43 44 #define PG_GETARG_SPOLY( arg ) \ 45 ( (SPOLY *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(arg))) ) 46 47 /* 48 * Checks whether two polygons are equal. 49 * 50 * p1 - pointer to the first polygon 51 * p2 - pointer to the second polygon 52 * 53 * If 'dir' is true, check with reverse polygon of 'p2'. 54 */ 55 bool spoly_eq(const SPOLY *p1, const SPOLY *p2, bool dir); 56 57 /* 58 * Returns the i-th line segment of a polygon. 59 * 60 * sl - pointer to the line segment 61 * poly - pointer to the polygon 62 * i - number of the segment 63 */ 64 bool spoly_segment(SLine *sl, const SPOLY *poly, int32 i); 65 66 /* 67 * Checks whether a polygon contains a point. 68 * 69 * pg - pointer to the polygon 70 * sp - pointer to the point 71 */ 72 bool spoly_contains_point(const SPOLY *pg, const SPoint *sp); 73 74 /* 75 * Returns the relationship between a polygon and a line as 76 * PGS_LINE_POLY_REL int8 value. 77 * 78 * poly - pointer to the polygon 79 * line - pointer to the line 80 */ 81 int8 poly_line_pos(const SPOLY *poly, const SLine *line); 82 83 /* 84 * Input of a spherical polygon. 85 */ 86 Datum spherepoly_in(PG_FUNCTION_ARGS); 87 88 /* 89 * Checks whether two polygons are equal. 90 */ 91 Datum spherepoly_equal(PG_FUNCTION_ARGS); 92 93 /* 94 * Checks whether two polygons are not equal. 95 */ 96 Datum spherepoly_equal_neg(PG_FUNCTION_ARGS); 97 98 /* 99 * Circumstance of a polygon. Returns circumference in radians 100 * (float8 datum). 101 */ 102 Datum spherepoly_circ(PG_FUNCTION_ARGS); 103 104 /* 105 * Count points (edges) of a polygon. 106 */ 107 Datum spherepoly_npts(PG_FUNCTION_ARGS); 108 109 /* 110 * Returns area of a polygon. 111 */ 112 Datum spherepoly_area(PG_FUNCTION_ARGS); 113 114 /* 115 * Checks whether a polygon contains a point. 116 */ 117 Datum spherepoly_cont_point(PG_FUNCTION_ARGS); 118 119 /* 120 * Checks whether a polygon doesn't contain a point. 121 */ 122 Datum spherepoly_cont_point_neg(PG_FUNCTION_ARGS); 123 124 /* 125 * Checks whether a polygon contains a point. 126 */ 127 Datum spherepoly_cont_point_com(PG_FUNCTION_ARGS); 128 129 /* 130 * Checks whether a polygon doesn't contain a point. 131 */ 132 Datum spherepoly_cont_point_com_neg(PG_FUNCTION_ARGS); 133 134 /* 135 * Checks whether a polygon contains a circle. 136 */ 137 Datum spherepoly_cont_circle(PG_FUNCTION_ARGS); 138 139 /* 140 * Checks whether a polygon doesn't contain a circle. 141 */ 142 Datum spherepoly_cont_circle_neg(PG_FUNCTION_ARGS); 143 144 /* 145 * Checks whether a polygon contains a circle. 146 */ 147 Datum spherepoly_cont_circle_com(PG_FUNCTION_ARGS); 148 149 /* 150 * Checks whether a polygon doesn't contain a circle. 151 */ 152 Datum spherepoly_cont_circle_com_neg(PG_FUNCTION_ARGS); 153 154 /* 155 * Checks whether a circle contains a polygon. 156 */ 157 Datum spherecircle_cont_poly(PG_FUNCTION_ARGS); 158 159 /* 160 * Checks whether a circle doesn't contain a polygon. 161 */ 162 Datum spherecircle_cont_poly_neg(PG_FUNCTION_ARGS); 163 164 /* 165 * Checks whether a circle contains a polygon. 166 */ 167 Datum spherecircle_cont_poly_com(PG_FUNCTION_ARGS); 168 169 /* 170 * Checks whether a circle doesn't contain a polygon. 171 */ 172 Datum spherecircle_cont_poly_com_neg(PG_FUNCTION_ARGS); 173 174 /* 175 * Checks whether a polygon and a circle overlap. 176 */ 177 Datum spherepoly_overlap_circle(PG_FUNCTION_ARGS); 178 179 /* 180 * Checks whether a polygon and a circle don't overlap. 181 */ 182 Datum spherepoly_overlap_circle_neg(PG_FUNCTION_ARGS); 183 184 /* 185 * Checks whether a polygon and a circle overlap. 186 */ 187 Datum spherepoly_overlap_circle_com(PG_FUNCTION_ARGS); 188 189 /* 190 * Checks whether a polygon and a circle don't overlap. 191 */ 192 Datum spherepoly_overlap_circle_com_neg(PG_FUNCTION_ARGS); 193 194 /* 195 * Checks whether a polygon contains a line. 196 */ 197 Datum spherepoly_cont_line(PG_FUNCTION_ARGS); 198 199 /* 200 * Checks whether a polygon doesn't contain a line. 201 */ 202 Datum spherepoly_cont_line_neg(PG_FUNCTION_ARGS); 203 204 /* 205 * Checks whether a polygon contains a line. 206 */ 207 Datum spherepoly_cont_line_com(PG_FUNCTION_ARGS); 208 209 /* 210 * Checks whether a polygon doesn't contain a line. 211 */ 212 Datum spherepoly_cont_line_com_neg(PG_FUNCTION_ARGS); 213 214 /* 215 * Checks whether a polygon and a line overlap. 216 */ 217 Datum spherepoly_overlap_line(PG_FUNCTION_ARGS); 218 219 /* 220 * Checks whether a polygon and a line don't overlap. 221 */ 222 Datum spherepoly_overlap_line_neg(PG_FUNCTION_ARGS); 223 224 /* 225 * Checks whether a polygon and a line overlap. 226 */ 227 Datum spherepoly_overlap_line_com(PG_FUNCTION_ARGS); 228 229 /* 230 * Checks whether a polygon and a line don't overlap. 231 */ 232 Datum spherepoly_overlap_line_com_neg(PG_FUNCTION_ARGS); 233 234 /* 235 * Checks whether a polygon contains other polygon. 236 */ 237 Datum spherepoly_cont_poly(PG_FUNCTION_ARGS); 238 239 /* 240 * Checks whether a polygon doesn't contain other polygon. 241 */ 242 Datum spherepoly_cont_poly_neg(PG_FUNCTION_ARGS); 243 244 /* 245 * Checks whether a polygon contains other polygon. 246 */ 247 Datum spherepoly_cont_poly_com(PG_FUNCTION_ARGS); 248 249 /* 250 * Checks whether a polygon doesn't contain other polygon. 251 */ 252 Datum spherepoly_cont_poly_com_neg(PG_FUNCTION_ARGS); 253 254 /* 255 * Checks whether two polygons overlap. 256 */ 257 Datum spherepoly_overlap_poly(PG_FUNCTION_ARGS); 258 259 /* 260 * Checks whether two polygons don't overlap. 261 */ 262 Datum spherepoly_overlap_poly_neg(PG_FUNCTION_ARGS); 263 264 /* 265 * Checks whether a polygon contains an ellipse. 266 */ 267 Datum spherepoly_cont_ellipse(PG_FUNCTION_ARGS); 268 269 /* 270 * Checks whether a polygon doesn't contain an ellipse. 271 */ 272 Datum spherepoly_cont_ellipse_neg(PG_FUNCTION_ARGS); 273 274 /* 275 * Checks whether a polygon contains an ellipse. 276 */ 277 Datum spherepoly_cont_ellipse_com(PG_FUNCTION_ARGS); 278 279 /* 280 * Checks whether a polygon doesn't contain an ellipse. 281 */ 282 Datum spherepoly_cont_ellipse_com_neg(PG_FUNCTION_ARGS); 283 284 /* 285 * Checks whether an ellipse contains a polygon. 286 */ 287 Datum sphereellipse_cont_poly(PG_FUNCTION_ARGS); 288 289 /* 290 * Checks whether an ellipse doesn't contain a polygon. 291 */ 292 Datum sphereellipse_cont_poly_neg(PG_FUNCTION_ARGS); 293 294 /* 295 * Checks whether an ellipse contains a polygon. 296 */ 297 Datum sphereellipse_cont_poly_com(PG_FUNCTION_ARGS); 298 299 /* 300 * Checks whether an ellipse doesn't contain a polygon. 301 */ 302 Datum sphereellipse_cont_poly_com_neg(PG_FUNCTION_ARGS); 303 304 /* 305 * Checks whether a polygon and an ellipse overlap. 306 */ 307 Datum spherepoly_overlap_ellipse(PG_FUNCTION_ARGS); 308 309 /* 310 * Checks whether a polygon and an ellipse don't overlap. 311 */ 312 Datum spherepoly_overlap_ellipse_neg(PG_FUNCTION_ARGS); 313 314 /* 315 * Checks whether a polygon and an ellipse overlap. 316 */ 317 Datum spherepoly_overlap_ellipse_com(PG_FUNCTION_ARGS); 318 319 /* 320 * Checks whether a polygon and an ellipse don't overlap. 321 */ 322 Datum spherepoly_overlap_ellipse_com_neg(PG_FUNCTION_ARGS); 323 324 /* 325 * Performs inverse transform on a polygon using an Euler transformation. 326 */ 327 Datum spheretrans_poly(PG_FUNCTION_ARGS); 328 329 /* 330 * Performs inverse transform on a polygon using an Euler transformation. 331 */ 332 Datum spheretrans_poly_inverse(PG_FUNCTION_ARGS); 333 334 /* 335 * State transition function for the aggregate function spoly(spoint). Never 336 * call this function outside an aggregate function! Adds a point to a polygon. 337 */ 338 Datum spherepoly_add_point(PG_FUNCTION_ARGS); 339 340 /* 341 * Finalize function for adding spoints to a polygon. 342 */ 343 Datum spherepoly_add_points_finalize(PG_FUNCTION_ARGS); 344 345 #endif 346