[postgis-commits] svn - r3651 - spike/mleslie/parser/liblwgeom
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Thu Feb 5 22:25:22 PST 2009
Author: mleslie
Date: 2009-02-05 22:25:21 -0800 (Thu, 05 Feb 2009)
New Revision: 3651
Modified:
spike/mleslie/parser/liblwgeom/lwgparse.c
spike/mleslie/parser/liblwgeom/wktparse.h
spike/mleslie/parser/liblwgeom/wktparse.tab.c
spike/mleslie/parser/liblwgeom/wktparse.y
Log:
Clearing out some unnecessary indirection.
Modified: spike/mleslie/parser/liblwgeom/lwgparse.c
===================================================================
--- spike/mleslie/parser/liblwgeom/lwgparse.c 2009-02-05 23:10:17 UTC (rev 3650)
+++ spike/mleslie/parser/liblwgeom/lwgparse.c 2009-02-06 06:25:21 UTC (rev 3651)
@@ -212,20 +212,23 @@
void alloc_counter(void);
void alloc_empty(void);
void check_compoundcurve(void);
+void check_closed_compoundcurve(void);
void check_linestring(void);
+void check_closed_linestring(void);
+void check_circularstring(void);
+void check_closed_circularstring(void);
void check_polygon(void);
void check_curvepolygon(void);
-void check_circularstring(void);
void check_compoundcurve_continuity(void);
-void check_geometry_closed(void);
-void check_polygon_closed(void);
void check_compoundcurve_closed(void);
void check_linestring_closed(void);
-void check_geometry_minpoints(void);
-void check_polygon_minpoints(int);
-void check_curvepolygon_minpoints(int);
-void check_compoundcurve_minpoints(int);
-void check_linestring_minpoints(int);
+void check_circularstring_closed(void);
+void check_polygon_closed(void);
+void check_polygon_minpoints(void);
+void check_curvepolygon_minpoints(void);
+void check_compoundcurve_minpoints(void);
+void check_linestring_minpoints(void);
+void check_circularstring_minpoints(void);
void check_circularstring_isodd(void);
void make_serialized_lwgeom(LWGEOM_PARSER_RESULT *lwg_parser_result);
uchar strhex_readbyte(const char *in);
@@ -423,46 +426,56 @@
LWDEBUGF(4, "alloc_stack_tuple complete: %p", the_geom.stack);
}
-void
-pop(void)
-{
- LWDEBUGF(3, "pop: type= %d, tuple= %p", the_geom.stack->uu.nn.type,
- the_geom.stack);
- the_geom.stack = the_geom.stack->uu.nn.stack_next;
-}
-
/*
* Begin Check functions
*/
void check_compoundcurve(void)
{
- check_geometry_minpoints();
+ check_compoundcurve_minpoints();
check_compoundcurve_continuity();
}
-void check_linestring(void)
+void check_closed_compoundcurve(void)
{
- check_geometry_minpoints();
+ check_compoundcurve_closed();
+ check_compoundcurve();
}
-void check_polygon(void)
+void check_linestring(void)
{
- check_geometry_minpoints();
- check_geometry_closed();
+ check_linestring_minpoints();
}
-void check_curvepolygon(void)
+void check_closed_linestring(void)
{
- check_geometry_minpoints();
- check_geometry_closed();
+ check_linestring_closed();
+ check_linestring();
}
void check_circularstring(void)
{
+ check_circularstring_minpoints();
check_circularstring_isodd();
}
+void check_closed_circularstring(void)
+{
+ check_linestring_closed();
+ check_circularstring();
+}
+
+void check_polygon(void)
+{
+ check_polygon_minpoints();
+ check_polygon_closed();
+}
+
+void check_curvepolygon(void)
+{
+ check_curvepolygon_minpoints();
+}
+
void
check_compoundcurve_continuity(void)
{
@@ -555,50 +568,6 @@
}
}
-/*
- * Determines if all rings of the current polygon are closed. This is done
- * by marching through the tuple list finding the first and last point tuples
- * of each ring and comparing their 2d values.
- */
-void
-check_polygon_closed(void)
-{
- tuple *tp = the_geom.stack; /* Current tuple */
- int i, j; /* Loop counters */
- int num, mum; /* sub-unit counts */
- tuple *first, *last; /* First and last tuple of the current ring. */
-
- LWDEBUG(3, "check_polygon_closed");
- /* tuple counting rings */
- tp = tp->next;
- num = tp->uu.nn.num;
- for(i = 0; i < num; i++)
- {
- /* ring tuple counting points */
- tp = tp->next;
- mum = tp->uu.nn.num;
- first = tp->next;
- for(j = 0; j < mum; j++)
- {
- tp = tp->next;
- }
- last = tp;
- if(first->uu.points[0] != last->uu.points[0] ||
- first->uu.points[1] != last->uu.points[1])
- {
- LWDEBUGF(4, "Unclosed geometry: (%f, %f) != (%f, %f)",
- first->uu.points[0], first->uu.points[1],
- last->uu.points[0], last->uu.points[1]);
- LWDEBUGF(5, "First %p, last %p", first, last);
- LWGEOM_WKT_VALIDATION_ERROR(PARSER_ERROR_UNCLOSED, last->uu.nn.parse_location);
- }
- else
- {
- LWDEBUGF(5, "Ring %d found closed.", i);
- }
- }
-}
-
/*
* Determines if the compound curve is closed or not. This is done by finding
* the first point tuple of the first sub-geometry then marching through the
@@ -691,29 +660,47 @@
}
}
-/*
- * This will check to ensure that the geometry is closed. The parser has a
- * concept of close separate from non-close, in terms of linear geometries,
- * but polygons are not built from linear geometries, rather just from point
- * arrays, so they need to be dealt with differently. Compound curves require
- * separate handling as well. In other cases, there is
- * a single point array that needs to be checked.
+/*
+ * Determines if all rings of the current polygon are closed. This is done
+ * by marching through the tuple list finding the first and last point tuples
+ * of each ring and comparing their 2d values.
*/
void
-check_geometry_closed(void)
+check_polygon_closed(void)
{
- LWDEBUG(3, "check_geometry_closed");
- switch(TYPE_GETTYPE(the_geom.stack->uu.nn.type)) {
- case POLYGONTYPE:
- check_polygon_closed();
- break;
- case COMPOUNDTYPE:
- check_compoundcurve_closed();
- break;
- case LINETYPE:
- case CIRCSTRINGTYPE:
- check_linestring_closed();
- break;
+ tuple *tp = the_geom.stack; /* Current tuple */
+ int i, j; /* Loop counters */
+ int num, mum; /* sub-unit counts */
+ tuple *first, *last; /* First and last tuple of the current ring. */
+
+ LWDEBUG(3, "check_polygon_closed");
+ /* tuple counting rings */
+ tp = tp->next;
+ num = tp->uu.nn.num;
+ for(i = 0; i < num; i++)
+ {
+ /* ring tuple counting points */
+ tp = tp->next;
+ mum = tp->uu.nn.num;
+ first = tp->next;
+ for(j = 0; j < mum; j++)
+ {
+ tp = tp->next;
+ }
+ last = tp;
+ if(first->uu.points[0] != last->uu.points[0] ||
+ first->uu.points[1] != last->uu.points[1])
+ {
+ LWDEBUGF(4, "Unclosed geometry: (%f, %f) != (%f, %f)",
+ first->uu.points[0], first->uu.points[1],
+ last->uu.points[0], last->uu.points[1]);
+ LWDEBUGF(5, "First %p, last %p", first, last);
+ LWGEOM_WKT_VALIDATION_ERROR(PARSER_ERROR_UNCLOSED, last->uu.nn.parse_location);
+ }
+ else
+ {
+ LWDEBUGF(5, "Ring %d found closed.", i);
+ }
}
}
@@ -723,11 +710,12 @@
* lets keep things generic here for now.
*/
void
-check_polygon_minpoints(int minpoints)
+check_polygon_minpoints(void)
{
tuple *tp = the_geom.stack->next; /* Current tuple */
int i, j; /* Loop counters */
int num, mum; /* ring / point count */
+ int minpoints = 4;
LWDEBUG(3, "check_polygon_minpoints");
@@ -763,12 +751,13 @@
* geometry) contains the minimum number of points.
*/
void
-check_curvepolygon_minpoints(int minpoints)
+check_curvepolygon_minpoints()
{
tuple *tp = the_geom.stack->next; /* Current tuple */
int i, j, k; /* Loop counters */
int num, mum, lum; /* subgeom, point counts */
int count = 0; /* Running counter for compound curve */
+ int minpoints = 4;
num = tp->uu.nn.num;
LWDEBUG(3, "check_curvepolygon_minpoints");
@@ -829,12 +818,13 @@
* redundant and shall not be counted.
*/
void
-check_compoundcurve_minpoints(int minpoints)
+check_compoundcurve_minpoints()
{
tuple *tp = the_geom.stack->next; /* Current tuple */
int i, j; /* Loop counters */
int num, mum; /* sub-geom / point count */
int count = 0; /* Running count of points */
+ int minpoints = 3;
LWDEBUG(3, "check_compoundcurve_minpoints");
num = tp->uu.nn.num;
@@ -871,10 +861,11 @@
}
void
-check_linestring_minpoints(int minpoints)
+check_linestring_minpoints()
{
tuple *tp = the_geom.stack->next; /* Current counting tuple */
int i, num;
+ int minpoints = 2;
LWDEBUG(3, "check_linestring_minpoints");
if(tp->uu.nn.num < minpoints)
@@ -890,41 +881,19 @@
}
}
-/*
- * This method checks the counter tuples of the geometry to ensure a minimum
- * number of points are available
- */
-void
-check_geometry_minpoints(void)
-{
- LWDEBUG(3, "check_geometry_minpoints");
- switch(TYPE_GETTYPE(the_geom.stack->uu.nn.type)) {
- case POLYGONTYPE:
- check_polygon_minpoints(4);
- break;
- case CURVEPOLYTYPE:
- check_curvepolygon_minpoints(4);
- break;
- case COMPOUNDTYPE:
- check_compoundcurve_minpoints(3);
- break;
- case LINETYPE:
- case CIRCSTRINGTYPE:
- check_linestring_minpoints(2);
- break;
- }
- LWDEBUG(4, "check_geometry_minpoints complete");
+void check_circularstring_minpoints()
+{
+ check_linestring_minpoints();
}
void
-popc(void)
+pop(void)
{
- LWDEBUGF(3, "popc: tuple= %p", the_geom.stack);
-
+ LWDEBUGF(3, "pop: type= %d, tuple= %p", the_geom.stack->uu.nn.type,
+ the_geom.stack);
the_geom.stack = the_geom.stack->uu.nn.stack_next;
}
-
void
check_dims(int num)
{
@@ -1466,7 +1435,7 @@
}
/* Perform a check of the ordinate array */
- popc();
+ pop();
}
void
Modified: spike/mleslie/parser/liblwgeom/wktparse.h
===================================================================
--- spike/mleslie/parser/liblwgeom/wktparse.h 2009-02-05 23:10:17 UTC (rev 3650)
+++ spike/mleslie/parser/liblwgeom/wktparse.h 2009-02-06 06:25:21 UTC (rev 3651)
@@ -109,7 +109,9 @@
void check_polygon(void);
void check_curvepolygon(void);
void check_circularstring(void);
-void check_geometry_closed(void);
+void check_closed_compoundcurve(void);
+void check_closed_linestring(void);
+void check_closed_circularstring(void);
void pop(void);
void popc(void);
Modified: spike/mleslie/parser/liblwgeom/wktparse.tab.c
===================================================================
--- spike/mleslie/parser/liblwgeom/wktparse.tab.c 2009-02-05 23:10:17 UTC (rev 3650)
+++ spike/mleslie/parser/liblwgeom/wktparse.tab.c 2009-02-06 06:25:21 UTC (rev 3651)
@@ -1821,7 +1821,7 @@
case 53:
#line 140 "wktparse.y"
- { check_geometry_closed(); check_linestring(); pop(); }
+ { check_closed_linestring(); pop(); }
break;
case 54:
@@ -1831,7 +1831,7 @@
case 55:
#line 143 "wktparse.y"
- { popc(); }
+ { pop(); }
break;
case 59:
@@ -1871,7 +1871,7 @@
case 73:
#line 179 "wktparse.y"
- { check_geometry_closed(); check_circularstring(); pop(); }
+ { check_closed_circularstring(); pop(); }
break;
case 74:
@@ -1881,7 +1881,7 @@
case 75:
#line 182 "wktparse.y"
- { popc(); }
+ { pop(); }
break;
case 79:
@@ -1931,7 +1931,7 @@
case 95:
#line 221 "wktparse.y"
- { check_geometry_closed(); check_compoundcurve(); pop(); }
+ { check_closed_compoundcurve(); pop(); }
break;
case 96:
@@ -1941,7 +1941,7 @@
case 97:
#line 224 "wktparse.y"
- {popc();}
+ {pop();}
break;
case 102:
Modified: spike/mleslie/parser/liblwgeom/wktparse.y
===================================================================
--- spike/mleslie/parser/liblwgeom/wktparse.y 2009-02-05 23:10:17 UTC (rev 3650)
+++ spike/mleslie/parser/liblwgeom/wktparse.y 2009-02-06 06:25:21 UTC (rev 3651)
@@ -137,10 +137,10 @@
{ alloc_linestring(); } linestring_1 { check_linestring(); pop(); }
nonempty_linestring_closed :
- { alloc_linestring_closed(); } linestring_1 { check_geometry_closed(); check_linestring(); pop(); }
+ { alloc_linestring_closed(); } linestring_1 { check_closed_linestring(); pop(); }
linestring_1 :
- { alloc_counter(); } LPAREN linestring_int RPAREN { popc(); }
+ { alloc_counter(); } LPAREN linestring_int RPAREN { pop(); }
linestring_int :
a_point
@@ -176,10 +176,10 @@
{ alloc_circularstring(); } circularstring_1 { check_circularstring(); pop(); }
nonempty_circularstring_closed :
- { alloc_circularstring_closed(); } circularstring_1 { check_geometry_closed(); check_circularstring(); pop(); }
+ { alloc_circularstring_closed(); } circularstring_1 { check_closed_circularstring(); pop(); }
circularstring_1 :
- { alloc_counter(); } LPAREN circularstring_int RPAREN { popc(); }
+ { alloc_counter(); } LPAREN circularstring_int RPAREN { pop(); }
circularstring_int :
a_point
@@ -218,10 +218,10 @@
{ alloc_compoundcurve(); } compoundcurve_1 { check_compoundcurve(); pop(); }
nonempty_compoundcurve_closed:
- { alloc_compoundcurve_closed(); } compoundcurve_1 { check_geometry_closed(); check_compoundcurve(); pop(); }
+ { alloc_compoundcurve_closed(); } compoundcurve_1 { check_closed_compoundcurve(); pop(); }
compoundcurve_1:
- { alloc_counter(); } LPAREN compoundcurve_int RPAREN {popc();}
+ { alloc_counter(); } LPAREN compoundcurve_int RPAREN {pop();}
compoundcurve_int:
nonempty_linestring
More information about the postgis-commits
mailing list