51 if ( circ_cache->
index )
54 circ_cache->
index = 0;
59 circ_cache->
index = tree;
67 if ( circ_cache->
index )
70 circ_cache->
index = 0;
71 circ_cache->
gcache.argnum = 0;
81 return (GeomCache*)cache;
106 POSTGIS_DEBUGF(3,
"tree1_type=%d", tree1_type);
111 POSTGIS_DEBUG(3,
"tree is a polygon, using tree PiP");
116 POSTGIS_DEBUG(3,
"unable to read gbox from gserialized, calculating from scratch");
128 POSTGIS_DEBUG(3,
"in_point3d is not inside the tree gbox, CircTreePIP returning FALSE");
136 pt2d_inside.
x = in_point->
x;
137 pt2d_inside.
y = in_point->
y;
141 lwpgerror(
"%s: Unable to generate outside point!", __func__);
143 POSTGIS_DEBUGF(3,
"p2d_inside=POINT(%g %g) p2d_outside=POINT(%g %g)", pt2d_inside.
x, pt2d_inside.
y, pt2d_outside.
x, pt2d_outside.
y);
145 POSTGIS_DEBUG(3,
"calling circ_tree_contains_point for PiP test");
151 POSTGIS_DEBUG(3,
"tree1 not polygonal, so CircTreePIP returning FALSE");
180 if ( tree_cache && tree_cache->
gcache.argnum && tree_cache->
index )
192 if ( tree_cache->
gcache.argnum == 1 )
196 geomtype_cached = type1;
199 else if ( tree_cache->
gcache.argnum == 2 )
203 geomtype_cached = type2;
208 lwpgerror(
"geography_distance_cache this cannot happen!");
216 if (
CircTreePIP(circtree_cached, g_cached, &p4d) )
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
static GeomCache * CircTreeAllocator(void)
static CircTreeGeomCache * GetCircTreeGeomCache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2)
int geography_dwithin_cache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double tolerance, int *dwithin)
static GeomCacheMethods CircTreeCacheMethods
static int CircTreeFreer(GeomCache *cache)
int geography_tree_distance(const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double tolerance, double *distance)
static int geography_distance_cache_tolerance(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double tolerance, double *distance)
int geography_distance_cache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double *distance)
static int CircTreePIP(const CIRC_NODE *tree1, const GSERIALIZED *g1, const POINT4D *in_point)
static int CircTreeBuilder(const LWGEOM *lwgeom, GeomCache *cache)
Builder, freeer and public accessor for cached CIRC_NODE trees.
int lwgeom_startpoint(const LWGEOM *lwgeom, POINT4D *pt)
void lwgeom_free(LWGEOM *geom)
int gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside)
Calculate a spherical point that falls outside the geocentric gbox.
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define LW_TRUE
Return types for functions with status returns.
#define FP_TOLERANCE
Floating point comparators.
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesian coordinates on unit sphere.
double circ_tree_distance_tree(const CIRC_NODE *n1, const CIRC_NODE *n2, const SPHEROID *spheroid, double threshold)
int circ_tree_get_point(const CIRC_NODE *node, POINT2D *pt)
Returns a POINT2D that is a vertex of the input shape.
void circ_tree_free(CIRC_NODE *node)
Recurse from top of node tree and free all children.
int circ_tree_contains_point(const CIRC_NODE *node, const POINT2D *pt, const POINT2D *pt_outside, int *on_boundary)
Walk the tree and count intersections between the stab line and the edges.
CIRC_NODE * lwgeom_calculate_circ_tree(const LWGEOM *lwgeom)
int circ_tree_get_point_outside(const CIRC_NODE *node, POINT2D *pt)
Datum distance(PG_FUNCTION_ARGS)
Point in spherical coordinates on the world.
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.