1/*-------------------------------------------------------------------------
3 * geo_decls.h - Declarations for various 2D constructs.
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/utils/geo_decls.h
11 * XXX These routines were not written by a numerical analyst.
13 * XXX I have made some attempt to flesh out the operators
14 * and data types. There are still some more to do. - tgl 97/04/19
16 *-------------------------------------------------------------------------
25/*--------------------------------------------------------------------
26 * Useful floating point utilities and constants.
27 *--------------------------------------------------------------------
29 * "Fuzzy" floating-point comparisons: values within EPSILON of each other
30 * are considered equal. Beware of normal reasoning about the behavior of
31 * these comparisons, since for example FPeq does not behave transitively.
33 * Note that these functions are not NaN-aware and will give FALSE for
34 * any case involving NaN inputs.
36 * Also note that these will give sane answers for infinite inputs,
37 * where it's important to avoid computing Inf minus Inf; we do so
38 * by eliminating equality cases before subtracting.
41 #define EPSILON 1.0E-06
44 #define FPzero(A) (fabs(A) <= EPSILON)
49 return A == B || fabs(A - B) <=
EPSILON;
55 return A != B && fabs(A - B) >
EPSILON;
82#define FPzero(A) ((A) == 0)
83#define FPeq(A,B) ((A) == (B))
84#define FPne(A,B) ((A) != (B))
85#define FPlt(A,B) ((A) < (B))
86#define FPle(A,B) ((A) <= (B))
87#define FPgt(A,B) ((A) > (B))
88#define FPge(A,B) ((A) >= (B))
91 #define HYPOT(A, B) pg_hypot(A, B)
93/*---------------------------------------------------------------------
95 *-------------------------------------------------------------------*/
103/*---------------------------------------------------------------------
104 * LSEG - A straight line, specified by endpoints.
105 *-------------------------------------------------------------------*/
112/*---------------------------------------------------------------------
113 * PATH - Specified by vertex points.
114 *-------------------------------------------------------------------*/
125/*---------------------------------------------------------------------
126 * LINE - Specified by its general equation (Ax+By+C=0).
127 *-------------------------------------------------------------------*/
136/*---------------------------------------------------------------------
137 * BOX - Specified by two corner points, which are
138 * sorted to save calculation time later.
139 *-------------------------------------------------------------------*/
146/*---------------------------------------------------------------------
147 * POLYGON - Specified by an array of doubles defining the points,
148 * keeping the number of points and the bounding box for
150 *-------------------------------------------------------------------*/
159/*---------------------------------------------------------------------
160 * CIRCLE - Specified by a center point and radius.
161 *-------------------------------------------------------------------*/
169 * fmgr interface functions
171 * Path and Polygon are toastable varlena types, the others are just
172 * fixed-size pass-by-reference types.
185 #define PG_GETARG_POINT_P(n) DatumGetPointP(PG_GETARG_DATUM(n))
186 #define PG_RETURN_POINT_P(x) return PointPGetDatum(x)
198 #define PG_GETARG_LSEG_P(n) DatumGetLsegP(PG_GETARG_DATUM(n))
199 #define PG_RETURN_LSEG_P(x) return LsegPGetDatum(x)
216 #define PG_GETARG_PATH_P(n) DatumGetPathP(PG_GETARG_DATUM(n))
217 #define PG_GETARG_PATH_P_COPY(n) DatumGetPathPCopy(PG_GETARG_DATUM(n))
218 #define PG_RETURN_PATH_P(x) return PathPGetDatum(x)
230 #define PG_GETARG_LINE_P(n) DatumGetLineP(PG_GETARG_DATUM(n))
231 #define PG_RETURN_LINE_P(x) return LinePGetDatum(x)
243 #define PG_GETARG_BOX_P(n) DatumGetBoxP(PG_GETARG_DATUM(n))
244 #define PG_RETURN_BOX_P(x) return BoxPGetDatum(x)
261 #define PG_GETARG_POLYGON_P(n) DatumGetPolygonP(PG_GETARG_DATUM(n))
262 #define PG_GETARG_POLYGON_P_COPY(n) DatumGetPolygonPCopy(PG_GETARG_DATUM(n))
263 #define PG_RETURN_POLYGON_P(x) return PolygonPGetDatum(x)
275 #define PG_GETARG_CIRCLE_P(n) DatumGetCircleP(PG_GETARG_DATUM(n))
276 #define PG_RETURN_CIRCLE_P(x) return CirclePGetDatum(x)
285#endif /* GEO_DECLS_H */
#define FLEXIBLE_ARRAY_MEMBER
#define PG_DETOAST_DATUM_COPY(datum)
#define PG_DETOAST_DATUM(datum)
static Datum PathPGetDatum(const PATH *X)
static bool FPlt(double A, double B)
static Datum LsegPGetDatum(const LSEG *X)
static bool FPge(double A, double B)
static Datum PolygonPGetDatum(const POLYGON *X)
static PATH * DatumGetPathPCopy(Datum X)
static POLYGON * DatumGetPolygonPCopy(Datum X)
static LINE * DatumGetLineP(Datum X)
static Point * DatumGetPointP(Datum X)
static Datum LinePGetDatum(const LINE *X)
static PATH * DatumGetPathP(Datum X)
float8 pg_hypot(float8 x, float8 y)
static Datum PointPGetDatum(const Point *X)
static POLYGON * DatumGetPolygonP(Datum X)
static bool FPne(double A, double B)
static BOX * DatumGetBoxP(Datum X)
static CIRCLE * DatumGetCircleP(Datum X)
static Datum CirclePGetDatum(const CIRCLE *X)
static LSEG * DatumGetLsegP(Datum X)
static bool FPgt(double A, double B)
static bool FPle(double A, double B)
static Datum BoxPGetDatum(const BOX *X)
static bool FPeq(double A, double B)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)