@@ -33,10 +33,10 @@ pair<int,int> TileBbox::scaleLatpLon(double latp, double lon) const {
3333
3434// Scaling with naive self-intersection check - if we've added the new point
3535// within the last 5 points, then backtrack to the last time we added it
36- std::vector<Point> TileBbox::scaleRing (Ring const &src) const {
37- std::vector<Point> points;
36+ void TileBbox::scaleRing (Ring &points, Ring const &src) const {
37+ points. clear () ;
3838 points.reserve (src.size ());
39- for (auto &i: src) {
39+ for (auto const &i: src) {
4040 auto scaled = scaleLatpLon (i.y (), i.x ()); // -> .first is x, .second is y
4141 bool found = false ;
4242 for (size_t j=1 ; j<5 ; j++) {
@@ -48,36 +48,46 @@ std::vector<Point> TileBbox::scaleRing(Ring const &src) const {
4848 }
4949 if (!found) points.push_back (Point (scaled.first ,scaled.second ));
5050 }
51+ }
52+
53+ Ring TileBbox::scaleRing (Ring const &src) const {
54+ Ring points;
55+ scaleRing (points, src);
5156 return points;
5257}
5358
54- MultiPolygon TileBbox::scaleGeometry (MultiPolygon const &src) const {
55- MultiPolygon dst;
56- for (auto poly: src) {
57- Polygon p;
59+ void TileBbox::scaleGeometry (MultiPolygon &dst, MultiPolygon const &src) const {
60+ if (dst.size () < src.size ())
61+ dst.resize (src.size ());
62+
63+ size_t polygonCount = 0 ;
64+ for (auto const &poly: src) {
65+ Polygon &p = dst[polygonCount];
5866
5967 // Copy the outer ring
60- std::vector<Point> points = scaleRing (poly.outer ());
61- if (points.size ()<4 ) continue ;
62- Ring outer;
63- geom::append (outer,points);
64- geom::append (p,outer);
68+ scaleRing (p.outer (), poly.outer ());
69+ if (p.outer ().size ()<4 )
70+ continue ;
6571
6672 // Copy the inner rings
67- int num_rings = 0 ;
68- for (auto &r: poly.inners ()) {
69- points = scaleRing (r);
70- if (points.size ()<4 ) continue ;
71- Ring inner;
72- geom::append (inner,points);
73- num_rings++;
74- geom::interior_rings (p).resize (num_rings);
75- geom::append (p, inner, num_rings-1 );
73+ if (p.inners ().size () < poly.inners ().size ())
74+ p.inners ().resize (poly.inners ().size ());
75+ size_t innerCount = 0 ;
76+ for (auto const &r: poly.inners ()) {
77+ Ring &points = p.inners ()[innerCount];
78+ scaleRing (points, r);
79+ if (points.size ()>=4 )
80+ innerCount++;
7681 }
77-
78- // Add to multipolygon
79- dst.push_back (p);
82+ p.inners ().resize (innerCount);
83+ polygonCount++;
8084 }
85+ dst.resize (polygonCount);
86+ }
87+
88+ MultiPolygon TileBbox::scaleGeometry (MultiPolygon const &src) const {
89+ MultiPolygon dst;
90+ scaleGeometry (dst, src);
8191 return dst;
8292}
8393
0 commit comments