Add gbox string constructor for testing purposes

git-svn-id: http://svn.osgeo.org/postgis/trunk@4504 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
Paul Ramsey 2009-09-16 21:09:24 +00:00
parent 154a0f5bcb
commit 2f24c23327
3 changed files with 55 additions and 18 deletions

View file

@ -67,6 +67,7 @@ void test_gbox_from_spherical_coordinates(void)
{
double ll[64];
GBOX *box = gbox_new(gflags(0, 0, 1));
GBOX *good;
int rv;
POINTARRAY *pa;
ll[0] = -3.083333333333333333333333333333333;
@ -76,10 +77,17 @@ void test_gbox_from_spherical_coordinates(void)
pa = pointArray_construct((uchar*)ll, 0, 0, 2);
rv = ptarray_calculate_gbox_geodetic(pa, box);
good = gbox_from_string("GBOX((0.95958795,-0.05299812,-0.09150161),(0.99495869,0.26611729,0.17078275))");
// printf("\n%s\n", gbox_to_string(box));
// printf("%s\n", "(0.95958795, -0.05299812, -0.09150161) (0.99495869, 0.26611729, 0.17078275)");
CU_ASSERT_DOUBLE_EQUAL(box->xmin, 0.95958795, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->xmin, good->xmin, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->xmax, good->xmax, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->ymin, good->ymin, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->ymax, good->ymax, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->zmin, good->zmin, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->zmax, good->zmax, 0.0001);
lwfree(pa);
lwfree(good);
ll[0] = -35.0;
@ -89,10 +97,17 @@ void test_gbox_from_spherical_coordinates(void)
pa = pointArray_construct((uchar*)ll, 0, 0, 2);
rv = ptarray_calculate_gbox_geodetic(pa, box);
good = gbox_from_string("GBOX((0.32139380,-0.34917121,0.79335334),(0.49866816,0.38302222,0.90147645))");
// printf("\n%s\n", gbox_to_string(box));
// printf("%s\n", "(0.32139380, -0.34917121, 0.79335334) (0.49866816, 0.38302222, 0.90147645)");
CU_ASSERT_DOUBLE_EQUAL(box->xmin, 0.32139380, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->xmin, good->xmin, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->xmax, good->xmax, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->ymin, good->ymin, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->ymax, good->ymax, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->zmin, good->zmin, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->zmax, good->zmax, 0.0001);
lwfree(pa);
lwfree(good);
ll[0] = -122.5;
@ -102,10 +117,17 @@ void test_gbox_from_spherical_coordinates(void)
pa = pointArray_construct((uchar*)ll, 0, 0, 2);
rv = ptarray_calculate_gbox_geodetic(pa, box);
good = gbox_from_string("GBOX((-0.29850766,-0.46856318,0.83146961),(-0.19629681,-0.29657213,0.93461892))");
// printf("\n%s\n", gbox_to_string(box));
// printf("%s\n", "(-0.29850766, -0.46856318, 0.83146961) (-0.19629681, -0.29657213, 0.93461892)");
CU_ASSERT_DOUBLE_EQUAL(box->zmin, 0.83146961, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->xmin, good->xmin, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->xmax, good->xmax, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->ymin, good->ymin, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->ymax, good->ymax, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->zmin, good->zmin, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(box->zmax, good->zmax, 0.0001);
lwfree(pa);
lwfree(good);
lwfree(box);

View file

@ -11,6 +11,7 @@
#include "libgeom.h"
#include <math.h>
#include <stdlib.h>
GBOX* gbox_new(uchar flags)
{
@ -78,28 +79,37 @@ int gbox_overlaps(GBOX *g1, GBOX *g2)
return LW_TRUE;
}
#if 0
/**
* Warning, this function is only good for x/y/z boxes, used
* in unit testing of geodetic box generation.
*/
GBOX* gbox_from_string(char *str)
{
int ndims = 0;
char *ptr = str;
char *nextptr;
double d;
char *gbox_start = strstr(str, "GBOX((");
GBOX *gbox = gbox_new(0);
GBOX *gbox = gbox_new(gflags(0,0,1));
if( ! gbox_start ) return NULL; /* No header found */
ptr += 5;
do {
ptr++;
d = strtod(ptr, &nextptr);
if( ptr == nextptr ) return NULL; /* No double found */
gbox->xmin = d;
ndims++;
ptr = nextptr;
ptr += 6;
gbox->xmin = strtod(ptr, &nextptr);
if( ptr == nextptr ) return NULL; /* No double found */
ptr = nextptr + 1;
gbox->ymin = strtod(ptr, &nextptr);
if( ptr == nextptr ) return NULL; /* No double found */
ptr = nextptr + 1;
gbox->zmin = strtod(ptr, &nextptr);
if( ptr == nextptr ) return NULL; /* No double found */
ptr = nextptr + 3;
gbox->xmax = strtod(ptr, &nextptr);
if( ptr == nextptr ) return NULL; /* No double found */
ptr = nextptr + 1;
gbox->ymax = strtod(ptr, &nextptr);
if( ptr == nextptr ) return NULL; /* No double found */
ptr = nextptr + 1;
gbox->zmax = strtod(ptr, &nextptr);
if( ptr == nextptr ) return NULL; /* No double found */
return gbox;
}
#endif
char* gbox_to_string(GBOX *gbox)
{

View file

@ -410,6 +410,11 @@ extern char* gbox_to_string(GBOX *gbox);
*/
extern GBOX* gbox_copy(GBOX *gbox);
/**
* Warning, do not use this function, it is very particular about inputs.
*/
extern GBOX* gbox_from_string(char *str);
/**
* Return #LW_TRUE if the #GBOX overlaps, #LW_FALSE otherwise.
*/