Make the ptarray_add_point behavior more explicit.

git-svn-id: http://svn.osgeo.org/postgis/trunk@6190 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
Paul Ramsey 2010-11-23 00:44:24 +00:00
parent 1ea46cf7a5
commit 262696c293
16 changed files with 77 additions and 70 deletions

View file

@ -41,13 +41,13 @@ static void test_ptarray_append_point(void)
line = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0,1 1)"));
p.x = 1;
p.y = 1;
ptarray_append_point(line->points, &p, LW_TRUE);
ptarray_append_point(line->points, &p, REPEATED_POINTS_OK);
wkt = lwgeom_to_text(lwline_as_lwgeom(line));
printf("\nWTK: %s\n",wkt);
CU_ASSERT_STRING_EQUAL(wkt,"LINESTRING(0 0,1 1,1 1)");
lwfree(wkt);
ptarray_append_point(line->points, &p, LW_FALSE);
ptarray_append_point(line->points, &p, REPEATED_POINTS_NOT_OK);
wkt = lwgeom_to_text(lwline_as_lwgeom(line));
printf("\nWTK: %s\n",wkt);
CU_ASSERT_STRING_EQUAL(wkt,"LINESTRING(0 0,1 1,1 1)");

View file

@ -62,8 +62,7 @@ int main()
point4d.x = 0;
point4d.y = 51;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
testpoint = lwpoint_construct(-1, NULL, dpa);
/* Generate the LWGEOM from LWPOINT, then serialize it ready for the parser */
@ -89,15 +88,15 @@ int main()
dpa = ptarray_construct_empty(0, 0, 2);
point4d.x = 0;
point4d.y = 0;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
point4d.x = 2;
point4d.y = 2;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
point4d.x = 4;
point4d.y = 1;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
testline = lwline_construct(-1, NULL, dpa);
@ -128,23 +127,23 @@ int main()
dpa = ptarray_construct_empty(0, 0, 2);
point4d.x = 0;
point4d.y = 0;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
point4d.x = 0;
point4d.y = 10;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
point4d.x = 10;
point4d.y = 10;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
point4d.x = 10;
point4d.y = 0;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
point4d.x = 0;
point4d.y = 0;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
rings[0] = dpa;
@ -152,23 +151,23 @@ int main()
dpa = ptarray_construct_empty(0, 0, 2);
point4d.x = 3;
point4d.y = 3;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
point4d.x = 3;
point4d.y = 6;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
point4d.x = 6;
point4d.y = 6;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
point4d.x = 6;
point4d.y = 3;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
point4d.x = 3;
point4d.y = 3;
ptarray_append_point(dpa, &point4d, 0);
ptarray_append_point(dpa, &point4d, REPEATED_POINTS_NOT_OK);
rings[1] = dpa;

View file

@ -72,6 +72,16 @@
#define NO_Z_VALUE NO_VALUE
#define NO_M_VALUE NO_VALUE
/**
* Repeated points defines
* TODO, move to _internal
*/
#define REPEATED_POINTS_OK 1
#define REPEATED_POINTS_NOT_OK 0
#define SPLICE_LINES_YES 1
#define SPLICE_LINES_NO 1
/**
* Largest float value. TODO: Should this be from math.h instead?
*/

View file

