[Commits] Rev 3605: ST_ConvexHull fixed. in file:///home/hf/wmar/5.3-gis/

holyfoot at askmonty.org holyfoot at askmonty.org
Fri Nov 30 12:41:52 EET 2012


At file:///home/hf/wmar/5.3-gis/

------------------------------------------------------------
revno: 3605
revision-id: holyfoot at askmonty.org-20121130103337-x0deikajst3z5rsr
parent: holyfoot at askmonty.org-20121123134857-779f6r64mbl29f4f
committer: Alexey Botchkov <holyfoot at askmonty.org>
branch nick: 5.3-gis
timestamp: Fri 2012-11-30 14:33:37 +0400
message:
  ST_ConvexHull fixed.
-------------- next part --------------
=== modified file 'mysql-test/r/gis-precise.result'
--- a/mysql-test/r/gis-precise.result	2012-11-23 13:48:57 +0000
+++ b/mysql-test/r/gis-precise.result	2012-11-30 10:33:37 +0000
@@ -200,12 +200,24 @@ result
 SELECT ST_Equals(PointFromText('POINT (12 13)'),PointFromText('POINT (12 13)')) as result;
 result
 1
+Select AsText(ST_ConvexHull(NULL));
+AsText(ST_ConvexHull(NULL))
+NULL
 select astext(st_convexhull(point(0,0)));
 astext(st_convexhull(point(0,0)))
 POINT(0 0)
 select astext(st_convexhull(GeomFromText('GeometryCollection EMPTY')));
 astext(st_convexhull(GeomFromText('GeometryCollection EMPTY')))
 GEOMETRYCOLLECTION EMPTY
+Select AsText(ST_ConvexHull(GeomFromText('MULTIPOINT(0 0, 1 1)')));
+AsText(ST_ConvexHull(GeomFromText('MULTIPOINT(0 0, 1 1)')))
+LINESTRING(0 0,1 1)
+select astext(st_convexhull(GeomFromText("MULTIPOINT(0 0, 7 7, 8 1, 7 0)")));
+astext(st_convexhull(GeomFromText("MULTIPOINT(0 0, 7 7, 8 1, 7 0)")))
+POLYGON((0 0,7 7,8 1,7 0,0 0))
+SELECT AsText(ST_ConvexHull(GeomFromText('POLYGON(( 1 6,  7 10,  4 7,  2 5,  0 5,  1 6))')));
+AsText(ST_ConvexHull(GeomFromText('POLYGON(( 1 6,  7 10,  4 7,  2 5,  0 5,  1 6))')))
+POLYGON((0 5,1 6,7 10,2 5,0 5))
 select astext(st_convexhull(GeomFromText('POLYGON((0 0, 0 1, 1 0, 0 0))')));
 astext(st_convexhull(GeomFromText('POLYGON((0 0, 0 1, 1 0, 0 0))')))
 POLYGON((0 0,0 1,1 0,0 0))

=== modified file 'mysql-test/t/gis-precise.test'
--- a/mysql-test/t/gis-precise.test	2012-11-23 13:48:57 +0000
+++ b/mysql-test/t/gis-precise.test	2012-11-30 10:33:37 +0000
@@ -109,8 +109,12 @@ SELECT ST_Equals(PolyFromText('POLYGON((
 SELECT ST_Equals(PointFromText('POINT (12 13)'),PointFromText('POINT (12 13)')) as result;
 
 # ConvexHull test
+Select AsText(ST_ConvexHull(NULL));
 select astext(st_convexhull(point(0,0)));
 select astext(st_convexhull(GeomFromText('GeometryCollection EMPTY')));
+Select AsText(ST_ConvexHull(GeomFromText('MULTIPOINT(0 0, 1 1)')));
+select astext(st_convexhull(GeomFromText("MULTIPOINT(0 0, 7 7, 8 1, 7 0)")));
+SELECT AsText(ST_ConvexHull(GeomFromText('POLYGON(( 1 6,  7 10,  4 7,  2 5,  0 5,  1 6))')));
 select astext(st_convexhull(GeomFromText('POLYGON((0 0, 0 1, 1 0, 0 0))')));
 select astext(st_convexhull(GeomFromText('POLYGON((10 0, 7 3, 10 6, 0 14, 10 16, 15 15, 12 10, 14 7, 10 0))')));
 select astext(st_convexhull(GeomFromText('POLYGON((10 0, 7 3, 15 6, 0 14, 10 16, 15 15, 12 10, 14 7, 10 0))')));

=== modified file 'sql/item_geofunc.cc'
--- a/sql/item_geofunc.cc	2012-11-23 13:48:57 +0000
+++ b/sql/item_geofunc.cc	2012-11-30 10:33:37 +0000
@@ -382,8 +382,6 @@ int Item_func_convexhull::add_node_to_li
                   cur->prev->pi, cur->pi, cur->pi, pi);
     if (v_sign*dir <0)
       break;
-    /* The last node in the line should be */
-    /* replaced with the curren one.       */
     new_node= cur;
     cur= cur->prev;
     res_heap.free_item(new_node);
@@ -416,7 +414,7 @@ String *Item_func_convexhull::val_str(St
   if ((null_value=
        args[0]->null_value ||
        !(geom= Geometry::construct(&buffer, swkb->ptr(), swkb->length()))))
-    return 0;
+    DBUG_RETURN(0);
   
   geom->get_mbr(&mbr, &c_end);
   collector.set_extent(mbr.xmin, mbr.xmax, mbr.ymin, mbr.ymax);
@@ -472,25 +470,37 @@ String *Item_func_convexhull::val_str(St
         if (add_node_to_line(&left_cur, 1, ev->pi))
           goto mem_error;
       }
-      else
+      if (pit.point())
       {
         /* Check the rightmost point */
         for(; pit.point()->c_get_next(); ++pit)
           ;
-        if (!pit.point()->event)
-          goto skip_point;
-
+      }
+      if (!pit.point() || pit.point()->event)
+      {
         /* Handle right part of the hull. */
         if (add_node_to_line(&right_cur, -1, ev->pi))
           goto mem_error;
       }
     }
-
-skip_point:
-    ;
+skip_point:;
   }
 
   left_cur->next= 0;
+  if (left_first->get_next()->get_next() == NULL &&
+      right_cur->prev->prev == NULL)
+  {
+    /* We only have 2 nodes in the result, so we create a polyline. */
+    if (res_receiver.start_shape(Gcalc_function::shape_line) ||
+        res_receiver.add_point(left_first->pi->x, left_first->pi->y) ||
+        res_receiver.add_point(left_cur->pi->x, left_cur->pi->y) ||
+        res_receiver.complete_shape())
+
+      goto mem_error;
+
+    goto build_result;
+  }
+
   if (res_receiver.start_shape(Gcalc_function::shape_polygon))
     goto mem_error;
 
@@ -500,6 +510,10 @@ String *Item_func_convexhull::val_str(St
       goto mem_error;
     left_first= left_first->get_next();
   }
+
+  /* Skip last point in the right part as it coincides */
+  /* with the last one in the left.                    */
+  right_cur= right_cur->prev;
   while (right_cur->prev)
   {
     if (res_receiver.add_point(right_cur->pi->x, right_cur->pi->y))



More information about the commits mailing list