]> granicus.if.org Git - postgis/commitdiff
Use minimum tolerance when adding pre-snapped edge endpoints
authorSandro Santilli <strk@kbt.io>
Sun, 22 Oct 2017 15:38:54 +0000 (15:38 +0000)
committerSandro Santilli <strk@kbt.io>
Sun, 22 Oct 2017 15:38:54 +0000 (15:38 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@16034 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwgeom_topo.c

index 791151c671bdaf8219e233a9bdcb2f9e4eba9c35..1f487c41ee89a7862d4b606caab56e25c6990b58 100644 (file)
@@ -4999,6 +4999,25 @@ lwt_GetFaceByPoint(LWT_TOPOLOGY *topo, LWPOINT *pt, double tol)
   return id;
 }
 
+/* Return the smallest delta that can perturbate
+ * the given value */
+static inline double
+_lwt_minToleranceDouble( double d )
+{
+  double ret = 3.6 * pow(10,  - ( 15 - log10(d?d:1.0) ) );
+  return ret;
+}
+
+/* Return the smallest delta that can perturbate
+ * the given point */
+static inline double
+_lwt_minTolerancePoint2d( const POINT2D* p )
+{
+  double max = FP_ABS(p->x);
+  if ( max < FP_ABS(p->y) ) max = FP_ABS(p->y);
+  return _lwt_minToleranceDouble(max);
+}
+
 /* Return the smallest delta that can perturbate
  * the maximum absolute value of a geometry ordinate
  */
@@ -5016,7 +5035,7 @@ _lwt_minTolerance( LWGEOM *g )
   if ( max < FP_ABS(gbox->ymin) ) max = FP_ABS(gbox->ymin);
   if ( max < FP_ABS(gbox->ymax) ) max = FP_ABS(gbox->ymax);
 
-  ret = 3.6 * pow(10,  - ( 15 - log10(max?max:1.0) ) );
+  ret = _lwt_minToleranceDouble(max);
 
   return ret;
 }
@@ -5486,7 +5505,9 @@ _lwt_AddLineEdge( LWT_TOPOLOGY* topo, LWLINE* edge, double tol,
     lwnotice("Empty component of noded line");
     return 0; /* must be empty */
   }
-  nid[0] = _lwt_AddPoint( topo, start_point, tol, handleFaceSplit );
+  nid[0] = _lwt_AddPoint( topo, start_point,
+                          _lwt_minTolerance(lwpoint_as_lwgeom(start_point)),
+                          handleFaceSplit );
   lwpoint_free(start_point); /* too late if lwt_AddPoint calls lwerror */
   if ( nid[0] == -1 ) return -1; /* lwerror should have been called */
 
@@ -5497,7 +5518,9 @@ _lwt_AddLineEdge( LWT_TOPOLOGY* topo, LWLINE* edge, double tol,
             "after successfully getting first point !?");
     return -1;
   }
-  nid[1] = _lwt_AddPoint( topo, end_point, tol, handleFaceSplit );
+  nid[1] = _lwt_AddPoint( topo, end_point,
+                          _lwt_minTolerance(lwpoint_as_lwgeom(end_point)),
+                          handleFaceSplit );
   lwpoint_free(end_point); /* too late if lwt_AddPoint calls lwerror */
   if ( nid[1] == -1 ) return -1; /* lwerror should have been called */