@ -73,8 +73,6 @@
#define WKB_TIN_TYPE 16
#define WKB_TRIANGLE_TYPE 17
/**
* Macro for reading the size from the GSERIALIZED size attribute.
* Cribbed from PgSQL, top 30 bits are size. Use VARSIZE() when working

View file

@ -521,17 +521,17 @@ lwgeom_from_tgeom(TGEOM *tgeom)
assert(edge_id);
if (edge_id > 0)
ptarray_append_point(dpa, tgeom->edges[edge_id]->s, LW_TRUE);
ptarray_append_point(dpa, tgeom->edges[edge_id]->s, REPEATED_POINTS_OK);
else
ptarray_append_point(dpa, tgeom->edges[-edge_id]->e, LW_TRUE);
ptarray_append_point(dpa, tgeom->edges[-edge_id]->e, REPEATED_POINTS_OK);
}
edge_id = tgeom->faces[i]->edges[0];
LWDEBUGF(3, "TIN edge_id: %i\n", edge_id);
if (edge_id > 0)
ptarray_append_point(dpa, tgeom->edges[edge_id]->s, LW_TRUE);
ptarray_append_point(dpa, tgeom->edges[edge_id]->s, REPEATED_POINTS_OK);
else
ptarray_append_point(dpa, tgeom->edges[-edge_id]->e, LW_TRUE);
ptarray_append_point(dpa, tgeom->edges[-edge_id]->e, REPEATED_POINTS_OK);
geom = (LWGEOM *) lwtin_add_lwtriangle((LWTIN *) geom,
lwtriangle_construct(tgeom->srid, NULL, dpa));
@ -552,17 +552,17 @@ lwgeom_from_tgeom(TGEOM *tgeom)
assert(edge_id);
LWDEBUGF(3, "POLYHEDRALSURFACE edge_id: %i\n", edge_id);
if (edge_id > 0)
ptarray_append_point(dpa, tgeom->edges[edge_id]->s, LW_TRUE);
ptarray_append_point(dpa, tgeom->edges[edge_id]->s, REPEATED_POINTS_OK);
else
ptarray_append_point(dpa, tgeom->edges[-edge_id]->e, LW_TRUE);
ptarray_append_point(dpa, tgeom->edges[-edge_id]->e, REPEATED_POINTS_OK);
}
edge_id = tgeom->faces[i]->edges[0];
LWDEBUGF(3, "POLYHEDRALSURFACE edge_id: %i\n", edge_id);
if (edge_id > 0)
ptarray_append_point(dpa, tgeom->edges[edge_id]->s, LW_TRUE);
ptarray_append_point(dpa, tgeom->edges[edge_id]->s, REPEATED_POINTS_OK);
else
ptarray_append_point(dpa, tgeom->edges[-edge_id]->e, LW_TRUE);
ptarray_append_point(dpa, tgeom->edges[-edge_id]->e, REPEATED_POINTS_OK);
ppa = lwalloc(sizeof(POINTARRAY*)
* (tgeom->faces[i]->nrings + 1));

View file

@ -532,12 +532,12 @@ LWCOLLECTION *lwline_clip_to_ordinate_range(LWLINE *line, int ordinate, double f
double interpolation_value;
(ordinate_value_q > to) ? (interpolation_value = to) : (interpolation_value = from);
rv = lwpoint_interpolate(q, p, r, dims, ordinate, interpolation_value);
rv = ptarray_append_point(dp, r, LW_FALSE);
rv = ptarray_append_point(dp, r, REPEATED_POINTS_NOT_OK);
LWDEBUGF(4, "[0] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
}
}
/* Add the current vertex to the point array. */
rv = ptarray_append_point(dp, p, LW_FALSE);
rv = ptarray_append_point(dp, p, REPEATED_POINTS_NOT_OK);
if ( ordinate_value_p == from || ordinate_value_p == to )
{
added_last_point = 2; /* Added on boundary. */
@ -558,7 +558,7 @@ LWCOLLECTION *lwline_clip_to_ordinate_range(LWLINE *line, int ordinate, double f
double interpolation_value;
(ordinate_value_p > to) ? (interpolation_value = to) : (interpolation_value = from);
rv = lwpoint_interpolate(q, p, r, dims, ordinate, interpolation_value);
rv = ptarray_append_point(dp, r, LW_FALSE);
rv = ptarray_append_point(dp, r, REPEATED_POINTS_NOT_OK);
LWDEBUGF(4, " [1] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
}
else if ( added_last_point == 2 )
@ -573,7 +573,7 @@ LWCOLLECTION *lwline_clip_to_ordinate_range(LWLINE *line, int ordinate, double f
double interpolation_value;
(ordinate_value_p > to) ? (interpolation_value = to) : (interpolation_value = from);
rv = lwpoint_interpolate(q, p, r, dims, ordinate, interpolation_value);
rv = ptarray_append_point(dp, r, LW_FALSE);
rv = ptarray_append_point(dp, r, REPEATED_POINTS_NOT_OK);
LWDEBUGF(4, " [2] interpolating between (%g, %g) with interpolation point (%g)", ordinate_value_q, ordinate_value_p, interpolation_value);
}
}

View file

@ -245,7 +245,7 @@ POINTARRAY* wkt_parser_ptarray_add_coord(POINTARRAY *pa, POINT p)
if( FLAGS_GET_M(pa->dims) && ! FLAGS_GET_Z(pa->dims) )
pt.m = p.z;
ptarray_append_point(pa, &pt, LW_TRUE); /* Allow duplicate points in array */
ptarray_append_point(pa, &pt, REPEATED_POINTS_OK); /* Allow duplicate points in array */
return pa;
}

