29 #ifndef _LIBLWGEOM_INTERNAL_H
30 #define _LIBLWGEOM_INTERNAL_H 1
32 #include "../postgis_config.h"
53 #define FP_TOLERANCE 1e-12
54 #define FP_IS_ZERO(A) (fabs(A) <= FP_TOLERANCE)
55 #define FP_MAX(A, B) (((A) > (B)) ? (A) : (B))
56 #define FP_MIN(A, B) (((A) < (B)) ? (A) : (B))
57 #define FP_ABS(a) ((a) < (0) ? -(a) : (a))
58 #define FP_EQUALS(A, B) (fabs((A)-(B)) <= FP_TOLERANCE)
59 #define FP_NEQUALS(A, B) (fabs((A)-(B)) > FP_TOLERANCE)
60 #define FP_LT(A, B) (((A) + FP_TOLERANCE) < (B))
61 #define FP_LTEQ(A, B) (((A) - FP_TOLERANCE) <= (B))
62 #define FP_GT(A, B) (((A) - FP_TOLERANCE) > (B))
63 #define FP_GTEQ(A, B) (((A) + FP_TOLERANCE) >= (B))
64 #define FP_CONTAINS_TOP(A, X, B) (FP_LT(A, X) && FP_LTEQ(X, B))
65 #define FP_CONTAINS_BOTTOM(A, X, B) (FP_LTEQ(A, X) && FP_LT(X, B))
66 #define FP_CONTAINS_INCL(A, X, B) (FP_LTEQ(A, X) && FP_LTEQ(X, B))
67 #define FP_CONTAINS_EXCL(A, X, B) (FP_LT(A, X) && FP_LT(X, B))
68 #define FP_CONTAINS(A, X, B) FP_CONTAINS_EXCL(A, X, B)
76 #define NO_Z_VALUE NO_VALUE
77 #define NO_M_VALUE NO_VALUE
83 #define WKT_NO_TYPE 0x08
84 #define WKT_NO_PARENS 0x10
85 #define WKT_IS_CHILD 0x20
91 #define WKB_DOUBLE_SIZE 8
92 #define WKB_INT_SIZE 4
93 #define WKB_BYTE_SIZE 1
98 #define WKB_POINT_TYPE 1
99 #define WKB_LINESTRING_TYPE 2
100 #define WKB_POLYGON_TYPE 3
101 #define WKB_MULTIPOINT_TYPE 4
102 #define WKB_MULTILINESTRING_TYPE 5
103 #define WKB_MULTIPOLYGON_TYPE 6
104 #define WKB_GEOMETRYCOLLECTION_TYPE 7
105 #define WKB_CIRCULARSTRING_TYPE 8
106 #define WKB_COMPOUNDCURVE_TYPE 9
107 #define WKB_CURVEPOLYGON_TYPE 10
108 #define WKB_MULTICURVE_TYPE 11
109 #define WKB_MULTISURFACE_TYPE 12
110 #define WKB_CURVE_TYPE 13
111 #define WKB_SURFACE_TYPE 14
112 #define WKB_POLYHEDRALSURFACE_TYPE 15
113 #define WKB_TIN_TYPE 16
114 #define WKB_TRIANGLE_TYPE 17
121 #define SIZE_GET(varsize) (((varsize) >> 2) & 0x3FFFFFFF)
122 #define SIZE_SET(varsize, size) (((varsize) & 0x00000003)|(((size) & 0x3FFFFFFF) << 2 ))
130 #define SIGNUM(n) (((n) > 0) - ((n) < 0))
135 #define EPSILON_SQLMM 1e-8
140 #define OUT_MAX_DOUBLE 1E15
141 #define OUT_SHOW_DIGS_DOUBLE 20
142 #define OUT_MAX_DOUBLE_PRECISION 15
143 #define OUT_MAX_DIGS_DOUBLE (OUT_SHOW_DIGS_DOUBLE + 2)
144 #define OUT_DOUBLE_BUFFER_SIZE \
145 OUT_MAX_DIGS_DOUBLE + OUT_MAX_DOUBLE_PRECISION + 1
151 #define LW_BOUNDARY 0
152 #define LW_OUTSIDE -1
485 int lwprint_double(
double d,
int maxdd,
char* buf,
size_t bufsize);
490 #define LW_ON_INTERRUPT(x) { \
491 if ( _lwgeom_interrupt_callback ) { \
492 (*_lwgeom_interrupt_callback)(); \
494 if ( _lwgeom_interrupt_requested ) { \
495 _lwgeom_interrupt_requested = 0; \
496 lwnotice("liblwgeom code interrupted"); \
void() lwinterrupt_callback()
Install a callback to be called periodically during algorithm execution.
enum LWORD_T LWORD
Ordinate names.
This library is the generic geometry handling section of PostGIS.
int ptarray_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
double lwline_length_2d(const LWLINE *line)
void ptarray_longitude_shift(POINTARRAY *pa)
Longitude shift for a pointarray.
void lwpoint_set_ordinate(POINT4D *p, char ordinate, double value)
Given a point, ordinate number and value, set that ordinate on the point.
LWLINE * lwline_clone_deep(const LWLINE *lwgeom)
int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds)
double lwcircstring_length_2d(const LWCIRCSTRING *circ)
LWPOINT * lwpoint_clone(const LWPOINT *lwgeom)
LWCOLLECTION * lwmpoint_clip_to_ordinate_range(const LWMPOINT *mpoint, char ordinate, double from, double to)
Clip a multi-point based on the from/to range of one of its ordinates.
lwinterrupt_callback * _lwgeom_interrupt_callback
LWGEOM * lwline_remove_repeated_points(const LWLINE *in, double tolerance)
int lwcircstring_is_closed(const LWCIRCSTRING *curve)
void ptarray_reverse_in_place(POINTARRAY *pa)
LWLINE * lwline_clone(const LWLINE *lwgeom)
char lwcollection_same(const LWCOLLECTION *p1, const LWCOLLECTION *p2)
check for same geometry composition
int p4d_same(const POINT4D *p1, const POINT4D *p2)
int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt)
For POINTARRAYs representing CIRCULARSTRINGS.
double lwtriangle_area(const LWTRIANGLE *triangle)
Find the area of the outer ring.
int p3d_same(const POINT3D *p1, const POINT3D *p2)
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.
double lw_arc_length(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns the length of a circular arc segment.
double lwcompound_length_2d(const LWCOMPOUND *comp)
uint32_t lwpoly_count_vertices(LWPOLY *poly)
int lwline_is_empty(const LWLINE *line)
int lwcompound_contains_point(const LWCOMPOUND *comp, const POINT2D *pt)
double ptarray_length(const POINTARRAY *pts)
Find the 3d/2d length of the given POINTARRAY (depending on its dimensionality)
LWCOLLECTION * lwline_clip_to_ordinate_range(const LWLINE *line, char ordinate, double from, double to)
Clip a line based on the from/to range of one of its ordinates.
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
char getMachineEndian(void)
int lwline_is_closed(const LWLINE *line)
char lwtriangle_same(const LWTRIANGLE *p1, const LWTRIANGLE *p2)
int lwpoly_startpoint(const LWPOLY *lwpoly, POINT4D *pt)
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
int lwcollection_startpoint(const LWCOLLECTION *col, POINT4D *pt)
void ptarray_simplify_in_place(POINTARRAY *pa, double epsilon, uint32_t minpts)
int _lwgeom_interrupt_requested
int ptarray_startpoint(const POINTARRAY *pa, POINT4D *pt)
int lwcompound_is_closed(const LWCOMPOUND *curve)
int gbox_contains_point2d(const GBOX *g, const POINT2D *p)
double lwtriangle_perimeter_2d(const LWTRIANGLE *triangle)
int lwpoly_is_clockwise(LWPOLY *poly)
void ptarray_grid_in_place(POINTARRAY *pa, const gridspec *grid)
double gbox_angular_height(const GBOX *gbox)
GBOX utility functions to figure out coverage/location on the globe.
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
CG_SEGMENT_INTERSECTION_TYPE
int lwline_split_by_point_to(const LWLINE *ln, const LWPOINT *pt, LWMLINE *to)
Split a line by a point and push components to the provided multiline.
int lw_segment_intersects(const POINT2D *p1, const POINT2D *p2, const POINT2D *q1, const POINT2D *q2)
returns the kind of CG_SEGMENT_INTERSECTION_TYPE behavior of lineseg 1 (constructed from p1 and p2) a...
int lwtriangle_is_clockwise(LWTRIANGLE *triangle)
char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2)
double gbox_angular_width(const GBOX *gbox)
Returns the angular width (longitudinal span) of the box in radians.
char lwline_same(const LWLINE *p1, const LWLINE *p2)
void ptarray_remove_repeated_points_in_place(POINTARRAY *pa, double tolerance, uint32_t min_points)
double lwtriangle_perimeter(const LWTRIANGLE *triangle)
POINT4D * lwmpoint_extract_points_4d(const LWMPOINT *g, uint32_t *npoints, int *input_empty)
double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result)
Determines the center of the circle defined by the three given points.
int lwpoint_is_empty(const LWPOINT *point)
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
double lwcompound_length(const LWCOMPOUND *comp)
LWCOLLECTION * lwcollection_clone_deep(const LWCOLLECTION *lwgeom)
Deep clone LWCOLLECTION object.
int lw_arc_side(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *Q)
double lw_seg_length(const POINT2D *A1, const POINT2D *A2)
Returns the length of a linear segment.
void lwtriangle_force_clockwise(LWTRIANGLE *triangle)
LWPOINT * lwpoint_force_dims(const LWPOINT *lwpoint, int hasz, int hasm)
void affine_invert(AFFINE *affine)
double ptarray_arc_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY, using circular arc interpolation between each coordinate ...
POINTARRAY * ptarray_remove_repeated_points(const POINTARRAY *in, double tolerance)
LWCOLLECTION * lwpoint_clip_to_ordinate_range(const LWPOINT *mpoint, char ordinate, double from, double to)
Clip a point based on the from/to range of one of its ordinates.
void ptarray_scale(POINTARRAY *pa, const POINT4D *factor)
WARNING, make sure you send in only 16-member double arrays or obviously things will go pear-shaped f...
void ptarray_affine(POINTARRAY *pa, const AFFINE *affine)
Affine transform a pointarray.
int lwpsurface_is_closed(const LWPSURFACE *psurface)
int lwtriangle_is_empty(const LWTRIANGLE *triangle)
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
Return 1 if the point is inside the POINTARRAY, -1 if it is outside, and 0 if it is on the boundary.
LWPOLY * lwpoly_force_dims(const LWPOLY *lwpoly, int hasz, int hasm)
int ptarrayarc_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
double lwcurvepoly_perimeter(const LWCURVEPOLY *poly)
LWCOLLECTION * lwcollection_force_dims(const LWCOLLECTION *lwcol, int hasz, int hasm)
int lw_pt_in_seg(const POINT2D *P, const POINT2D *A1, const POINT2D *A2)
Returns true if P is between A1/A2.
int lwpoly_is_empty(const LWPOLY *poly)
char lwpoly_same(const LWPOLY *p1, const LWPOLY *p2)
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
int ptarray_isccw(const POINTARRAY *pa)
int ptarray_has_z(const POINTARRAY *pa)
double lwline_length(const LWLINE *line)
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
LWLINE * lwcompound_stroke(const LWCOMPOUND *icompound, uint32_t perQuad)
void lwcollection_reserve(LWCOLLECTION *col, uint32_t ngeoms)
Ensure the collection can hold at least up to ngeoms geometries.
void lwpoly_force_clockwise(LWPOLY *poly)
void ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2)
Swap ordinate values o1 and o2 on a given POINTARRAY.
int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
LWPOLY * lwcurvepoly_stroke(const LWCURVEPOLY *curvepoly, uint32_t perQuad)
double lwpoly_perimeter_2d(const LWPOLY *poly)
Compute the sum of polygon rings length (forcing 2d computation).
int lwprint_double(double d, int maxdd, char *buf, size_t bufsize)
int ptarray_npoints_in_rect(const POINTARRAY *pa, const GBOX *gbox)
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
int lwtin_is_closed(const LWTIN *tin)
int gbox_centroid(const GBOX *gbox, POINT2D *out)
Computes the average(ish) center of the box and returns success.
int lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt)
void closest_point_on_segment(const POINT4D *R, const POINT4D *A, const POINT4D *B, POINT4D *ret)
GBOX * gbox_clone(const GBOX *gbox)
char lwcircstring_same(const LWCIRCSTRING *p1, const LWCIRCSTRING *p2)
LWPOLY * lwpoly_clone_deep(const LWPOLY *lwgeom)
double lwcircstring_length(const LWCIRCSTRING *circ)
uint32_t lwcollection_count_vertices(LWCOLLECTION *col)
int point_interpolate(const POINT4D *p1, const POINT4D *p2, POINT4D *p, int hasz, int hasm, char ordinate, double interpolation_value)
Given two points, a dimensionality, an ordinate, and an interpolation value generate a new point that...
int lw_arc_is_pt(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns true if arc A is actually a point (all vertices are the same) .
double lwcurvepoly_area(const LWCURVEPOLY *curvepoly)
This should be rewritten to make use of the curve itself.
LWCOLLECTION * lwcollection_clone(const LWCOLLECTION *lwgeom)
Clone LWCOLLECTION object.
void decode_geohash_bbox(char *geohash, double *lat, double *lon, int precision)
int lwpoly_is_closed(const LWPOLY *poly)
LWLINE * lwline_force_dims(const LWLINE *lwline, int hasz, int hasm)
struct gridspec_t gridspec
Snap to grid.
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
LWGEOM * lwgeom_force_dims(const LWGEOM *lwgeom, int hasz, int hasm)
LWPOLY * lwpoly_clone(const LWPOLY *lwgeom)
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
void ptarray_copy_point(POINTARRAY *pa, uint32_t from, uint32_t to)
POINTARRAY * ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm)
int lw_pt_in_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns true if P is on the same side of the plane partition defined by A1/A3 as A2 is.
int ptarray_has_m(const POINTARRAY *pa)
int lwcircstring_is_empty(const LWCIRCSTRING *circ)
int lwcollection_is_empty(const LWCOLLECTION *col)
uint32_t lwline_count_vertices(LWLINE *line)
double lwcurvepoly_perimeter_2d(const LWCURVEPOLY *poly)
double lwpoly_perimeter(const LWPOLY *poly)
Compute the sum of polygon rings length.
int lw_arc_calculate_gbox_cartesian_2d(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, GBOX *gbox)
LWTRIANGLE * lwtriangle_clone(const LWTRIANGLE *lwgeom)
char lwpoint_same(const LWPOINT *p1, const LWPOINT *p2)
LWCIRCSTRING * lwcircstring_clone(const LWCIRCSTRING *curve)
void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid)
LWCOLLECTION * lwmline_clip_to_ordinate_range(const LWMLINE *mline, char ordinate, double from, double to)
Clip a multi-line based on the from/to range of one of its ordinates.
char * geohash_point(double longitude, double latitude, int precision)
int point4d_transform(POINT4D *pt, projPJ srcpj, projPJ dstpj)
int p2d_same(const POINT2D *p1, const POINT2D *p2)