PostgreSQL Source Code  git master
geo_decls.h File Reference
#include <math.h>
#include "fmgr.h"
Include dependency graph for geo_decls.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Point
 
struct  LSEG
 
struct  PATH
 
struct  LINE
 
struct  BOX
 
struct  POLYGON
 
struct  CIRCLE
 

Macros

#define EPSILON   1.0E-06
 
#define FPzero(A)   (fabs(A) <= EPSILON)
 
#define FPeq(A, B)   (fabs((A) - (B)) <= EPSILON)
 
#define FPne(A, B)   (fabs((A) - (B)) > EPSILON)
 
#define FPlt(A, B)   ((B) - (A) > EPSILON)
 
#define FPle(A, B)   ((A) - (B) <= EPSILON)
 
#define FPgt(A, B)   ((A) - (B) > EPSILON)
 
#define FPge(A, B)   ((B) - (A) <= EPSILON)
 
#define HYPOT(A, B)   pg_hypot(A, B)
 
#define DatumGetPointP(X)   ((Point *) DatumGetPointer(X))
 
#define PointPGetDatum(X)   PointerGetDatum(X)
 
#define PG_GETARG_POINT_P(n)   DatumGetPointP(PG_GETARG_DATUM(n))
 
#define PG_RETURN_POINT_P(x)   return PointPGetDatum(x)
 
#define DatumGetLsegP(X)   ((LSEG *) DatumGetPointer(X))
 
#define LsegPGetDatum(X)   PointerGetDatum(X)
 
#define PG_GETARG_LSEG_P(n)   DatumGetLsegP(PG_GETARG_DATUM(n))
 
#define PG_RETURN_LSEG_P(x)   return LsegPGetDatum(x)
 
#define DatumGetPathP(X)   ((PATH *) PG_DETOAST_DATUM(X))
 
#define DatumGetPathPCopy(X)   ((PATH *) PG_DETOAST_DATUM_COPY(X))
 
#define PathPGetDatum(X)   PointerGetDatum(X)
 
#define PG_GETARG_PATH_P(n)   DatumGetPathP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_PATH_P_COPY(n)   DatumGetPathPCopy(PG_GETARG_DATUM(n))
 
#define PG_RETURN_PATH_P(x)   return PathPGetDatum(x)
 
#define DatumGetLineP(X)   ((LINE *) DatumGetPointer(X))
 
#define LinePGetDatum(X)   PointerGetDatum(X)
 
#define PG_GETARG_LINE_P(n)   DatumGetLineP(PG_GETARG_DATUM(n))
 
#define PG_RETURN_LINE_P(x)   return LinePGetDatum(x)
 
#define DatumGetBoxP(X)   ((BOX *) DatumGetPointer(X))
 
#define BoxPGetDatum(X)   PointerGetDatum(X)
 
#define PG_GETARG_BOX_P(n)   DatumGetBoxP(PG_GETARG_DATUM(n))
 
#define PG_RETURN_BOX_P(x)   return BoxPGetDatum(x)
 
#define DatumGetPolygonP(X)   ((POLYGON *) PG_DETOAST_DATUM(X))
 
#define DatumGetPolygonPCopy(X)   ((POLYGON *) PG_DETOAST_DATUM_COPY(X))
 
#define PolygonPGetDatum(X)   PointerGetDatum(X)
 
#define PG_GETARG_POLYGON_P(n)   DatumGetPolygonP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_POLYGON_P_COPY(n)   DatumGetPolygonPCopy(PG_GETARG_DATUM(n))
 
#define PG_RETURN_POLYGON_P(x)   return PolygonPGetDatum(x)
 
#define DatumGetCircleP(X)   ((CIRCLE *) DatumGetPointer(X))
 
#define CirclePGetDatum(X)   PointerGetDatum(X)
 
#define PG_GETARG_CIRCLE_P(n)   DatumGetCircleP(PG_GETARG_DATUM(n))
 
#define PG_RETURN_CIRCLE_P(x)   return CirclePGetDatum(x)
 

Functions

double point_dt (Point *pt1, Point *pt2)
 
double point_sl (Point *pt1, Point *pt2)
 