View file

@ -301,7 +301,7 @@ lwcurve_segmentize(LWCIRCSTRING *icurve, uint32 perQuad)
{
lwerror("lwcurve_segmentize: Cannot extract point.");
}
ptarray_append_point(ptarray, &p4, LW_TRUE);
ptarray_append_point(ptarray, &p4, REPEATED_POINTS_OK);
for (i = 2; i < icurve->points->npoints; i+=2)
{
@ -319,7 +319,7 @@ lwcurve_segmentize(LWCIRCSTRING *icurve, uint32 perQuad)
for (j = 0; j < tmp->npoints; j++)
{
getPoint4d_p(tmp, j, &p4);
ptarray_append_point(ptarray, &p4, LW_TRUE);
ptarray_append_point(ptarray, &p4, REPEATED_POINTS_OK);
}
lwfree(tmp);
}
@ -330,7 +330,7 @@ lwcurve_segmentize(LWCIRCSTRING *icurve, uint32 perQuad)
for (j = i - 1 ; j <= i ; j++)
{
getPoint4d_p(icurve->points, j, &p4);
ptarray_append_point(ptarray, &p4, LW_TRUE);
ptarray_append_point(ptarray, &p4, REPEATED_POINTS_OK);
}
}
@ -361,7 +361,7 @@ lwcompound_segmentize(LWCOMPOUND *icompound, uint32 perQuad)
for (j = 0; j < tmp->points->npoints; j++)
{
getPoint4d_p(tmp->points, j, &p);
ptarray_append_point(ptarray, &p, LW_TRUE);
ptarray_append_point(ptarray, &p, REPEATED_POINTS_OK);
}
lwfree(tmp);
}
@ -371,7 +371,7 @@ lwcompound_segmentize(LWCOMPOUND *icompound, uint32 perQuad)
for (j = 0; j < tmp->points->npoints; j++)
{
getPoint4d_p(tmp->points, j, &p);
ptarray_append_point(ptarray, &p, LW_TRUE);
ptarray_append_point(ptarray, &p, REPEATED_POINTS_OK);
}
}
else

View file

