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) 150 #define LW_BOUNDARY 0 151 #define LW_OUTSIDE -1 457 #define LW_ON_INTERRUPT(x) { \ 458 if ( _lwgeom_interrupt_callback ) { \ 459 (*_lwgeom_interrupt_callback)(); \ 461 if ( _lwgeom_interrupt_requested ) { \ 462 _lwgeom_interrupt_requested = 0; \ 463 lwnotice("liblwgeom code interrupted"); \ LWCIRCSTRING * lwcircstring_grid(const LWCIRCSTRING *line, const gridspec *grid)
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.
LWPOINT * lwpoint_force_dims(const LWPOINT *lwpoint, int hasz, int hasm)
int lwcollection_count_vertices(LWCOLLECTION *col)
POINTARRAY * ptarray_remove_repeated_points(const POINTARRAY *in, double tolerance)
LWPOLY * lwpoly_clone_deep(const LWPOLY *lwgeom)
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 lwcircstring_length(const LWCIRCSTRING *circ)
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
int ptarray_npoints_in_rect(const POINTARRAY *pa, const GBOX *gbox)
GBOX * box2d_clone(const GBOX *lwgeom)
POINTARRAY * ptarray_clone(const POINTARRAY *ptarray)
Clone a POINTARRAY object.
int lwline_count_vertices(LWLINE *line)
int lw_arc_calculate_gbox_cartesian_2d(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, GBOX *gbox)
double lw_seg_length(const POINT2D *A1, const POINT2D *A2)
Returns the length of a linear segment.
int gbox_contains_point2d(const GBOX *g, const POINT2D *p)
LWPOLY * lwpoly_simplify(const LWPOLY *ipoly, double dist, int preserve_collapsed)
CG_SEGMENT_INTERSECTION_TYPE
LWLINE * lwline_clone(const LWLINE *lwgeom)
int lwtin_is_closed(const LWTIN *tin)
void ptarray_scale(POINTARRAY *pa, const POINT4D *factor)
Scale a pointarray.
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.
void trim_trailing_zeros(char *num)
int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt)
For POINTARRAYs representing CIRCULARSTRINGS.
void() lwinterrupt_callback()
Install a callback to be called periodically during algorithm execution.
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.
double lwtriangle_perimeter_2d(const LWTRIANGLE *triangle)
double lwcircstring_length_2d(const LWCIRCSTRING *circ)
LWTRIANGLE * lwtriangle_clone(const LWTRIANGLE *lwgeom)
void decode_geohash_bbox(char *geohash, double *lat, double *lon, int precision)
int gbox_centroid(const GBOX *gbox, POINT2D *out)
Computes the average(ish) center of the box and returns success.
double lwline_length_2d(const LWLINE *line)
LWGEOM * lwmpoint_remove_repeated_points(const LWMPOINT *in, double tolerance)
int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
LWLINE * lwline_grid(const LWLINE *line, const gridspec *grid)
LWPOINT * lwpoint_grid(const LWPOINT *point, const gridspec *grid)
int lwcompound_is_closed(const LWCOMPOUND *curve)
LWPOLY * lwcurvepoly_stroke(const LWCURVEPOLY *curvepoly, uint32_t perQuad)
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 lwtriangle_area(const LWTRIANGLE *triangle)
Find the area of the outer ring.
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
double lwtriangle_perimeter(const LWTRIANGLE *triangle)
void lwcircstring_reverse(LWCIRCSTRING *curve)
int lwtriangle_is_empty(const LWTRIANGLE *triangle)
int p2d_same(const POINT2D *p1, const POINT2D *p2)
lwinterrupt_callback * _lwgeom_interrupt_callback
LWGEOM * lwcollection_remove_repeated_points(const LWCOLLECTION *in, double tolerance)
int lwcompound_contains_point(const LWCOMPOUND *comp, const POINT2D *pt)
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)
int lwcollection_is_empty(const LWCOLLECTION *col)
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.
LWPOLY * lwpoly_force_dims(const LWPOLY *lwpoly, int hasz, int hasm)
void ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2)
Swap ordinate values o1 and o2 on a given POINTARRAY.
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 lwpoly_is_closed(const LWPOLY *poly)
double lwcompound_length(const LWCOMPOUND *comp)
int lwcircstring_is_closed(const LWCIRCSTRING *curve)
int ptarray_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
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.
LWCOLLECTION * lwcollection_simplify(const LWCOLLECTION *igeom, double dist, int preserve_collapsed)
int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds)
LWCIRCSTRING * lwcircstring_clone(const LWCIRCSTRING *curve)
GBOX * gbox_clone(const GBOX *gbox)
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
int lwpoly_is_empty(const LWPOLY *poly)
double lwcurvepoly_perimeter_2d(const LWCURVEPOLY *poly)
POINTARRAY * ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm)
void lwpoint_set_ordinate(POINT4D *p, char ordinate, double value)
Given a point, ordinate number and value, set that ordinate on the point.
LWPOLY * lwpoly_grid(const LWPOLY *poly, const gridspec *grid)
enum LWORD_T LWORD
Ordinate names.
int _lwgeom_interrupt_requested
struct gridspec_t gridspec
Snap to grid.
int lwpsurface_is_closed(const LWPSURFACE *psurface)
char * geohash_point(double longitude, double latitude, int precision)
char getMachineEndian(void)
int lwcollection_startpoint(const LWCOLLECTION *col, POINT4D *pt)
LWGEOM * lwgeom_force_dims(const LWGEOM *lwgeom, int hasz, int hasm)
LWCOLLECTION * lwcollection_clone_deep(const LWCOLLECTION *lwgeom)
Deep clone LWCOLLECTION object.
int lwpoly_startpoint(const LWPOLY *lwpoly, POINT4D *pt)
double lwpoly_perimeter_2d(const LWPOLY *poly)
Compute the sum of polygon rings length (forcing 2d computation).
int lwcircstring_is_empty(const LWCIRCSTRING *circ)
double lwpoly_perimeter(const LWPOLY *poly)
Compute the sum of polygon rings length.
LWCOLLECTION * lwcollection_force_dims(const LWCOLLECTION *lwcol, int hasz, int hasm)
int ptarray_startpoint(const POINTARRAY *pa, POINT4D *pt)
int lwline_is_empty(const LWLINE *line)
LWGEOM * lwline_remove_repeated_points(const LWLINE *in, double tolerance)
int lwpoly_contains_point(const LWPOLY *poly, const POINT2D *pt)
LWGEOM * lwpoly_remove_repeated_points(const LWPOLY *in, double tolerance)
POINTARRAY * ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts)
double lwcurvepoly_perimeter(const LWCURVEPOLY *poly)
LWLINE * lwline_force_dims(const LWLINE *lwline, int hasz, int hasm)
int lw_arc_side(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *Q)
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
int ptarray_has_m(const POINTARRAY *pa)
double lwline_length(const LWLINE *line)
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...
POINTARRAY * ptarray_remove_repeated_points_minpoints(const POINTARRAY *in, double tolerance, int minpoints)
int lwline_is_closed(const LWLINE *line)
double gbox_angular_height(const GBOX *gbox)
GBOX utility functions to figure out coverage/location on the globe.
POINTARRAY * ptarray_grid(const POINTARRAY *pa, const gridspec *grid)
int lwpoint_is_empty(const LWPOINT *point)
int p3d_same(const POINT3D *p1, const POINT3D *p2)
LWCOLLECTION * lwcollection_grid(const LWCOLLECTION *coll, const gridspec *grid)
int lw_pt_in_seg(const POINT2D *P, const POINT2D *A1, const POINT2D *A2)
Returns true if P is between A1/A2.
LWCOLLECTION * lwcollection_clone(const LWCOLLECTION *lwgeom)
Clone LWCOLLECTION object.
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...
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
int ptarray_has_z(const POINTARRAY *pa)
LWLINE * lwcompound_stroke(const LWCOMPOUND *icompound, uint32_t perQuad)
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
int lwpoly_count_vertices(LWPOLY *poly)
void closest_point_on_segment(const POINT4D *R, const POINT4D *A, const POINT4D *B, POINT4D *ret)
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
LWPOLY * lwpoly_clone(const LWPOLY *lwgeom)
LWLINE * lwline_clone_deep(const LWLINE *lwgeom)
int ptarrayarc_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
double lwcurvepoly_area(const LWCURVEPOLY *curvepoly)
This should be rewritten to make use of the curve itself.
LWLINE * lwline_simplify(const LWLINE *iline, double dist, int preserve_collapsed)
int p4d_same(const POINT4D *p1, const POINT4D *p2)
This library is the generic geometry handling section of PostGIS.
void ptarray_affine(POINTARRAY *pa, const AFFINE *affine)
Affine transform a pointarray.
void lwcollection_reserve(LWCOLLECTION *col, int ngeoms)
Ensure the collection can hold at least up to ngeoms geometries.
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.
double gbox_angular_width(const GBOX *gbox)
Returns the angular width (longitudinal span) of the box in radians.
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...