From 9cccf2ba77b08b98a79df9ac2cc1863d5eb0439a Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 29 Nov 2012 11:41:24 +0100 Subject: [PATCH] Fix "whole" multi centroid computation (#1606) Still lacks a testcase --- include/mapnik/geom_util.hpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/include/mapnik/geom_util.hpp b/include/mapnik/geom_util.hpp index b3eeee7bd..c875d8b75 100644 --- a/include/mapnik/geom_util.hpp +++ b/include/mapnik/geom_util.hpp @@ -340,12 +340,10 @@ bool centroid_geoms(Iter start, Iter end, double & x, double & y) double start_x = x0; double start_y = y0; - bool empty = true; - double atmp = 0.0; double xtmp = 0.0; double ytmp = 0.0; - unsigned count = 1; + unsigned count = 0; while (start!=end) { @@ -353,7 +351,11 @@ bool centroid_geoms(Iter start, Iter end, double & x, double & y) path.rewind(0); unsigned command = path.vertex(&x0, &y0); if (command == SEG_END) continue; - empty = false; + + if ( ! count++ ) { + start_x = x0; + start_y = y0; + } while (SEG_END != (command = path.vertex(&x1, &y1))) { @@ -369,9 +371,10 @@ bool centroid_geoms(Iter start, Iter end, double & x, double & y) y0 = y1; ++count; } + } - if ( empty ) return false; + if (count == 0) return false; if (count <= 2) { x = (start_x + x0) * 0.5;