Commit 01e4a171 authored by Paul Ramsey's avatar Paul Ramsey

astyle --style=ansi --indent=tab=8


git-svn-id: http://svn.osgeo.org/postgis/trunk@3284 b70326c6-7e19-0410-871a-916f4a2858ee
parent ac378e71
......@@ -8,7 +8,7 @@
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU General Public Licence. See the COPYING file.
*
*
**********************************************************************/
#include "lwgeom_geos_prepared.h"
......@@ -35,7 +35,7 @@
** objects used in computations.
**
** PreparedCacheContextMethods, a set of callback functions that
** get hooked into a MemoryContext that is in turn used as a
** get hooked into a MemoryContext that is in turn used as a
** key in the PrepGeomHash.
**
** All this is to allow us to clean up external malloc'ed objects
......@@ -56,21 +56,22 @@
** Backend prepared hash table
**
** The memory context call-backs use a MemoryContext as the parameter
** so we need to map that over to actual references to GEOS objects to
** so we need to map that over to actual references to GEOS objects to
** delete.
**
** This hash table stores a key/value pair of MemoryContext/Geom* objects.
*/
static HTAB* PrepGeomHash = NULL;
#define PREPARED_BACKEND_HASH_SIZE 32
#define PREPARED_BACKEND_HASH_SIZE 32
typedef struct
typedef struct
{
MemoryContext context;
const GEOSPreparedGeometry* prepared_geom;
GEOSGeometry* geom;
} PrepGeomHashEntry;
}
PrepGeomHashEntry;
/* Memory context hash table function prototypes */
uint32 mcxt_ptr_hasha(const void *key, Size keysize);
......@@ -90,20 +91,21 @@ static void PreparedCacheCheck(MemoryContext context);
#endif
/* Memory context definition must match the current version of PostgreSQL */
static MemoryContextMethods PreparedCacheContextMethods = {
NULL,
NULL,
NULL,
PreparedCacheInit,
PreparedCacheReset,
PreparedCacheDelete,
NULL,
PreparedCacheIsEmpty,
PreparedCacheStats
static MemoryContextMethods PreparedCacheContextMethods =
{
NULL,
NULL,
NULL,
PreparedCacheInit,
PreparedCacheReset,
PreparedCacheDelete,
NULL,
PreparedCacheIsEmpty,
PreparedCacheStats
#ifdef MEMORY_CONTEXT_CHECKING
, PreparedCacheCheck
, PreparedCacheCheck
#endif
};
};
static void
PreparedCacheInit(MemoryContext context)
......@@ -128,9 +130,9 @@ PreparedCacheDelete(MemoryContext context)
POSTGIS_DEBUGF(3, "deleting geom object (%p) and prepared geom object (%p) with MemoryContext key (%p)", pghe->geom, pghe->prepared_geom, context);
/* Free them */
if( pghe->prepared_geom )
if ( pghe->prepared_geom )
GEOSPreparedGeom_destroy( pghe->prepared_geom );
if( pghe->geom )
if ( pghe->geom )
GEOSGeom_destroy( pghe->geom );
/* Remove the hash entry as it is no longer needed */
......@@ -182,7 +184,7 @@ PreparedCacheCheck(MemoryContext context)
** mcxt_ptr_hash
** Build a key from a pointer and a size value.
*/
uint32
uint32
mcxt_ptr_hasha(const void *key, Size keysize)
{
uint32 hashval;
......@@ -204,7 +206,7 @@ CreatePrepGeomHash(void)
PrepGeomHash = hash_create("PostGIS Prepared Geometry Backend MemoryContext Hash", PREPARED_BACKEND_HASH_SIZE, &ctl, (HASH_ELEM | HASH_FUNCTION));
}
static void
static void
AddPrepGeomHashEntry(PrepGeomHashEntry pghe)
{
bool found;
......@@ -213,7 +215,7 @@ AddPrepGeomHashEntry(PrepGeomHashEntry pghe)
/* The hash key is the MemoryContext pointer */
key = (void *)&(pghe.context);
he = (PrepGeomHashEntry *) hash_search(PrepGeomHash, key, HASH_ENTER, &found);
if (!found)
{
......@@ -244,11 +246,11 @@ GetPrepGeomHashEntry(MemoryContext mcxt)
}
static void
static void
DeletePrepGeomHashEntry(MemoryContext mcxt)
{
void **key;
PrepGeomHashEntry *he;
PrepGeomHashEntry *he;
/* The hash key is the MemoryContext pointer */
key = (void *)&mcxt;
......@@ -268,10 +270,10 @@ DeletePrepGeomHashEntry(MemoryContext mcxt)
**
** Pull the current prepared geometry from the cache or make
** one if there is not one available. Only prepare geometry
** if we are seeing a key for the second time. That way rapidly
** if we are seeing a key for the second time. That way rapidly
** cycling keys don't cause too much preparing.
*/
PrepGeomCache*
PrepGeomCache*
GetPrepGeomCache(FunctionCallInfoData *fcinfo, PG_LWGEOM *pg_geom1, PG_LWGEOM *pg_geom2)
{
MemoryContext old_context;
......@@ -280,16 +282,16 @@ GetPrepGeomCache(FunctionCallInfoData *fcinfo, PG_LWGEOM *pg_geom1, PG_LWGEOM *p
size_t pg_geom1_size = 0;
size_t pg_geom2_size = 0;
/* Make sure this isn't someone else's cache object. */
if( cache && cache->type != 2 ) cache = NULL;
/* Make sure this isn't someone else's cache object. */
if ( cache && cache->type != 2 ) cache = NULL;
if (!PrepGeomHash)
CreatePrepGeomHash();
if( pg_geom1 )
if ( pg_geom1 )
pg_geom1_size = VARSIZE(pg_geom1) + VARHDRSZ;
if( pg_geom2 )
if ( pg_geom2 )
pg_geom2_size = VARSIZE(pg_geom2) + VARHDRSZ;
if ( cache == NULL)
......@@ -301,12 +303,12 @@ GetPrepGeomCache(FunctionCallInfoData *fcinfo, PG_LWGEOM *pg_geom1, PG_LWGEOM *p
** wasted time preparing a geometry we don't need.
*/
PrepGeomHashEntry pghe;
old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
cache = palloc(sizeof(PrepGeomCache));
cache = palloc(sizeof(PrepGeomCache));
MemoryContextSwitchTo(old_context);
cache->type = 2;
cache->type = 2;
cache->prepared_geom = 0;
cache->geom = 0;
cache->argnum = 0;
......@@ -315,9 +317,9 @@ GetPrepGeomCache(FunctionCallInfoData *fcinfo, PG_LWGEOM *pg_geom1, PG_LWGEOM *p
cache->pg_geom1_size = 0;
cache->pg_geom2_size = 0;
cache->context = MemoryContextCreate(T_AllocSetContext, 8192,
&PreparedCacheContextMethods,
fcinfo->flinfo->fn_mcxt,
"PostGIS Prepared Geometry Context");
&PreparedCacheContextMethods,
fcinfo->flinfo->fn_mcxt,
"PostGIS Prepared Geometry Context");
POSTGIS_DEBUGF(1, "GetPrepGeomCache: creating cache: %p", cache);
......@@ -331,9 +333,9 @@ GetPrepGeomCache(FunctionCallInfoData *fcinfo, PG_LWGEOM *pg_geom1, PG_LWGEOM *p
POSTGIS_DEBUGF(3, "GetPrepGeomCache: adding context to hash: %p", cache);
}
else if ( pg_geom1 &&
cache->argnum != 2 &&
cache->pg_geom1_size == pg_geom1_size &&
memcmp(cache->pg_geom1, pg_geom1, pg_geom1_size) == 0)
cache->argnum != 2 &&
cache->pg_geom1_size == pg_geom1_size &&
memcmp(cache->pg_geom1, pg_geom1, pg_geom1_size) == 0)
{
if ( !cache->prepared_geom )
{
......@@ -342,7 +344,7 @@ GetPrepGeomCache(FunctionCallInfoData *fcinfo, PG_LWGEOM *pg_geom1, PG_LWGEOM *p
** Prepare it.
*/
PrepGeomHashEntry* pghe;
cache->geom = POSTGIS2GEOS( pg_geom1 );
cache->prepared_geom = GEOSPrepare( cache->geom );
cache->argnum = 1;
......@@ -354,7 +356,7 @@ GetPrepGeomCache(FunctionCallInfoData *fcinfo, PG_LWGEOM *pg_geom1, PG_LWGEOM *p
POSTGIS_DEBUG(3, "GetPrepGeomCache: storing references to prepared obj in argument 1");
}
else
{
{
/*
** Cache hit, and we're good to go. Do nothing.
*/
......@@ -363,38 +365,38 @@ GetPrepGeomCache(FunctionCallInfoData *fcinfo, PG_LWGEOM *pg_geom1, PG_LWGEOM *p
/* We don't need new keys until we have a cache miss */
copy_keys = 0;
}
else if ( pg_geom2 &&
cache->argnum != 1 &&
cache->pg_geom2_size == pg_geom2_size &&
memcmp(cache->pg_geom2, pg_geom2, pg_geom2_size) == 0)
else if ( pg_geom2 &&
cache->argnum != 1 &&
cache->pg_geom2_size == pg_geom2_size &&
memcmp(cache->pg_geom2, pg_geom2, pg_geom2_size) == 0)
{
if ( !cache->prepared_geom )
{
/*
** Cache hit on arg2, but we haven't prepared our geometry yet.
** Prepare it.
*/
PrepGeomHashEntry* pghe;
cache->geom = POSTGIS2GEOS( pg_geom2 );
cache->prepared_geom = GEOSPrepare( cache->geom );
cache->argnum = 2;
POSTGIS_DEBUG(1, "GetPrepGeomCache: preparing obj in argument 2");
pghe = GetPrepGeomHashEntry(cache->context);
pghe->geom = cache->geom;
pghe->prepared_geom = cache->prepared_geom;
POSTGIS_DEBUG(3, "GetPrepGeomCache: storing references to prepared obj in argument 2");
}
else
{
/*
** Cache hit, and we're good to go. Do nothing.
*/
POSTGIS_DEBUG(1, "GetPrepGeomCache: cache hit, argument 2");
}
/* We don't need new keys until we have a cache miss */
copy_keys = 0;
if ( !cache->prepared_geom )
{
/*
** Cache hit on arg2, but we haven't prepared our geometry yet.
** Prepare it.
*/
PrepGeomHashEntry* pghe;
cache->geom = POSTGIS2GEOS( pg_geom2 );
cache->prepared_geom = GEOSPrepare( cache->geom );
cache->argnum = 2;
POSTGIS_DEBUG(1, "GetPrepGeomCache: preparing obj in argument 2");
pghe = GetPrepGeomHashEntry(cache->context);
pghe->geom = cache->geom;
pghe->prepared_geom = cache->prepared_geom;
POSTGIS_DEBUG(3, "GetPrepGeomCache: storing references to prepared obj in argument 2");
}
else
{
/*
** Cache hit, and we're good to go. Do nothing.
*/
POSTGIS_DEBUG(1, "GetPrepGeomCache: cache hit, argument 2");
}
/* We don't need new keys until we have a cache miss */
copy_keys = 0;
}
else if ( cache->prepared_geom )
{
......@@ -411,14 +413,14 @@ GetPrepGeomCache(FunctionCallInfoData *fcinfo, PG_LWGEOM *pg_geom1, PG_LWGEOM *p
POSTGIS_DEBUGF(1, "GetPrepGeomCache: cache miss, argument %d", cache->argnum);
GEOSPreparedGeom_destroy( cache->prepared_geom );
GEOSGeom_destroy( cache->geom );
cache->prepared_geom = 0;
cache->geom = 0;
cache->argnum = 0;
}
if( copy_keys && pg_geom1 )
if ( copy_keys && pg_geom1 )
{
/*
** If this is a new key (cache miss) we flip into the function
......@@ -428,18 +430,18 @@ GetPrepGeomCache(FunctionCallInfoData *fcinfo, PG_LWGEOM *pg_geom1, PG_LWGEOM *p
*/
POSTGIS_DEBUG(1, "GetPrepGeomCache: copying pg_geom1 into cache");
old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
if( cache->pg_geom1 )
if ( cache->pg_geom1 )
pfree(cache->pg_geom1);
cache->pg_geom1 = palloc(pg_geom1_size);
MemoryContextSwitchTo(old_context);
memcpy(cache->pg_geom1, pg_geom1, pg_geom1_size);
cache->pg_geom1_size = pg_geom1_size;
}
if( copy_keys && pg_geom2 )
{
if ( copy_keys && pg_geom2 )
{
POSTGIS_DEBUG(1, "GetPrepGeomCache: copying pg_geom2 into cache");
old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
if( cache->pg_geom2 )
if ( cache->pg_geom2 )
pfree(cache->pg_geom2);
cache->pg_geom2 = palloc(pg_geom2_size);
MemoryContextSwitchTo(old_context);
......@@ -448,7 +450,7 @@ GetPrepGeomCache(FunctionCallInfoData *fcinfo, PG_LWGEOM *pg_geom1, PG_LWGEOM *p
}
return cache;
}
#endif /* PREPARED_GEOM */
......@@ -464,7 +466,7 @@ Datum containsPrepared(PG_FUNCTION_ARGS)
{
#ifndef PREPARED_GEOM
elog(ERROR,"Not implemented in this version!");
PG_RETURN_NULL();
PG_RETURN_NULL();
#else
PG_LWGEOM * geom1;
PG_LWGEOM * geom2;
......@@ -488,10 +490,10 @@ Datum containsPrepared(PG_FUNCTION_ARGS)
* Do the test IFF BOUNDING BOX AVAILABLE.
*/
if ( getbox2d_p(SERIALIZED_FORM(geom1), &box1) &&
getbox2d_p(SERIALIZED_FORM(geom2), &box2) )
getbox2d_p(SERIALIZED_FORM(geom2), &box2) )
{
if (( box2.xmin < box1.xmin ) || ( box2.xmax > box1.xmax ) ||
( box2.ymin < box1.ymin ) || ( box2.ymax > box1.ymax ))
( box2.ymin < box1.ymin ) || ( box2.ymax > box1.ymax ))
PG_RETURN_BOOL(FALSE);
}
......@@ -564,7 +566,7 @@ Datum coversPrepared(PG_FUNCTION_ARGS)
getbox2d_p(SERIALIZED_FORM(geom2), &box2) )
{
if (( box2.xmin < box1.xmin ) || ( box2.xmax > box1.xmax ) ||
( box2.ymin < box1.ymin ) || ( box2.ymax > box1.ymax ))
( box2.ymin < box1.ymin ) || ( box2.ymax > box1.ymax ))
PG_RETURN_BOOL(FALSE);
}
......@@ -636,7 +638,7 @@ Datum intersectsPrepared(PG_FUNCTION_ARGS)
getbox2d_p(SERIALIZED_FORM(geom2), &box2) )
{
if (( box2.xmax < box1.xmin ) || ( box2.xmin > box1.xmax ) ||
( box2.ymax < box1.ymin ) || ( box2.ymin > box1.ymax ))
( box2.ymax < box1.ymin ) || ( box2.ymin > box1.ymax ))
PG_RETURN_BOOL(FALSE);
}
......
......@@ -7,7 +7,7 @@
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU General Public Licence. See the COPYING file.
*
*
**********************************************************************/
#include "../postgis_config.h"
......@@ -34,34 +34,35 @@
** GEOS prepared geometry is only available from GEOS 3.1 onwards
*/
#if POSTGIS_GEOS_VERSION >= 31
#define PREPARED_GEOM
#define PREPARED_GEOM
#endif
/*
/*
** Cache structure. We use PG_LWGEOM as keys so no transformations
** are needed before we memcmp them with other keys. We store the
** are needed before we memcmp them with other keys. We store the
** size to avoid having to calculate the size every time.
** The argnum gives the number of function arguments we are caching.
** Intersects requires that both arguments be checked for cacheability,
** while Contains only requires that the containing argument be checked.
** Both the Geometry and the PreparedGeometry have to be cached,
** The argnum gives the number of function arguments we are caching.
** Intersects requires that both arguments be checked for cacheability,
** while Contains only requires that the containing argument be checked.
** Both the Geometry and the PreparedGeometry have to be cached,
** because the PreparedGeometry contains a reference to the geometry.
*/
#ifdef PREPARED_GEOM
typedef struct
{
char type;
PG_LWGEOM* pg_geom1;
PG_LWGEOM* pg_geom2;
PG_LWGEOM *pg_geom1;
PG_LWGEOM *pg_geom2;
size_t pg_geom1_size;
size_t pg_geom2_size;
int32 argnum;
const GEOSPreparedGeometry* prepared_geom;
GEOSGeometry* geom;
const GEOSPreparedGeometry *prepared_geom;
GEOSGeometry *geom;
MemoryContext context;
} PrepGeomCache;
}
PrepGeomCache;
/*
/*
** Get the current cache, given the input geometries.
** Function will create cache if none exists, and prepare geometries in
** cache if necessary, or pull an existing cache if possible.
......
......@@ -7,7 +7,7 @@
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU General Public Licence. See the COPYING file.
*
*
**********************************************************************/
#include "lwgeom_pg.h"
......@@ -24,80 +24,81 @@ Datum LWGEOM_polygon_index(PG_FUNCTION_ARGS);
*/
RTREE_NODE *createTree(POINTARRAY *pointArray)
{
RTREE_NODE *root;
RTREE_NODE *root;
RTREE_NODE** nodes = lwalloc(sizeof(RTREE_NODE*) * pointArray->npoints);
int i, nodeCount;
int childNodes, parentNodes;
int childNodes, parentNodes;
LWDEBUGF(2, "createTree called with pointarray %p", pointArray);
LWDEBUGF(2, "createTree called with pointarray %p", pointArray);
nodeCount = pointArray->npoints - 1;
nodeCount = pointArray->npoints - 1;
LWDEBUGF(3, "Total leaf nodes: %d", nodeCount);
LWDEBUGF(3, "Total leaf nodes: %d", nodeCount);
/*
* Create a leaf node for every line segment.
*/
for(i = 0; i < nodeCount; i++)
/*
* Create a leaf node for every line segment.
*/
for (i = 0; i < nodeCount; i++)
{
nodes[i] = createLeafNode(pointArray, i);
}
/*
* Next we group nodes by pairs. If there's an odd number of nodes,
* we bring the last node up a level as is. Continue until we have
* a single top node.
*/
childNodes = nodeCount;
parentNodes = nodeCount / 2;
while (parentNodes > 0)
{
LWDEBUGF(3, "Merging %d children into %d parents.", childNodes, parentNodes);
i = 0;
while (i < parentNodes)
{
nodes[i] = createLeafNode(pointArray, i);
nodes[i] = createInteriorNode(nodes[i*2], nodes[i*2+1]);
i++;
}
/*
* Next we group nodes by pairs. If there's an odd number of nodes,
* we bring the last node up a level as is. Continue until we have
* a single top node.
* Check for an odd numbered final node.
*/
childNodes = nodeCount;
parentNodes = nodeCount / 2;
while(parentNodes > 0)
if (parentNodes * 2 < childNodes)
{
LWDEBUGF(3, "Merging %d children into %d parents.", childNodes, parentNodes);
i = 0;
while(i < parentNodes)
{
nodes[i] = createInteriorNode(nodes[i*2], nodes[i*2+1]);
i++;
}
/*
* Check for an odd numbered final node.
*/
if(parentNodes * 2 < childNodes)
{
LWDEBUGF(3, "Shuffling child %d to parent %d", childNodes - 1, i);
nodes[i] = nodes[childNodes - 1];
parentNodes++;
}
childNodes = parentNodes;
parentNodes = parentNodes / 2;
LWDEBUGF(3, "Shuffling child %d to parent %d", childNodes - 1, i);
nodes[i] = nodes[childNodes - 1];
parentNodes++;
}
childNodes = parentNodes;
parentNodes = parentNodes / 2;
}
root = nodes[0];
lwfree(nodes);
LWDEBUGF(3, "createTree returning %p", root);
root = nodes[0];
lwfree(nodes);
LWDEBUGF(3, "createTree returning %p", root);
return root;
return root;
}
/*
* Creates an interior node given the children.
/*
* Creates an interior node given the children.
*/
RTREE_NODE *createInteriorNode(RTREE_NODE *left, RTREE_NODE *right){
RTREE_NODE *parent;
RTREE_NODE *createInteriorNode(RTREE_NODE *left, RTREE_NODE *right)
{
RTREE_NODE *parent;
LWDEBUGF(2, "createInteriorNode called for children %p, %p", left, right);
LWDEBUGF(2, "createInteriorNode called for children %p, %p", left, right);
parent = lwalloc(sizeof(RTREE_NODE));
parent->leftNode = left;
parent->rightNode = right;
parent->interval = mergeIntervals(left->interval, right->interval);
parent->segment = NULL;
parent = lwalloc(sizeof(RTREE_NODE));
parent->leftNode = left;
parent->rightNode = right;
parent->interval = mergeIntervals(left->interval, right->interval);
parent->segment = NULL;
LWDEBUGF(3, "createInteriorNode returning %p", parent);
LWDEBUGF(3, "createInteriorNode returning %p", parent);
return parent;
return parent;
}
/*
......@@ -105,52 +106,52 @@ RTREE_NODE *createInteriorNode(RTREE_NODE *left, RTREE_NODE *right){
*/
RTREE_NODE *createLeafNode(POINTARRAY *pa, int startPoint)
{
RTREE_NODE *parent;
LWLINE *line;
double value1;
double value2;
POINT4D tmp;
POINTARRAY *npa;
RTREE_NODE *parent;
LWLINE *line;
double value1;
double value2;
POINT4D tmp;
POINTARRAY *npa;
LWDEBUGF(2, "createLeafNode called for point %d of %p", startPoint, pa);
LWDEBUGF(2, "createLeafNode called for point %d of %p", startPoint, pa);
if(pa->npoints < startPoint + 2)
{
lwerror("createLeafNode: npoints = %d, startPoint = %d", pa->npoints, startPoint);
}
if (pa->npoints < startPoint + 2)
{
lwerror("createLeafNode: npoints = %d, startPoint = %d", pa->npoints, startPoint);
}
/*
* The given point array will be part of a geometry that will be freed
* independently of the index. Since we may want to cache the index,
* we must create independent arrays.
*/
npa = lwalloc(sizeof(POINTARRAY));
npa->dims = 0;
npa->npoints = 2;
TYPE_SETZM(npa->dims, 0, 0);
npa->serialized_pointlist = lwalloc(pointArray_ptsize(pa) * 2);
getPoint4d_p(pa, startPoint, &tmp);
setPoint4d(npa, 0, &tmp);
value1 = tmp.y;
getPoint4d_p(pa, startPoint + 1, &tmp);
setPoint4d(npa, 1, &tmp);
value2 = tmp.y;
line = lwline_construct(-1, NULL, npa);
parent = lwalloc(sizeof(RTREE_NODE));
parent->interval = createInterval(value1, value2);
parent->segment = line;
parent->leftNode = NULL;
parent->rightNode = NULL;
LWDEBUGF(3, "createLeafNode returning %p", parent);
return parent;
/*
* The given point array will be part of a geometry that will be freed
* independently of the index. Since we may want to cache the index,
* we must create independent arrays.
*/
npa = lwalloc(sizeof(POINTARRAY));
npa->dims = 0;
npa->npoints = 2;
TYPE_SETZM(npa->dims, 0, 0);
npa->serialized_pointlist = lwalloc(pointArray_ptsize(pa) * 2);
getPoint4d_p(pa, startPoint, &tmp);
setPoint4d(npa, 0, &tmp);
value1 = tmp.y;
getPoint4d_p(pa, startPoint + 1, &tmp);
setPoint4d(npa, 1, &tmp);
value2 = tmp.y;
line = lwline_construct(-1, NULL, npa);
parent = lwalloc(sizeof(RTREE_NODE));
parent->interval = createInterval(value1, value2);
parent->segment = line;
parent->leftNode = NULL;
parent->rightNode = NULL;
LWDEBUGF(3, "createLeafNode returning %p", parent);
return parent;
}
/*
......@@ -158,17 +159,17 @@ RTREE_NODE *createLeafNode(POINTARRAY *pa, int startPoint)
*/
INTERVAL *mergeIntervals(INTERVAL *inter1, INTERVAL *inter2)
{
INTERVAL *interval;
INTERVAL *interval;
LWDEBUGF(2, "mergeIntervals called with %p, %p", inter1, inter2);
LWDEBUGF(2, "mergeIntervals called with %p, %p", inter1, inter2);
interval = lwalloc(sizeof(INTERVAL));
interval->max = FP_MAX(inter1->max, inter2->max);
interval->min = FP_MIN(inter1->min, inter2->min);
interval = lwalloc(sizeof(INTERVAL));
interval->max = FP_MAX(inter1->max, inter2->max);
interval->min = FP_MIN(inter1->min, inter2->min);
LWDEBUGF(3, "interval min = %8.3f, max = %8.3f", interval->min, interval->max);
LWDEBUGF(3, "interval min = %8.3f, max = %8.3f", interval->min, interval->max);
return interval;
return interval;
}
/*
......@@ -176,38 +177,39 @@ INTERVAL *mergeIntervals(INTERVAL *inter1, INTERVAL *inter2)
*/
INTERVAL *createInterval(double value1, double value2)
{
INTERVAL *interval;
INTERVAL *interval;
LWDEBUGF(2, "createInterval called with %8.3f, %8.3f", value1, value2);
LWDEBUGF(2, "createInterval called with %8.3f, %8.3f", value1, value2);
interval = lwalloc(sizeof(INTERVAL));
interval->max = FP_MAX(value1, value2);
interval->min = FP_MIN(value1, value2);
interval = lwalloc(sizeof(INTERVAL));
interval->max = FP_MAX(value1, value2);
interval->min = FP_MIN(value1, value2);
LWDEBUGF(3, "interval min = %8.3f, max = %8.3f", interval->min, interval->max);
LWDEBUGF(3, "interval min = %8.3f, max = %8.3f", interval->min, interval->max);
return interval;
return interval;
}
/*
* Recursively frees the child nodes, the interval and the line before
* Recursively frees the child nodes, the interval and the line before
* freeing the root node.
*/
void freeTree(RTREE_NODE *root)
{
LWDEBUGF(2, "freeTree called for %p", root);
if(root->leftNode)
freeTree(root->leftNode);
if(root->rightNode)
freeTree(root->rightNode);
lwfree(root->interval);
if(root->segment) {
lwfree(root->segment->points->serialized_pointlist);
lwfree(root->segment->points);
lwgeom_release((LWGEOM *)root->segment);
}
lwfree(root);
LWDEBUGF(2, "freeTree called for %p", root);