@ -120,7 +120,7 @@ ptarray_insert_point(POINTARRAY *pa, POINT4D *p, int where)
}
int
ptarray_append_point(POINTARRAY *pa, POINT4D *pt, int allow_duplicates)
ptarray_append_point(POINTARRAY *pa, POINT4D *pt, int repeated_points)
{
/* Check for pathology */
@ -131,7 +131,7 @@ ptarray_append_point(POINTARRAY *pa, POINT4D *pt, int allow_duplicates)
}
/* Check for duplicate end point */
if ( ! allow_duplicates && pa->npoints > 0 )
if ( repeated_points == REPEATED_POINTS_NOT_OK && pa->npoints > 0 )
{
POINT4D tmp;
getPoint4d_p(pa, pa->npoints-1, &tmp);
@ -401,7 +401,7 @@ ptarray_segmentize2d(const POINTARRAY *ipa, double dist)
/* Add first point */
getPoint4d_p(ipa, ipoff, &p1);
ptarray_append_point(opa, &p1, 0);
ptarray_append_point(opa, &p1, REPEATED_POINTS_NOT_OK);
ipoff++;
@ -431,12 +431,12 @@ ptarray_segmentize2d(const POINTARRAY *ipa, double dist)
pbuf.z = p1.z + (p2.z-p1.z)/segdist * dist;
if( hasm )
pbuf.m = p1.m + (p2.m-p1.m)/segdist * dist;
ptarray_append_point(opa, &pbuf, 0);
ptarray_append_point(opa, &pbuf, REPEATED_POINTS_NOT_OK);
p1 = pbuf;
}
else /* copy second point */
{
ptarray_append_point(opa, &p2, 0);
ptarray_append_point(opa, &p2, REPEATED_POINTS_NOT_OK);
p1 = p2;
ipoff++;
}
@ -685,7 +685,7 @@ ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm)
pt.z = 0.0;
if( hasm && ! in_hasm )
pt.m = 0.0;
ptarray_append_point(pa_out, &pt, LW_TRUE);
ptarray_append_point(pa_out, &pt, REPEATED_POINTS_OK);
}
return pa_out;
@ -840,7 +840,7 @@ ptarray_substring(POINTARRAY *ipa, double from, double to)
/*
* Second point is our start
*/
ptarray_append_point(dpa, &p2, LW_TRUE);
ptarray_append_point(dpa, &p2, REPEATED_POINTS_OK);
state=1; /* we're inside now */
goto END;
}
@ -853,7 +853,7 @@ ptarray_substring(POINTARRAY *ipa, double from, double to)
/*
* First point is our start
*/
ptarray_append_point(dpa, &p1, LW_TRUE);
ptarray_append_point(dpa, &p1, REPEATED_POINTS_OK);
/*
* We're inside now, but will check
@ -874,7 +874,7 @@ ptarray_substring(POINTARRAY *ipa, double from, double to)
dseg = (from - tlength) / slength;
interpolate_point4d(&p1, &p2, &pt, dseg);
ptarray_append_point(dpa, &pt, LW_TRUE);
ptarray_append_point(dpa, &pt, REPEATED_POINTS_OK);
/*
* We're inside now, but will check
@ -895,7 +895,7 @@ ptarray_substring(POINTARRAY *ipa, double from, double to)
*/
if ( to > tlength + slength )
{
ptarray_append_point(dpa, &p2, LW_FALSE);
ptarray_append_point(dpa, &p2, REPEATED_POINTS_NOT_OK);
goto END;
}
@ -907,7 +907,7 @@ ptarray_substring(POINTARRAY *ipa, double from, double to)
LWDEBUG(3, " Second point is our end");
ptarray_append_point(dpa, &p2, LW_FALSE);
ptarray_append_point(dpa, &p2, REPEATED_POINTS_NOT_OK);
break; /* substring complete */
}
@ -920,7 +920,7 @@ ptarray_substring(POINTARRAY *ipa, double from, double to)
LWDEBUG(3, " First point is our end");
ptarray_append_point(dpa, &p1, LW_FALSE);
ptarray_append_point(dpa, &p1, REPEATED_POINTS_NOT_OK);
break; /* substring complete */
}
@ -937,7 +937,7 @@ ptarray_substring(POINTARRAY *ipa, double from, double to)
dseg = (to - tlength) / slength;
interpolate_point4d(&p1, &p2, &pt, dseg);
ptarray_append_point(dpa, &pt, LW_FALSE);
ptarray_append_point(dpa, &pt, REPEATED_POINTS_NOT_OK);
break;
}
@ -1225,7 +1225,7 @@ ptarray_simplify(POINTARRAY *inpts, double epsilon)
/* Allocate output POINTARRAY, and add first point. */
outpts = ptarray_construct_empty(FLAGS_GET_Z(inpts->dims), FLAGS_GET_M(inpts->dims), inpts->npoints);
getPoint4d_p(inpts, 0, &pt);
ptarray_append_point(outpts, &pt, LW_FALSE);
ptarray_append_point(outpts, &pt, REPEATED_POINTS_NOT_OK);
LWDEBUG(3, "Added P0 to simplified point array (size 1)");
@ -1243,7 +1243,7 @@ ptarray_simplify(POINTARRAY *inpts, double epsilon)
else
{
getPoint4d_p(inpts, stack[sp], &pt);
ptarray_append_point(outpts, &pt, LW_FALSE);
ptarray_append_point(outpts, &pt, REPEATED_POINTS_NOT_OK);
LWDEBUGF(4, "Added P%d to simplified point array (size: %d)", stack[sp], outpts->npoints);

View file

@ -292,7 +292,7 @@ GeneratePointGeometry(SHPLOADERSTATE *state, SHPObject *obj, char **geometry)
/* Create a dynptarray containing a single point */
dpas[u] = ptarray_construct_empty(hasz, hasm, 1);
ptarray_append_point(dpas[u], &point4d, LW_FALSE);
ptarray_append_point(dpas[u], &point4d, REPEATED_POINTS_NOT_OK);
/* Generate the LWPOINT */
lwmultipoints[u] = lwpoint_as_lwgeom(lwpoint_construct(state->config->sr_id, NULL, dpas[u]));
@ -420,7 +420,7 @@ GenerateLineStringGeometry(SHPLOADERSTATE *state, SHPObject *obj, char **geometr
if (state->wkbtype & WKBMOFFSET)
point4d.m = obj->padfM[v];
ptarray_append_point(dpas[u], &point4d, LW_FALSE);
ptarray_append_point(dpas[u], &point4d, REPEATED_POINTS_NOT_OK);
}
/* Generate the LWLINE */
@ -773,7 +773,7 @@ GeneratePolygonGeometry(SHPLOADERSTATE *state, SHPObject *obj, char **geometry)
if (state->wkbtype & WKBMOFFSET)
point4d.m = polyring->list[vi].m;
ptarray_append_point(dpas, &point4d, LW_FALSE);
ptarray_append_point(dpas, &point4d, REPEATED_POINTS_NOT_OK);
}
/* Copy the POINTARRAY pointer so we can use the LWPOLY constructor */

