From 1baa5e0e300f6a1c1df4f8571aec13a90f2582b6 Mon Sep 17 00:00:00 2001 From: Ray <7869818+rayrrr@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:51:41 -0400 Subject: [PATCH] restore floats (as per RFC 7946 Section 3.1.1) --- geojson/utils.py | 6 +++--- tests/test_utils.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/geojson/utils.py b/geojson/utils.py index c80f893..61c55d6 100644 --- a/geojson/utils.py +++ b/geojson/utils.py @@ -129,7 +129,7 @@ def map_geometries(func, obj): def generate_random(featureType, numberVertices=3, - boundingBox=[-180, -90, 180, 90]): + boundingBox=[-180.0, -90.0, 180.0, 90.0]): """ Generates random geojson features depending on the parameters passed through. @@ -190,8 +190,8 @@ def create_poly(): r_i = clip(random.gauss(ave_radius, spikeyness), 0, 2 * ave_radius) x = ctr_x + r_i * math.cos(angle) y = ctr_y + r_i * math.sin(angle) - x = (x + 180) * (abs(lon_min - lon_max) / 360) + lon_min - y = (y + 90) * (abs(lat_min - lat_max) / 180) + lat_min + x = (x + 180.0) * (abs(lon_min - lon_max) / 360.0) + lon_min + y = (y + 90.0) * (abs(lat_min - lat_max) / 180.0) + lat_min x = clip(x, lon_min, lon_max) y = clip(y, lat_min, lat_max) points.append((x, y)) diff --git a/tests/test_utils.py b/tests/test_utils.py index 58d9f04..5339cb8 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -10,12 +10,12 @@ def generate_bbox(): - min_lat = random.random() * 180 - 90 - max_lat = random.random() * 180 - 90 + min_lat = random.random() * 180.0 - 90.0 + max_lat = random.random() * 180.0 - 90.0 if min_lat > max_lat: min_lat, max_lat = max_lat, min_lat - min_lon = random.random() * 360 - 180 - max_lon = random.random() * 360 - 180 + min_lon = random.random() * 360.0 - 180.0 + max_lon = random.random() * 360.0 - 180.0 if min_lon > max_lon: min_lon, max_lon = max_lon, min_lon return [min_lon, min_lat, max_lon, max_lat] @@ -46,7 +46,7 @@ def check_point_bbox(point, bbox): class TestGenerateRandom(unittest.TestCase): def test_simple_polygon(self): for _ in range(5000): - bbox = [-180, -90, 180, 90] + bbox = [-180.0, -90.0, 180.0, 90.0] result = generate_random('Polygon') self.assertIsInstance(result, geojson.geometry.Polygon) self.assertTrue(geojson.geometry.check_polygon(result))