double pg_hypot (double x, double y)
 

Macro Definition Documentation

◆ BoxPGetDatum

◆ CirclePGetDatum

#define CirclePGetDatum (   X)    PointerGetDatum(X)

Definition at line 172 of file geo_decls.h.

Referenced by gist_point_consistent(), and poly_center().

◆ DatumGetBoxP

◆ DatumGetCircleP

#define DatumGetCircleP (   X)    ((CIRCLE *) DatumGetPointer(X))

Definition at line 171 of file geo_decls.h.

Referenced by gist_circle_compress(), and poly_center().

◆ DatumGetLineP

#define DatumGetLineP (   X)    ((LINE *) DatumGetPointer(X))

Definition at line 154 of file geo_decls.h.

◆ DatumGetLsegP

#define DatumGetLsegP (   X)    ((LSEG *) DatumGetPointer(X))

Definition at line 142 of file geo_decls.h.

◆ DatumGetPathP

#define DatumGetPathP (   X)    ((PATH *) PG_DETOAST_DATUM(X))

Definition at line 147 of file geo_decls.h.

Referenced by poly2path().

◆ DatumGetPathPCopy

#define DatumGetPathPCopy (   X)    ((PATH *) PG_DETOAST_DATUM_COPY(X))

Definition at line 148 of file geo_decls.h.

◆ DatumGetPointP

◆ DatumGetPolygonP

#define DatumGetPolygonP (   X)    ((POLYGON *) PG_DETOAST_DATUM(X))

Definition at line 164 of file geo_decls.h.

Referenced by gist_poly_compress().

◆ DatumGetPolygonPCopy

#define DatumGetPolygonPCopy (   X)    ((POLYGON *) PG_DETOAST_DATUM_COPY(X))

Definition at line 165 of file geo_decls.h.

◆ EPSILON

#define EPSILON   1.0E-06

Definition at line 33 of file geo_decls.h.

◆ FPeq

◆ FPge

◆ FPgt

◆ FPle

◆ FPlt

◆ FPne

#define FPne (   A,
 
)    (fabs((A) - (B)) > EPSILON)

Definition at line 38 of file geo_decls.h.

Referenced by circle_ne(), and point_ne().

◆ FPzero

◆ HYPOT

#define HYPOT (   A,
 
)    pg_hypot(A, B)

◆ LinePGetDatum

#define LinePGetDatum (   X)    PointerGetDatum(X)

Definition at line 155 of file geo_decls.h.

Referenced by line_distance(), line_interpt_internal(), line_intersect(), and on_sl().

◆ LsegPGetDatum

#define LsegPGetDatum (   X)    PointerGetDatum(X)

◆ PathPGetDatum

#define PathPGetDatum (   X)    PointerGetDatum(X)

Definition at line 149 of file geo_decls.h.

◆ PG_GETARG_BOX_P

◆ PG_GETARG_CIRCLE_P

◆ PG_GETARG_LINE_P

◆ PG_GETARG_LSEG_P

◆ PG_GETARG_PATH_P

◆ PG_GETARG_PATH_P_COPY

#define PG_GETARG_PATH_P_COPY (   n)    DatumGetPathPCopy(PG_GETARG_DATUM(n))

Definition at line 151 of file geo_decls.h.

Referenced by path_add_pt(), path_close(), path_div_pt(), path_mul_pt(), path_open(), and path_sub_pt().

◆ PG_GETARG_POINT_P

◆ PG_GETARG_POLYGON_P

◆ PG_GETARG_POLYGON_P_COPY

#define PG_GETARG_POLYGON_P_COPY (   n)    DatumGetPolygonPCopy(PG_GETARG_DATUM(n))

Definition at line 168 of file geo_decls.h.

◆ PG_RETURN_BOX_P

#define PG_RETURN_BOX_P (   x)    return BoxPGetDatum(x)

◆ PG_RETURN_CIRCLE_P

#define PG_RETURN_CIRCLE_P (   x)    return CirclePGetDatum(x)

◆ PG_RETURN_LINE_P

#define PG_RETURN_LINE_P (   x)    return LinePGetDatum(x)