View file

@ -318,7 +318,7 @@ ptarray_grid(POINTARRAY *pa, gridspec *grid)
pbuf.m = rint((pbuf.m - grid->ipm)/grid->msize) *
grid->msize + grid->ipm;
ptarray_append_point(dpa, &pbuf, LW_FALSE);
ptarray_append_point(dpa, &pbuf, REPEATED_POINTS_NOT_OK);
}

View file

@ -1884,19 +1884,19 @@ Datum LWGEOM_expand(PG_FUNCTION_ARGS)
/* Assign coordinates to POINT2D array */
pt.x = box3d.xmin;
pt.y = box3d.ymin;
ptarray_append_point(pa, &pt, LW_TRUE);
ptarray_append_point(pa, &pt, REPEATED_POINTS_OK);
pt.x = box3d.xmin;
pt.y = box3d.ymax;
ptarray_append_point(pa, &pt, LW_TRUE);
ptarray_append_point(pa, &pt, REPEATED_POINTS_OK);
pt.x = box3d.xmax;
pt.y = box3d.ymax;
ptarray_append_point(pa, &pt, LW_TRUE);
ptarray_append_point(pa, &pt, REPEATED_POINTS_OK);
pt.x = box3d.xmax;
pt.y = box3d.ymin;
ptarray_append_point(pa, &pt, LW_TRUE);
ptarray_append_point(pa, &pt, REPEATED_POINTS_OK);
pt.x = box3d.xmin;
pt.y = box3d.ymin;
ptarray_append_point(pa, &pt, LW_TRUE);
ptarray_append_point(pa, &pt, REPEATED_POINTS_OK);
/* Construct point array */
ppa[0] = pa;

