fix centroid error for two points and merge with dev.

This commit is contained in:
tamasmeszaros 2018-08-27 16:20:13 +02:00
commit 1c4574d42e
39 changed files with 849 additions and 132 deletions

View file

@ -357,10 +357,20 @@ inline ExPolygons unify(const ExPolygons& shapes) {
}
inline Point centroid(Points& pp) {
Polygon p;
p.points.swap(pp);
Point c = p.centroid();
pp.swap(p.points);
Point c;
switch(pp.size()) {
case 0: break;
case 1: c = pp.front(); break;
case 2: c = (pp[0] + pp[1]) / 2; break;
default: {
Polygon p;
p.points.swap(pp);
c = p.centroid();
pp.swap(p.points);
break;
}
}
return c;
}