summaryrefslogtreecommitdiff
path: root/sql/spatial.cc
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@mysql.com>2010-02-17 14:19:17 +0400
committerAlexey Botchkov <holyfoot@mysql.com>2010-02-17 14:19:17 +0400
commitb0cdcdcbb9a6e9fccbe548fba3b34ff693ebb83f (patch)
treecfb7a5c42532ecc00f787d2210f18567410b0ea1 /sql/spatial.cc
parent4f1c72f3133dbb8ead341939892e6717ec51f55f (diff)
downloadmariadb-git-b0cdcdcbb9a6e9fccbe548fba3b34ff693ebb83f.tar.gz
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
Diffstat (limited to 'sql/spatial.cc')
-rw-r--r--sql/spatial.cc22
1 files changed, 7 insertions, 15 deletions
diff --git a/sql/spatial.cc b/sql/spatial.cc
index 671b8544b8a..9a31b099e92 100644
--- a/sql/spatial.cc
+++ b/sql/spatial.cc
@@ -1612,9 +1612,8 @@ int Gis_multi_polygon::area(double *ar, const char **end_of_data) const
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 *result) const
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);
}