From: Sandro Santilli Date: Sun, 11 Aug 2013 15:55:50 +0000 (+0000) Subject: Require at least 8 edges to define a full circle (#2420) X-Git-Tag: 2.2.0rc1~1411 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b821c1aabe7655b9eaef4b4028af1223a832b9b;p=postgis Require at least 8 edges to define a full circle (#2420) git-svn-id: http://svn.osgeo.org/postgis/trunk@11769 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwsegmentize.c b/liblwgeom/lwsegmentize.c index 4fa9671b9..b7858f4e4 100644 --- a/liblwgeom/lwsegmentize.c +++ b/liblwgeom/lwsegmentize.c @@ -16,6 +16,9 @@ #include #include "liblwgeom_internal.h" + +//#define POSTGIS_DEBUG_LEVEL 4 + #include "lwgeom_log.h" @@ -551,9 +554,11 @@ pta_desegmentize(POINTARRAY *points, int type, int srid) int found_arc = LW_FALSE; int current_arc = 1; int num_edges; - int edge_type = -1; + int edge_type; /* non-zero if edge is part of an arc */ int start, end; LWCOLLECTION *outcol; + /* Minimum number of edges, per quadrant, required to define an arc */ + const unsigned int min_quad_edges = 2; /* Die on null input */ if ( ! points ) @@ -608,6 +613,24 @@ pta_desegmentize(POINTARRAY *points, int type, int srid) /* Jump past all the edges that were added to the arc */ if ( found_arc ) { + /* Check if an arc was composed by enough edges to be + * really considered an arc + * See http://trac.osgeo.org/postgis/ticket/2420 + */ + unsigned int arc_edges = j - 1 - i; + unsigned int num_quadrants = 1; /* silly guess, TODO: compute */ + LWDEBUGF(4, "arc defined by %d edges found", arc_edges); + if ( a1.x == b.x && a1.y == b.y ) { + LWDEBUG(4, "arc is a circle"); + num_quadrants = 4; + } + /* a1 is first point, b is last point */ + if ( arc_edges < min_quad_edges * num_quadrants ) { + LWDEBUGF(4, "Not enough edges for a %d quadrants arc", num_quadrants); + for ( k = j-1; k >= i; k-- ) + edges_in_arcs[k] = 0; + } + i = j-1; } else diff --git a/regress/tickets.sql b/regress/tickets.sql index d58ee794c..c516b6d3a 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -831,5 +831,7 @@ SELECT '#2415.2', ST_AsText(ST_Multi( SELECT '#2412', ST_AsText(ST_LineToCurve('LINESTRING(0 0,10 0,20 0)')); +SELECT '#2430', ST_AsText(ST_LineToCurve('LINESTRING(0 0,10 0,10 10,0 10,0 0)')); + -- Clean up DELETE FROM spatial_ref_sys; diff --git a/regress/tickets_expected b/regress/tickets_expected index 1084bae7c..82130cf80 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -247,3 +247,4 @@ ERROR: invalid GML representation #2415.1|MULTICURVE(COMPOUNDCURVE((0 0,10 0),CIRCULARSTRING(10 0,15 1,20 10))) #2415.2|MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(10 0,15 1,20 0,18 5,20 10,10 10,10 0))) #2412|LINESTRING(0 0,10 0,20 0) +#2430|LINESTRING(0 0,10 0,10 10,0 10,0 0)