Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GEO_DECLS_H
00022 #define GEO_DECLS_H
00023
00024 #include <math.h>
00025
00026 #include "fmgr.h"
00027
00028
00029
00030
00031
00032
00033 #define EPSILON 1.0E-06
00034
00035 #ifdef EPSILON
00036 #define FPzero(A) (fabs(A) <= EPSILON)
00037 #define FPeq(A,B) (fabs((A) - (B)) <= EPSILON)
00038 #define FPne(A,B) (fabs((A) - (B)) > EPSILON)
00039 #define FPlt(A,B) ((B) - (A) > EPSILON)
00040 #define FPle(A,B) ((A) - (B) <= EPSILON)
00041 #define FPgt(A,B) ((A) - (B) > EPSILON)
00042 #define FPge(A,B) ((B) - (A) <= EPSILON)
00043 #else
00044 #define FPzero(A) ((A) == 0)
00045 #define FPeq(A,B) ((A) == (B))
00046 #define FPne(A,B) ((A) != (B))
00047 #define FPlt(A,B) ((A) < (B))
00048 #define FPle(A,B) ((A) <= (B))
00049 #define FPgt(A,B) ((A) > (B))
00050 #define FPge(A,B) ((A) >= (B))
00051 #endif
00052
00053 #define HYPOT(A, B) pg_hypot(A, B)
00054
00055
00056
00057
00058 typedef struct
00059 {
00060 double x,
00061 y;
00062 } Point;
00063
00064
00065
00066
00067
00068 typedef struct
00069 {
00070 Point p[2];
00071
00072 double m;
00073 } LSEG;
00074
00075
00076
00077
00078
00079 typedef struct
00080 {
00081 int32 vl_len_;
00082 int32 npts;
00083 int32 closed;
00084 int32 dummy;
00085 Point p[1];
00086 } PATH;
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 typedef struct
00098 {
00099 double A,
00100 B,
00101 C;
00102
00103 double m;
00104 } LINE;
00105
00106
00107
00108
00109
00110
00111 typedef struct
00112 {
00113 Point high,
00114 low;
00115 } BOX;
00116
00117
00118
00119
00120
00121
00122 typedef struct
00123 {
00124 int32 vl_len_;
00125 int32 npts;
00126 BOX boundbox;
00127 Point p[1];
00128 } POLYGON;
00129
00130
00131
00132
00133 typedef struct
00134 {
00135 Point center;
00136 double radius;
00137 } CIRCLE;
00138
00139
00140
00141
00142
00143
00144
00145
00146 #define DatumGetPointP(X) ((Point *) DatumGetPointer(X))
00147 #define PointPGetDatum(X) PointerGetDatum(X)
00148 #define PG_GETARG_POINT_P(n) DatumGetPointP(PG_GETARG_DATUM(n))
00149 #define PG_RETURN_POINT_P(x) return PointPGetDatum(x)
00150
00151 #define DatumGetLsegP(X) ((LSEG *) DatumGetPointer(X))
00152 #define LsegPGetDatum(X) PointerGetDatum(X)
00153 #define PG_GETARG_LSEG_P(n) DatumGetLsegP(PG_GETARG_DATUM(n))
00154 #define PG_RETURN_LSEG_P(x) return LsegPGetDatum(x)
00155
00156 #define DatumGetPathP(X) ((PATH *) PG_DETOAST_DATUM(X))
00157 #define DatumGetPathPCopy(X) ((PATH *) PG_DETOAST_DATUM_COPY(X))
00158 #define PathPGetDatum(X) PointerGetDatum(X)
00159 #define PG_GETARG_PATH_P(n) DatumGetPathP(PG_GETARG_DATUM(n))
00160 #define PG_GETARG_PATH_P_COPY(n) DatumGetPathPCopy(PG_GETARG_DATUM(n))
00161 #define PG_RETURN_PATH_P(x) return PathPGetDatum(x)
00162
00163 #define DatumGetLineP(X) ((LINE *) DatumGetPointer(X))
00164 #define LinePGetDatum(X) PointerGetDatum(X)
00165 #define PG_GETARG_LINE_P(n) DatumGetLineP(PG_GETARG_DATUM(n))
00166 #define PG_RETURN_LINE_P(x) return LinePGetDatum(x)
00167
00168 #define DatumGetBoxP(X) ((BOX *) DatumGetPointer(X))
00169 #define BoxPGetDatum(X) PointerGetDatum(X)
00170 #define PG_GETARG_BOX_P(n) DatumGetBoxP(PG_GETARG_DATUM(n))
00171 #define PG_RETURN_BOX_P(x) return BoxPGetDatum(x)
00172
00173 #define DatumGetPolygonP(X) ((POLYGON *) PG_DETOAST_DATUM(X))
00174 #define DatumGetPolygonPCopy(X) ((POLYGON *) PG_DETOAST_DATUM_COPY(X))
00175 #define PolygonPGetDatum(X) PointerGetDatum(X)
00176 #define PG_GETARG_POLYGON_P(n) DatumGetPolygonP(PG_GETARG_DATUM(n))
00177 #define PG_GETARG_POLYGON_P_COPY(n) DatumGetPolygonPCopy(PG_GETARG_DATUM(n))
00178 #define PG_RETURN_POLYGON_P(x) return PolygonPGetDatum(x)
00179
00180 #define DatumGetCircleP(X) ((CIRCLE *) DatumGetPointer(X))
00181 #define CirclePGetDatum(X) PointerGetDatum(X)
00182 #define PG_GETARG_CIRCLE_P(n) DatumGetCircleP(PG_GETARG_DATUM(n))
00183 #define PG_RETURN_CIRCLE_P(x) return CirclePGetDatum(x)
00184
00185
00186
00187
00188
00189
00190
00191 extern Datum point_in(PG_FUNCTION_ARGS);
00192 extern Datum point_out(PG_FUNCTION_ARGS);
00193 extern Datum point_recv(PG_FUNCTION_ARGS);
00194 extern Datum point_send(PG_FUNCTION_ARGS);
00195 extern Datum construct_point(PG_FUNCTION_ARGS);
00196 extern Datum point_left(PG_FUNCTION_ARGS);
00197 extern Datum point_right(PG_FUNCTION_ARGS);
00198 extern Datum point_above(PG_FUNCTION_ARGS);
00199 extern Datum point_below(PG_FUNCTION_ARGS);
00200 extern Datum point_vert(PG_FUNCTION_ARGS);
00201 extern Datum point_horiz(PG_FUNCTION_ARGS);
00202 extern Datum point_eq(PG_FUNCTION_ARGS);
00203 extern Datum point_ne(PG_FUNCTION_ARGS);
00204 extern Datum point_distance(PG_FUNCTION_ARGS);
00205 extern Datum point_slope(PG_FUNCTION_ARGS);
00206 extern Datum point_add(PG_FUNCTION_ARGS);
00207 extern Datum point_sub(PG_FUNCTION_ARGS);
00208 extern Datum point_mul(PG_FUNCTION_ARGS);
00209 extern Datum point_div(PG_FUNCTION_ARGS);
00210
00211
00212 extern double point_dt(Point *pt1, Point *pt2);
00213 extern double point_sl(Point *pt1, Point *pt2);
00214 extern double pg_hypot(double x, double y);
00215
00216
00217 extern Datum lseg_in(PG_FUNCTION_ARGS);
00218 extern Datum lseg_out(PG_FUNCTION_ARGS);
00219 extern Datum lseg_recv(PG_FUNCTION_ARGS);
00220 extern Datum lseg_send(PG_FUNCTION_ARGS);
00221 extern Datum lseg_intersect(PG_FUNCTION_ARGS);
00222 extern Datum lseg_parallel(PG_FUNCTION_ARGS);
00223 extern Datum lseg_perp(PG_FUNCTION_ARGS);
00224 extern Datum lseg_vertical(PG_FUNCTION_ARGS);
00225 extern Datum lseg_horizontal(PG_FUNCTION_ARGS);
00226 extern Datum lseg_eq(PG_FUNCTION_ARGS);
00227 extern Datum lseg_ne(PG_FUNCTION_ARGS);
00228 extern Datum lseg_lt(PG_FUNCTION_ARGS);
00229 extern Datum lseg_le(PG_FUNCTION_ARGS);
00230 extern Datum lseg_gt(PG_FUNCTION_ARGS);
00231 extern Datum lseg_ge(PG_FUNCTION_ARGS);
00232 extern Datum lseg_construct(PG_FUNCTION_ARGS);
00233 extern Datum lseg_length(PG_FUNCTION_ARGS);
00234 extern Datum lseg_distance(PG_FUNCTION_ARGS);
00235 extern Datum lseg_center(PG_FUNCTION_ARGS);
00236 extern Datum lseg_interpt(PG_FUNCTION_ARGS);
00237 extern Datum dist_pl(PG_FUNCTION_ARGS);
00238 extern Datum dist_ps(PG_FUNCTION_ARGS);
00239 extern Datum dist_ppath(PG_FUNCTION_ARGS);
00240 extern Datum dist_pb(PG_FUNCTION_ARGS);
00241 extern Datum dist_sl(PG_FUNCTION_ARGS);
00242 extern Datum dist_sb(PG_FUNCTION_ARGS);
00243 extern Datum dist_lb(PG_FUNCTION_ARGS);
00244 extern Datum close_lseg(PG_FUNCTION_ARGS);
00245 extern Datum close_pl(PG_FUNCTION_ARGS);
00246 extern Datum close_ps(PG_FUNCTION_ARGS);
00247 extern Datum close_pb(PG_FUNCTION_ARGS);
00248 extern Datum close_sl(PG_FUNCTION_ARGS);
00249 extern Datum close_sb(PG_FUNCTION_ARGS);
00250 extern Datum close_ls(PG_FUNCTION_ARGS);
00251 extern Datum close_lb(PG_FUNCTION_ARGS);
00252 extern Datum on_pl(PG_FUNCTION_ARGS);
00253 extern Datum on_ps(PG_FUNCTION_ARGS);
00254 extern Datum on_pb(PG_FUNCTION_ARGS);
00255 extern Datum on_ppath(PG_FUNCTION_ARGS);
00256 extern Datum on_sl(PG_FUNCTION_ARGS);
00257 extern Datum on_sb(PG_FUNCTION_ARGS);
00258 extern Datum inter_sl(PG_FUNCTION_ARGS);
00259 extern Datum inter_sb(PG_FUNCTION_ARGS);
00260 extern Datum inter_lb(PG_FUNCTION_ARGS);
00261
00262
00263 extern Datum line_in(PG_FUNCTION_ARGS);
00264 extern Datum line_out(PG_FUNCTION_ARGS);
00265 extern Datum line_recv(PG_FUNCTION_ARGS);
00266 extern Datum line_send(PG_FUNCTION_ARGS);
00267 extern Datum line_interpt(PG_FUNCTION_ARGS);
00268 extern Datum line_distance(PG_FUNCTION_ARGS);
00269 extern Datum line_construct_pp(PG_FUNCTION_ARGS);
00270 extern Datum line_intersect(PG_FUNCTION_ARGS);
00271 extern Datum line_parallel(PG_FUNCTION_ARGS);
00272 extern Datum line_perp(PG_FUNCTION_ARGS);
00273 extern Datum line_vertical(PG_FUNCTION_ARGS);
00274 extern Datum line_horizontal(PG_FUNCTION_ARGS);
00275 extern Datum line_eq(PG_FUNCTION_ARGS);
00276
00277
00278 extern Datum box_in(PG_FUNCTION_ARGS);
00279 extern Datum box_out(PG_FUNCTION_ARGS);
00280 extern Datum box_recv(PG_FUNCTION_ARGS);
00281 extern Datum box_send(PG_FUNCTION_ARGS);
00282 extern Datum box_same(PG_FUNCTION_ARGS);
00283 extern Datum box_overlap(PG_FUNCTION_ARGS);
00284 extern Datum box_left(PG_FUNCTION_ARGS);
00285 extern Datum box_overleft(PG_FUNCTION_ARGS);
00286 extern Datum box_right(PG_FUNCTION_ARGS);
00287 extern Datum box_overright(PG_FUNCTION_ARGS);
00288 extern Datum box_below(PG_FUNCTION_ARGS);
00289 extern Datum box_overbelow(PG_FUNCTION_ARGS);
00290 extern Datum box_above(PG_FUNCTION_ARGS);
00291 extern Datum box_overabove(PG_FUNCTION_ARGS);
00292 extern Datum box_contained(PG_FUNCTION_ARGS);
00293 extern Datum box_contain(PG_FUNCTION_ARGS);
00294 extern Datum box_contain_pt(PG_FUNCTION_ARGS);
00295 extern Datum box_below_eq(PG_FUNCTION_ARGS);
00296 extern Datum box_above_eq(PG_FUNCTION_ARGS);
00297 extern Datum box_lt(PG_FUNCTION_ARGS);
00298 extern Datum box_gt(PG_FUNCTION_ARGS);
00299 extern Datum box_eq(PG_FUNCTION_ARGS);
00300 extern Datum box_le(PG_FUNCTION_ARGS);
00301 extern Datum box_ge(PG_FUNCTION_ARGS);
00302 extern Datum box_area(PG_FUNCTION_ARGS);
00303 extern Datum box_width(PG_FUNCTION_ARGS);
00304 extern Datum box_height(PG_FUNCTION_ARGS);
00305 extern Datum box_distance(PG_FUNCTION_ARGS);
00306 extern Datum box_center(PG_FUNCTION_ARGS);
00307 extern Datum box_intersect(PG_FUNCTION_ARGS);
00308 extern Datum box_diagonal(PG_FUNCTION_ARGS);
00309 extern Datum points_box(PG_FUNCTION_ARGS);
00310 extern Datum box_add(PG_FUNCTION_ARGS);
00311 extern Datum box_sub(PG_FUNCTION_ARGS);
00312 extern Datum box_mul(PG_FUNCTION_ARGS);
00313 extern Datum box_div(PG_FUNCTION_ARGS);
00314
00315
00316 extern Datum path_area(PG_FUNCTION_ARGS);
00317 extern Datum path_in(PG_FUNCTION_ARGS);
00318 extern Datum path_out(PG_FUNCTION_ARGS);
00319 extern Datum path_recv(PG_FUNCTION_ARGS);
00320 extern Datum path_send(PG_FUNCTION_ARGS);
00321 extern Datum path_n_lt(PG_FUNCTION_ARGS);
00322 extern Datum path_n_gt(PG_FUNCTION_ARGS);
00323 extern Datum path_n_eq(PG_FUNCTION_ARGS);
00324 extern Datum path_n_le(PG_FUNCTION_ARGS);
00325 extern Datum path_n_ge(PG_FUNCTION_ARGS);
00326 extern Datum path_inter(PG_FUNCTION_ARGS);
00327 extern Datum path_distance(PG_FUNCTION_ARGS);
00328 extern Datum path_length(PG_FUNCTION_ARGS);
00329
00330 extern Datum path_isclosed(PG_FUNCTION_ARGS);
00331 extern Datum path_isopen(PG_FUNCTION_ARGS);
00332 extern Datum path_npoints(PG_FUNCTION_ARGS);
00333
00334 extern Datum path_close(PG_FUNCTION_ARGS);
00335 extern Datum path_open(PG_FUNCTION_ARGS);
00336 extern Datum path_add(PG_FUNCTION_ARGS);
00337 extern Datum path_add_pt(PG_FUNCTION_ARGS);
00338 extern Datum path_sub_pt(PG_FUNCTION_ARGS);
00339 extern Datum path_mul_pt(PG_FUNCTION_ARGS);
00340 extern Datum path_div_pt(PG_FUNCTION_ARGS);
00341
00342 extern Datum path_center(PG_FUNCTION_ARGS);
00343 extern Datum path_poly(PG_FUNCTION_ARGS);
00344
00345
00346 extern Datum poly_in(PG_FUNCTION_ARGS);
00347 extern Datum poly_out(PG_FUNCTION_ARGS);
00348 extern Datum poly_recv(PG_FUNCTION_ARGS);
00349 extern Datum poly_send(PG_FUNCTION_ARGS);
00350 extern Datum poly_left(PG_FUNCTION_ARGS);
00351 extern Datum poly_overleft(PG_FUNCTION_ARGS);
00352 extern Datum poly_right(PG_FUNCTION_ARGS);
00353 extern Datum poly_overright(PG_FUNCTION_ARGS);
00354 extern Datum poly_below(PG_FUNCTION_ARGS);
00355 extern Datum poly_overbelow(PG_FUNCTION_ARGS);
00356 extern Datum poly_above(PG_FUNCTION_ARGS);
00357 extern Datum poly_overabove(PG_FUNCTION_ARGS);
00358 extern Datum poly_same(PG_FUNCTION_ARGS);
00359 extern Datum poly_overlap(PG_FUNCTION_ARGS);
00360 extern Datum poly_contain(PG_FUNCTION_ARGS);
00361 extern Datum poly_contained(PG_FUNCTION_ARGS);
00362 extern Datum poly_contain_pt(PG_FUNCTION_ARGS);
00363 extern Datum pt_contained_poly(PG_FUNCTION_ARGS);
00364 extern Datum poly_distance(PG_FUNCTION_ARGS);
00365 extern Datum poly_npoints(PG_FUNCTION_ARGS);
00366 extern Datum poly_center(PG_FUNCTION_ARGS);
00367 extern Datum poly_box(PG_FUNCTION_ARGS);
00368 extern Datum poly_path(PG_FUNCTION_ARGS);
00369 extern Datum box_poly(PG_FUNCTION_ARGS);
00370
00371
00372 extern Datum circle_in(PG_FUNCTION_ARGS);
00373 extern Datum circle_out(PG_FUNCTION_ARGS);
00374 extern Datum circle_recv(PG_FUNCTION_ARGS);
00375 extern Datum circle_send(PG_FUNCTION_ARGS);
00376 extern Datum circle_same(PG_FUNCTION_ARGS);
00377 extern Datum circle_overlap(PG_FUNCTION_ARGS);
00378 extern Datum circle_overleft(PG_FUNCTION_ARGS);
00379 extern Datum circle_left(PG_FUNCTION_ARGS);
00380 extern Datum circle_right(PG_FUNCTION_ARGS);
00381 extern Datum circle_overright(PG_FUNCTION_ARGS);
00382 extern Datum circle_contained(PG_FUNCTION_ARGS);
00383 extern Datum circle_contain(PG_FUNCTION_ARGS);
00384 extern Datum circle_below(PG_FUNCTION_ARGS);
00385 extern Datum circle_above(PG_FUNCTION_ARGS);
00386 extern Datum circle_overbelow(PG_FUNCTION_ARGS);
00387 extern Datum circle_overabove(PG_FUNCTION_ARGS);
00388 extern Datum circle_eq(PG_FUNCTION_ARGS);
00389 extern Datum circle_ne(PG_FUNCTION_ARGS);
00390 extern Datum circle_lt(PG_FUNCTION_ARGS);
00391 extern Datum circle_gt(PG_FUNCTION_ARGS);
00392 extern Datum circle_le(PG_FUNCTION_ARGS);
00393 extern Datum circle_ge(PG_FUNCTION_ARGS);
00394 extern Datum circle_contain_pt(PG_FUNCTION_ARGS);
00395 extern Datum pt_contained_circle(PG_FUNCTION_ARGS);
00396 extern Datum circle_add_pt(PG_FUNCTION_ARGS);
00397 extern Datum circle_sub_pt(PG_FUNCTION_ARGS);
00398 extern Datum circle_mul_pt(PG_FUNCTION_ARGS);
00399 extern Datum circle_div_pt(PG_FUNCTION_ARGS);
00400 extern Datum circle_diameter(PG_FUNCTION_ARGS);
00401 extern Datum circle_radius(PG_FUNCTION_ARGS);
00402 extern Datum circle_distance(PG_FUNCTION_ARGS);
00403 extern Datum dist_pc(PG_FUNCTION_ARGS);
00404 extern Datum dist_cpoly(PG_FUNCTION_ARGS);
00405 extern Datum circle_center(PG_FUNCTION_ARGS);
00406 extern Datum cr_circle(PG_FUNCTION_ARGS);
00407 extern Datum box_circle(PG_FUNCTION_ARGS);
00408 extern Datum circle_box(PG_FUNCTION_ARGS);
00409 extern Datum poly_circle(PG_FUNCTION_ARGS);
00410 extern Datum circle_poly(PG_FUNCTION_ARGS);
00411 extern Datum circle_area(PG_FUNCTION_ARGS);
00412
00413
00414 extern Datum gist_box_compress(PG_FUNCTION_ARGS);
00415 extern Datum gist_box_decompress(PG_FUNCTION_ARGS);
00416 extern Datum gist_box_union(PG_FUNCTION_ARGS);
00417 extern Datum gist_box_picksplit(PG_FUNCTION_ARGS);
00418 extern Datum gist_box_consistent(PG_FUNCTION_ARGS);
00419 extern Datum gist_box_penalty(PG_FUNCTION_ARGS);
00420 extern Datum gist_box_same(PG_FUNCTION_ARGS);
00421 extern Datum gist_poly_compress(PG_FUNCTION_ARGS);
00422 extern Datum gist_poly_consistent(PG_FUNCTION_ARGS);
00423 extern Datum gist_circle_compress(PG_FUNCTION_ARGS);
00424 extern Datum gist_circle_consistent(PG_FUNCTION_ARGS);
00425 extern Datum gist_point_compress(PG_FUNCTION_ARGS);
00426 extern Datum gist_point_consistent(PG_FUNCTION_ARGS);
00427 extern Datum gist_point_distance(PG_FUNCTION_ARGS);
00428
00429
00430 extern Datum areasel(PG_FUNCTION_ARGS);
00431 extern Datum areajoinsel(PG_FUNCTION_ARGS);
00432 extern Datum positionsel(PG_FUNCTION_ARGS);
00433 extern Datum positionjoinsel(PG_FUNCTION_ARGS);
00434 extern Datum contsel(PG_FUNCTION_ARGS);
00435 extern Datum contjoinsel(PG_FUNCTION_ARGS);
00436
00437 #endif