From 4d3e30773fea57a8c827d1165087996e3f8ccb59 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 12 Apr 2019 12:12:14 -0700 Subject: [PATCH] Be more consistent about when longitudes beyond 180 are allowed --- CHANGELOG.md | 5 +++++ projection.cpp | 11 ++++++++--- tests/high-longitude/in.json | 1 + tests/high-longitude/out/-z1.json | 25 +++++++++++++++++++++++++ tile.cpp | 7 ++++--- version.hpp | 2 +- 6 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 tests/high-longitude/in.json create mode 100644 tests/high-longitude/out/-z1.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 108fa82..55b7d6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.34.2 + +* Be more consistent about when longitudes beyond 180 are allowed. + Now if the entire feature is beyond 180, it will still appear. + ## 1.34.1 * Don't run shell filters if the current zoom is below the minzoom diff --git a/projection.cpp b/projection.cpp index ac2dc8b..a29516a 100644 --- a/projection.cpp +++ b/projection.cpp @@ -22,12 +22,17 @@ void lonlat2tile(double lon, double lat, int zoom, long long *x, long long *y) { int lat_class = fpclassify(lat); int lon_class = fpclassify(lon); + bool bad_lon = false; if (lat_class == FP_INFINITE || lat_class == FP_NAN) { lat = 89.9; } if (lon_class == FP_INFINITE || lon_class == FP_NAN) { - lon = 360; + // Keep these far enough from the plane that they don't get + // moved back into it by 360-degree offsetting + + lon = 720; + bad_lon = true; } // Must limit latitude somewhere to prevent overflow. @@ -40,10 +45,10 @@ void lonlat2tile(double lon, double lat, int zoom, long long *x, long long *y) { lat = 89.9; } - if (lon < -360) { + if (lon < -360 && !bad_lon) { lon = -360; } - if (lon > 360) { + if (lon > 360 && !bad_lon) { lon = 360; } diff --git a/tests/high-longitude/in.json b/tests/high-longitude/in.json new file mode 100644 index 0000000..e984e38 --- /dev/null +++ b/tests/high-longitude/in.json @@ -0,0 +1 @@ +{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "hpa": 103200 }, "geometry": { "type": "MultiLineString", "coordinates": [ [ [254,35], [204,35], [204,30], [254,30], [254,35] ] ] } } ] } diff --git a/tests/high-longitude/out/-z1.json b/tests/high-longitude/out/-z1.json new file mode 100644 index 0000000..24be53b --- /dev/null +++ b/tests/high-longitude/out/-z1.json @@ -0,0 +1,25 @@ +{ "type": "FeatureCollection", "properties": { +"bounds": "-180.000000,30.000000,180.000000,35.000000", +"center": "-90.000000,35.000000,1", +"description": "tests/high-longitude/out/-z1.json.check.mbtiles", +"format": "pbf", +"generator_options": "./tippecanoe -q -a@ -f -o tests/high-longitude/out/-z1.json.check.mbtiles -z1 tests/high-longitude/in.json", +"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 1, \"fields\": {\"hpa\": \"Number\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 1,\"geometry\": \"LineString\",\"attributeCount\": 1,\"attributes\": [{\"attribute\": \"hpa\",\"count\": 1,\"type\": \"number\",\"values\": [103200],\"min\": 103200,\"max\": 103200}]}]}}", +"maxzoom": "1", +"minzoom": "0", +"name": "tests/high-longitude/out/-z1.json.check.mbtiles", +"type": "overlay", +"version": "2" +}, "features": [ +{ "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [ +{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [ +{ "type": "Feature", "properties": { "hpa": 103200 }, "geometry": { "type": "LineString", "coordinates": [ [ -106.083984, 35.029996 ], [ -156.005859, 35.029996 ], [ -156.005859, 30.069094 ], [ -106.083984, 30.069094 ], [ -106.083984, 35.029996 ] ] } } +] } +] } +, +{ "type": "FeatureCollection", "properties": { "zoom": 1, "x": 0, "y": 0 }, "features": [ +{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [ +{ "type": "Feature", "properties": { "hpa": 103200 }, "geometry": { "type": "LineString", "coordinates": [ [ -106.040039, 35.029996 ], [ -156.005859, 35.029996 ], [ -156.005859, 30.031055 ], [ -106.040039, 30.031055 ], [ -106.040039, 35.029996 ] ] } } +] } +] } +] } diff --git a/tile.cpp b/tile.cpp index 6e76c50..5d4d533 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1214,9 +1214,6 @@ struct write_tile_args { bool clip_to_tile(serial_feature &sf, int z, long long buffer) { int quick = quick_check(sf.bbox, z, buffer); - if (quick == 0) { - return true; - } if (z == 0) { if (sf.bbox[0] <= (1LL << 32) * buffer / 256 || sf.bbox[2] >= (1LL << 32) - ((1LL << 32) * buffer / 256)) { @@ -1244,6 +1241,10 @@ bool clip_to_tile(serial_feature &sf, int z, long long buffer) { } } + if (quick == 0) { + return true; + } + // Can't accept the quick check if guaranteeing no duplication, since the // overlap might have been in the buffer. if (quick != 1 || prevent[P_DUPLICATION]) { diff --git a/version.hpp b/version.hpp index 799d28a..67d52c1 100644 --- a/version.hpp +++ b/version.hpp @@ -1,6 +1,6 @@ #ifndef VERSION_HPP #define VERSION_HPP -#define VERSION "v1.34.1" +#define VERSION "v1.34.2" #endif