MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Alexey Botchkov Date:February 17 2010 10:22am
Subject:bzr commit into mysql-5.5-next-mr-bugfixing branch (holyfoot:2968)
Bug#38959
View as plain text  
#At file:///home/hf/work/mysql_common/51mrg/ based on revid:magne.mahre@stripped

 2968 Alexey Botchkov	2010-02-17
      Bug#38959      archive_gis fails due to rounding difference
          Multi_polygon::centroid() has an error in the implementation
            
      per-file messages:
        sql/spatial.cc
      Bug#38959      archive_gis fails due to rounding difference
              multi_polygon::centroid() implementation fixed

    modified:
      sql/spatial.cc
=== modified file 'sql/spatial.cc'
--- a/sql/spatial.cc	2009-12-22 16:23:13 +0000
+++ b/sql/spatial.cc	2010-02-17 10:19:17 +0000
@@ -1612,9 +1612,8 @@ int Gis_multi_polygon::area(double *ar, 
 int Gis_multi_polygon::centroid(String *result) const
 {
   uint32 n_polygons;
-  bool first_loop= 1;
   Gis_polygon p;
-  double UNINIT_VAR(res_area), UNINIT_VAR(res_cx), UNINIT_VAR(res_cy);
+  double res_area= 0.0, res_cx= 0.0, res_cy= 0.0;
   double cur_area, cur_cx, cur_cy;
   const char *data= m_data;
 
@@ -1631,20 +1630,13 @@ int Gis_multi_polygon::centroid(String *
 	p.centroid_xy(&cur_cx, &cur_cy))
       return 1;
 
-    if (!first_loop)
-    {
-      double sum_area= res_area + cur_area;
-      res_cx= (res_area * res_cx + cur_area * cur_cx) / sum_area;
-      res_cy= (res_area * res_cy + cur_area * cur_cy) / sum_area;
-    }
-    else
-    {
-      first_loop= 0;
-      res_area= cur_area;
-      res_cx= cur_cx;
-      res_cy= cur_cy;
-    }
+    res_area+= cur_area;
+    res_cx+= cur_area * cur_cx;
+    res_cy+= cur_area * cur_cy;
   }
+   
+  res_cx/= res_area;
+  res_cy/= res_area;
 
   return create_point(result, res_cx, res_cy);
 }


Attachment: [text/bzr-bundle] bzr/holyfoot@mysql.com-20100217101917-riitwbv3vv8cvhes.bundle
Thread
bzr commit into mysql-5.5-next-mr-bugfixing branch (holyfoot:2968)Bug#38959Alexey Botchkov18 Feb