View file

@ -245,12 +245,12 @@ ptarray_locate_between_m(POINTARRAY *ipa, double m0, double m1)
LWDEBUGF(3, " 1 creating new POINTARRAY with first point %g,%g,%g,%g", p1.x, p1.y, p1.z, p1.m);
dpa = ptarray_construct_empty(FLAGS_GET_Z(ipa->dims), FLAGS_GET_M(ipa->dims), ipa->npoints-i);
ptarray_append_point(dpa, &p1, LW_TRUE);
ptarray_append_point(dpa, &p1, REPEATED_POINTS_OK);
}
/* Otherwise always add the next point, avoiding duplicates */
if (dpa)
ptarray_append_point(dpa, &p2, LW_FALSE);
ptarray_append_point(dpa, &p2, REPEATED_POINTS_NOT_OK);
/*
* second point has been clipped

View file

@ -630,7 +630,7 @@ static POINTARRAY* parse_gml_coordinates(xmlNodePtr xnode, bool *hasz)
*hasz = false;
}
ptarray_append_point(dpa, &pt, LW_FALSE);
ptarray_append_point(dpa, &pt, REPEATED_POINTS_NOT_OK);
digit = false;
q = p+1;
@ -698,7 +698,7 @@ static POINTARRAY* parse_gml_coord(xmlNodePtr xnode, bool *hasz)
if (!x || !y) lwerror("invalid GML representation");
if (!z) *hasz = false;
ptarray_append_point(dpa, &p, LW_FALSE);
ptarray_append_point(dpa, &p, REPEATED_POINTS_NOT_OK);
x = y = z = false;
return ptarray_clone(dpa);
@ -774,7 +774,7 @@ static POINTARRAY* parse_gml_pos(xmlNodePtr xnode, bool *hasz)
if (gml_dim < 2 || gml_dim > 3 || gml_dim != dim)
lwerror("invalid GML representation");
ptarray_append_point(dpa, &pt, LW_FALSE);
ptarray_append_point(dpa, &pt, REPEATED_POINTS_NOT_OK);
}
return ptarray_clone(dpa);
@ -831,7 +831,7 @@ static POINTARRAY* parse_gml_poslist(xmlNodePtr xnode, bool *hasz)
if (gml_dim == dim)
{
ptarray_append_point(dpa, &pt, LW_FALSE);
ptarray_append_point(dpa, &pt, REPEATED_POINTS_NOT_OK);
gml_dim = 0;
}
else if (*(poslist+1) == '\0')

View file

@ -325,7 +325,7 @@ static POINTARRAY* parse_kml_coordinates(xmlNodePtr xnode, bool *hasz)
*hasz = false;
}
ptarray_append_point(dpa, &pt, LW_FALSE);
ptarray_append_point(dpa, &pt, REPEATED_POINTS_NOT_OK);
digit = false;
q = p+1;
kml_dims = 0;

View file

@ -129,11 +129,11 @@ RTREE_NODE *createLeafNode(POINTARRAY *pa, int startPoint)
getPoint4d_p(pa, startPoint, &tmp);
value1 = tmp.y;
ptarray_append_point(npa,&tmp,1);
ptarray_append_point(npa,&tmp,REPEATED_POINTS_OK);
getPoint4d_p(pa, startPoint+1, &tmp);
value2 = tmp.y;
ptarray_append_point(npa,&tmp,1);
ptarray_append_point(npa,&tmp,REPEATED_POINTS_OK);
line = lwline_construct(-1, NULL, npa);