gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 line
5.6KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * geo_decls.h - Declarations for various 2D constructs.
  4. *
  5. *
  6. * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/utils/geo_decls.h
  10. *
  11. * XXX These routines were not written by a numerical analyst.
  12. *
  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
  15. *
  16. *-------------------------------------------------------------------------
  17. */
  18. #ifndef GEO_DECLS_H
  19. #define GEO_DECLS_H
  20. #include "fmgr.h"
  21. /*--------------------------------------------------------------------
  22. * Useful floating point utilities and constants.
  23. *-------------------------------------------------------------------
  24. *
  25. * XXX: They are not NaN-aware.
  26. */
  27. #define EPSILON 1.0E-06
  28. #ifdef EPSILON
  29. #define FPzero(A) (fabs(A) <= EPSILON)
  30. #define FPeq(A,B) (fabs((A) - (B)) <= EPSILON)
  31. #define FPne(A,B) (fabs((A) - (B)) > EPSILON)
  32. #define FPlt(A,B) ((B) - (A) > EPSILON)
  33. #define FPle(A,B) ((A) - (B) <= EPSILON)
  34. #define FPgt(A,B) ((A) - (B) > EPSILON)
  35. #define FPge(A,B) ((B) - (A) <= EPSILON)
  36. #else
  37. #define FPzero(A) ((A) == 0)
  38. #define FPeq(A,B) ((A) == (B))
  39. #define FPne(A,B) ((A) != (B))
  40. #define FPlt(A,B) ((A) < (B))
  41. #define FPle(A,B) ((A) <= (B))
  42. #define FPgt(A,B) ((A) > (B))
  43. #define FPge(A,B) ((A) >= (B))
  44. #endif
  45. #define HYPOT(A, B) pg_hypot(A, B)
  46. /*---------------------------------------------------------------------
  47. * Point - (x,y)
  48. *-------------------------------------------------------------------*/
  49. typedef struct
  50. {
  51. float8 x,
  52. y;
  53. } Point;
  54. /*---------------------------------------------------------------------
  55. * LSEG - A straight line, specified by endpoints.
  56. *-------------------------------------------------------------------*/
  57. typedef struct
  58. {
  59. Point p[2];
  60. } LSEG;
  61. /*---------------------------------------------------------------------
  62. * PATH - Specified by vertex points.
  63. *-------------------------------------------------------------------*/
  64. typedef struct
  65. {
  66. int32 vl_len_; /* varlena header (do not touch directly!) */
  67. int32 npts;
  68. int32 closed; /* is this a closed polygon? */
  69. int32 dummy; /* padding to make it double align */
  70. Point p[FLEXIBLE_ARRAY_MEMBER];
  71. } PATH;
  72. /*---------------------------------------------------------------------
  73. * LINE - Specified by its general equation (Ax+By+C=0).
  74. *-------------------------------------------------------------------*/
  75. typedef struct
  76. {
  77. float8 A,
  78. B,
  79. C;
  80. } LINE;
  81. /*---------------------------------------------------------------------
  82. * BOX - Specified by two corner points, which are
  83. * sorted to save calculation time later.
  84. *-------------------------------------------------------------------*/
  85. typedef struct
  86. {
  87. Point high,
  88. low; /* corner POINTs */
  89. } BOX;
  90. /*---------------------------------------------------------------------
  91. * POLYGON - Specified by an array of doubles defining the points,
  92. * keeping the number of points and the bounding box for
  93. * speed purposes.
  94. *-------------------------------------------------------------------*/
  95. typedef struct
  96. {
  97. int32 vl_len_; /* varlena header (do not touch directly!) */
  98. int32 npts;
  99. BOX boundbox;
  100. Point p[FLEXIBLE_ARRAY_MEMBER];
  101. } POLYGON;
  102. /*---------------------------------------------------------------------
  103. * CIRCLE - Specified by a center point and radius.
  104. *-------------------------------------------------------------------*/
  105. typedef struct
  106. {
  107. Point center;
  108. float8 radius;
  109. } CIRCLE;
  110. /*
  111. * fmgr interface macros
  112. *
  113. * Path and Polygon are toastable varlena types, the others are just
  114. * fixed-size pass-by-reference types.
  115. */
  116. #define DatumGetPointP(X) ((Point *) DatumGetPointer(X))
  117. #define PointPGetDatum(X) PointerGetDatum(X)
  118. #define PG_GETARG_POINT_P(n) DatumGetPointP(PG_GETARG_DATUM(n))
  119. #define PG_RETURN_POINT_P(x) return PointPGetDatum(x)
  120. #define DatumGetLsegP(X) ((LSEG *) DatumGetPointer(X))
  121. #define LsegPGetDatum(X) PointerGetDatum(X)
  122. #define PG_GETARG_LSEG_P(n) DatumGetLsegP(PG_GETARG_DATUM(n))
  123. #define PG_RETURN_LSEG_P(x) return LsegPGetDatum(x)
  124. #define DatumGetPathP(X) ((PATH *) PG_DETOAST_DATUM(X))
  125. #define DatumGetPathPCopy(X) ((PATH *) PG_DETOAST_DATUM_COPY(X))
  126. #define PathPGetDatum(X) PointerGetDatum(X)
  127. #define PG_GETARG_PATH_P(n) DatumGetPathP(PG_GETARG_DATUM(n))
  128. #define PG_GETARG_PATH_P_COPY(n) DatumGetPathPCopy(PG_GETARG_DATUM(n))
  129. #define PG_RETURN_PATH_P(x) return PathPGetDatum(x)
  130. #define DatumGetLineP(X) ((LINE *) DatumGetPointer(X))
  131. #define LinePGetDatum(X) PointerGetDatum(X)
  132. #define PG_GETARG_LINE_P(n) DatumGetLineP(PG_GETARG_DATUM(n))
  133. #define PG_RETURN_LINE_P(x) return LinePGetDatum(x)
  134. #define DatumGetBoxP(X) ((BOX *) DatumGetPointer(X))
  135. #define BoxPGetDatum(X) PointerGetDatum(X)
  136. #define PG_GETARG_BOX_P(n) DatumGetBoxP(PG_GETARG_DATUM(n))
  137. #define PG_RETURN_BOX_P(x) return BoxPGetDatum(x)
  138. #define DatumGetPolygonP(X) ((POLYGON *) PG_DETOAST_DATUM(X))
  139. #define DatumGetPolygonPCopy(X) ((POLYGON *) PG_DETOAST_DATUM_COPY(X))
  140. #define PolygonPGetDatum(X) PointerGetDatum(X)
  141. #define PG_GETARG_POLYGON_P(n) DatumGetPolygonP(PG_GETARG_DATUM(n))
  142. #define PG_GETARG_POLYGON_P_COPY(n) DatumGetPolygonPCopy(PG_GETARG_DATUM(n))
  143. #define PG_RETURN_POLYGON_P(x) return PolygonPGetDatum(x)
  144. #define DatumGetCircleP(X) ((CIRCLE *) DatumGetPointer(X))
  145. #define CirclePGetDatum(X) PointerGetDatum(X)
  146. #define PG_GETARG_CIRCLE_P(n) DatumGetCircleP(PG_GETARG_DATUM(n))
  147. #define PG_RETURN_CIRCLE_P(x) return CirclePGetDatum(x)
  148. /*
  149. * in geo_ops.c
  150. */
  151. extern float8 pg_hypot(float8 x, float8 y);
  152. #endif /* GEO_DECLS_H */
上海开阖软件有限公司 沪ICP备12045867号-1