From 9a5bd5da55b2de0938af16f8ac8581e452420718 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Tue, 23 May 2023 11:06:41 -0700 Subject: [PATCH] Round instead of truncating when clipping lines --- geometry.cpp | 4 ++-- .../out/-z0_--clip-bounding-box_-110,27,-92,52.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/geometry.cpp b/geometry.cpp index 30d51ed8..ba33d110 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -794,8 +794,8 @@ drawvec clip_lines(drawvec &geom, long long minx, long long miny, long long maxx int c = clip(&x1, &y1, &x2, &y2, minx, miny, maxx, maxy); if (c > 1) { // clipped - out.push_back(draw(VT_MOVETO, x1, y1)); - out.push_back(draw(VT_LINETO, x2, y2)); + out.push_back(draw(VT_MOVETO, std::round(x1), std::round(y1))); + out.push_back(draw(VT_LINETO, std::round(x2), std::round(y2))); out.push_back(draw(VT_MOVETO, geom[i].x, geom[i].y)); } else if (c == 1) { // unchanged out.push_back(geom[i]); diff --git a/tests/ne_110m_admin_1_states_provinces_lines/out/-z0_--clip-bounding-box_-110,27,-92,52.json b/tests/ne_110m_admin_1_states_provinces_lines/out/-z0_--clip-bounding-box_-110,27,-92,52.json index 536b1287..53dbce12 100644 --- a/tests/ne_110m_admin_1_states_provinces_lines/out/-z0_--clip-bounding-box_-110,27,-92,52.json +++ b/tests/ne_110m_admin_1_states_provinces_lines/out/-z0_--clip-bounding-box_-110,27,-92,52.json @@ -14,8 +14,6 @@ }, "features": [ { "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [ { "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [ -{ "type": "Feature", "properties": { "scalerank": 2, "featurecla": "Admin-1 boundary", "adm0_a3": "USA", "adm0_name": "United States of America", "mapcolor9": 1, "mapcolor13": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -110.039062, 41.046217 ], [ -109.072266, 40.979898 ] ] } } -, { "type": "Feature", "properties": { "scalerank": 2, "featurecla": "Admin-1 boundary", "adm0_a3": "USA", "adm0_name": "United States of America", "mapcolor9": 1, "mapcolor13": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -110.039062, 45.026950 ], [ -104.062500, 45.026950 ] ] } } , { "type": "Feature", "properties": { "scalerank": 2, "featurecla": "Admin-1 boundary", "adm0_a3": "USA", "adm0_name": "United States of America", "mapcolor9": 1, "mapcolor13": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -104.062500, 45.951150 ], [ -104.062500, 48.980217 ] ] } } @@ -42,6 +40,8 @@ , { "type": "Feature", "properties": { "scalerank": 2, "featurecla": "Admin-1 boundary", "adm0_a3": "USA", "adm0_name": "United States of America", "mapcolor9": 1, "mapcolor13": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -92.021484, 43.516689 ], [ -96.416016, 43.516689 ] ] } } , +{ "type": "Feature", "properties": { "scalerank": 2, "featurecla": "Admin-1 boundary", "adm0_a3": "USA", "adm0_name": "United States of America", "mapcolor9": 1, "mapcolor13": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -110.039062, 40.979898 ], [ -109.072266, 40.979898 ] ] } } +, { "type": "Feature", "properties": { "scalerank": 2, "featurecla": "Admin-1 boundary", "adm0_a3": "USA", "adm0_name": "United States of America", "mapcolor9": 1, "mapcolor13": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -104.062500, 40.979898 ], [ -109.072266, 40.979898 ] ] } } , { "type": "Feature", "properties": { "scalerank": 2, "featurecla": "Admin-1 boundary", "adm0_a3": "USA", "adm0_name": "United States of America", "mapcolor9": 1, "mapcolor13": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ -110.039062, 37.020098 ], [ -109.072266, 37.020098 ] ] } }