Definition at line 157 of file geo_decls.h.

Referenced by line_construct_pp(), line_in(), and line_recv().

◆ PG_RETURN_LSEG_P

#define PG_RETURN_LSEG_P (   x)    return LsegPGetDatum(x)

Definition at line 145 of file geo_decls.h.

Referenced by box_diagonal(), lseg_construct(), lseg_in(), and lseg_recv().

◆ PG_RETURN_PATH_P

#define PG_RETURN_PATH_P (   x)    return PathPGetDatum(x)

◆ PG_RETURN_POINT_P

◆ PG_RETURN_POLYGON_P

#define PG_RETURN_POLYGON_P (   x)    return PolygonPGetDatum(x)

Definition at line 169 of file geo_decls.h.

Referenced by box_poly(), circle_poly(), path_poly(), poly_in(), and poly_recv().

◆ PointPGetDatum

◆ PolygonPGetDatum

#define PolygonPGetDatum (   X)    PointerGetDatum(X)

Definition at line 166 of file geo_decls.h.

Referenced by gist_point_consistent(), and poly_center().

Function Documentation

◆ pg_hypot()

double pg_hypot ( double  x,
double  y 
)

Definition at line 5454 of file geo_ops.c.

References get_float8_infinity(), get_float8_nan(), and isinf().

5455 {
5456  double yx;
5457 
5458  /* Handle INF and NaN properly */
5459  if (isinf(x) || isinf(y))
5460  return get_float8_infinity();
5461 
5462  if (isnan(x) || isnan(y))
5463  return get_float8_nan();
5464 
5465  /* Else, drop any minus signs */
5466  x = fabs(x);
5467  y = fabs(y);
5468 
5469  /* Swap x and y if needed to make x the larger one */
5470  if (x < y)
5471  {
5472  double temp = x;
5473 
5474  x = y;
5475  y = temp;
5476  }
5477 
5478  /*
5479  * If y is zero, the hypotenuse is x. This test saves a few cycles in
5480  * such cases, but more importantly it also protects against
5481  * divide-by-zero errors, since now x >= y.
5482  */
5483  if (y == 0.0)
5484  return x;
5485 
5486  /* Determine the hypotenuse */
5487  yx = y / x;
5488  return x * sqrt(1.0 + (yx * yx));
5489 }
double get_float8_nan(void)
Definition: float.c:167
int isinf(double x)
double get_float8_infinity(void)
Definition: float.c:122

◆ point_dt()

double point_dt ( Point pt1,
Point pt2 
)

Definition at line 1906 of file geo_ops.c.

References HYPOT, Point::x, and Point::y.

Referenced by box_circle(), circle_contain(), circle_contain_pt(), circle_contained(), circle_distance(), circle_overlap(), dist_cpoint(), dist_pb(), dist_pc(), dist_ppath(), dist_ps_internal(), lseg_ge(), lseg_gt(), lseg_le(), lseg_length(), lseg_lt(), on_ppath(), on_ps_internal(), path_length(), poly_circle(), pt_contained_circle(), pt_in_widget(), and regress_dist_ptpath().

1907 {
1908 #ifdef GEODEBUG
1909  printf("point_dt- segment (%f,%f),(%f,%f) length is %f\n",
1910  pt1->x, pt1->y, pt2->x, pt2->y, HYPOT(pt1->x - pt2->x, pt1->y - pt2->y));
1911 #endif
1912  return HYPOT(pt1->x - pt2->x, pt1->y - pt2->y);
1913 }
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
#define HYPOT(A, B)
Definition: geo_decls.h:53

◆ point_sl()

double point_sl ( Point pt1,
Point pt2 
)

Definition at line 1926 of file geo_ops.c.

References FPeq, Point::x, and Point::y.

Referenced by close_ps(), lseg_parallel(), lseg_perp(), and point_slope().

1927 {
1928  return (FPeq(pt1->x, pt2->x)
1929  ? (double) DBL_MAX
1930  : (pt1->y - pt2->y) / (pt1->x - pt2->x));
1931 }
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
#define FPeq(A, B)
Definition: geo_decls.h:37