From 256139b385e775f2a6f41f5705bdfd7005902b93 Mon Sep 17 00:00:00 2001
From: Eric Fischer <enf@pobox.com>
Date: Tue, 8 Dec 2015 16:57:04 -0800
Subject: [PATCH] Clipping is faster with only one duplicate/shifted geometry
 copy

---
 tile.cc | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tile.cc b/tile.cc
index 6daa00a..b21e6b0 100644
--- a/tile.cc
+++ b/tile.cc
@@ -550,11 +550,17 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
 					// shifted by 360 degrees, and then make sure both copies get clipped down to size.
 
 					unsigned n = geom.size();
-					for (unsigned i = 0; i < n; i++) {
-						geom.push_back(draw(geom[i].op, geom[i].x - (1LL << 32), geom[i].y));
+
+					if (bbox[0] < 0) {
+						for (unsigned i = 0; i < n; i++) {
+							geom.push_back(draw(geom[i].op, geom[i].x + (1LL << 32), geom[i].y));
+						}
 					}
-					for (unsigned i = 0; i < n; i++) {
-						geom.push_back(draw(geom[i].op, geom[i].x + (1LL << 32), geom[i].y));
+
+					if (bbox[2] > 1LL << 32) {
+						for (unsigned i = 0; i < n; i++) {
+							geom.push_back(draw(geom[i].op, geom[i].x - (1LL << 32), geom[i].y));
+						}
 					}
 
 					bbox[0] = 0;