diff --git a/.gitattributes b/.gitattributes index ace46c26063caf7dca8b5a393e7976701ea96f03..eaaea84d7813362508676e74d6d6cd0e02c6fd19 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1800,3 +1800,4 @@ vllm/lib/python3.10/site-packages/cupy/_core/_fusion_trace.cpython-310-x86_64-li parrot/lib/python3.10/site-packages/scipy/optimize/_lsq/givens_elimination.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text vllm/lib/python3.10/site-packages/shapely/_geos.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text vllm/lib/python3.10/site-packages/shapely/lib.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text +vllm/lib/python3.10/site-packages/cupyx/cudnn.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text diff --git a/vllm/lib/python3.10/site-packages/cupyx/cudnn.cpython-310-x86_64-linux-gnu.so b/vllm/lib/python3.10/site-packages/cupyx/cudnn.cpython-310-x86_64-linux-gnu.so new file mode 100644 index 0000000000000000000000000000000000000000..5698963dfe0e95e26e57cc62758b97921a82c555 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupyx/cudnn.cpython-310-x86_64-linux-gnu.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fdc9b696bd071426ccbb30e5a2c43f03afd0c5ff54a08b8f39bd245e140a263f +size 4677920 diff --git a/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.10.0_pickle_py33_np18.pkl b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.10.0_pickle_py33_np18.pkl new file mode 100644 index 0000000000000000000000000000000000000000..d6cf697b1c1c752d4d8a78d702a70042ad047ce9 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.10.0_pickle_py33_np18.pkl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e064c2eecfdc58d552844467da7bd56eca596098322bfd266a7e1312abdd5735 +size 1068 diff --git a/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.10.0_pickle_py33_np18.pkl.bz2 b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.10.0_pickle_py33_np18.pkl.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..317981559c4a9987aa099efeb68e4359c08d71ec --- /dev/null +++ b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.10.0_pickle_py33_np18.pkl.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e86d6f6ecfe2626cf691827ac38a81d64ec3ebb527c5432eb344b8496781b45a +size 1000 diff --git a/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.2_pickle_py27_np16.pkl_02.npy b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.2_pickle_py27_np16.pkl_02.npy new file mode 100644 index 0000000000000000000000000000000000000000..f00f08fbeeda280fa3ce00069c313c5412a33eca --- /dev/null +++ b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.2_pickle_py27_np16.pkl_02.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c1cf36cb781fbcc21b953bb0a0b45df092da0eae0e765882e5963ccd70105b1 +size 120 diff --git a/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.2_pickle_py27_np16.pkl_04.npy b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.2_pickle_py27_np16.pkl_04.npy new file mode 100644 index 0000000000000000000000000000000000000000..e9b5e77c73268dfff541b576126f06fc6fed3d59 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.2_pickle_py27_np16.pkl_04.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ecbe244294ba93e08479b16c1b9a9411e3569ff660ed0459dca1d241381df05 +size 104 diff --git a/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.2_pickle_py34_np19.pkl_01.npy b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.2_pickle_py34_np19.pkl_01.npy new file mode 100644 index 0000000000000000000000000000000000000000..15574a4193ad4ad724b2b8053c701a82efa78fd5 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.2_pickle_py34_np19.pkl_01.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0efbd7d9ce7eec3a6e0a0db41e795e0396cca3d6b037dad6c61b464843d28809 +size 120 diff --git a/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.4.dev0_compressed_cache_size_pickle_py35_np19.gz b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.4.dev0_compressed_cache_size_pickle_py35_np19.gz new file mode 100644 index 0000000000000000000000000000000000000000..e3125fe0fd4709dbd0067e67a06a3f24073934ad --- /dev/null +++ b/vllm/lib/python3.10/site-packages/joblib/test/data/joblib_0.9.4.dev0_compressed_cache_size_pickle_py35_np19.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f2361f589b31d2863627edcb96612280ae5c0a59c9496d89dab7de493670f93b +size 802 diff --git a/vllm/lib/python3.10/site-packages/shapely/geometry/__pycache__/__init__.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/geometry/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..684c32cf533647876d71231513e6b1de1c67f364 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/geometry/__pycache__/__init__.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__init__.py b/vllm/lib/python3.10/site-packages/shapely/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/__init__.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3ef1f8b515fd74f328e8a0562c883cd0963d3095 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/__init__.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/common.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/common.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f0e99c37452c7529f98712b19840c83c0568f291 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/common.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_constructive.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_constructive.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3d094ab2481c7df68018465044a53f2ed4ca84c1 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_constructive.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_coordinates.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_coordinates.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..51b1f8bba050d3a8f92d9a2992dea94f6145464b Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_coordinates.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_creation.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_creation.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ccdaa76b7b0e837bb32cecb012a69b0199dd52c7 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_creation.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_creation_indices.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_creation_indices.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b4ba3b489e15c04b9dd14ba7dc548c47026f2bdc Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_creation_indices.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_geometry.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_geometry.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..df4fe1dccd4ea79c3a78d0c3423d61fc905c206c Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_geometry.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_io.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_io.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d9ce29e551b8b5d7cb9bd76c3a171870b3c9c0d3 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_io.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_linear.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_linear.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..826a8846b755cc67c359bb235adcc7e9679913d8 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_linear.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_measurement.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_measurement.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c5676e11eb2741dda01721e08e73171b9b93a36b Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_measurement.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_misc.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_misc.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d42fb56e39c55c8ddca707b8d082826dfe37cde3 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_misc.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_plotting.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_plotting.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c76e2fe8421f35551161c4579f00bf818a716abc Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_plotting.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_predicates.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_predicates.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4876ea919415a111cb1bd821b610ff38e432a573 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_predicates.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_ragged_array.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_ragged_array.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c9e77c6d8e8d318da0f5e9609054f5991fe4883b Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_ragged_array.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_set_operations.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_set_operations.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5a2ac9625496d226d9aeab7373fc2c727f8118e3 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_set_operations.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_strtree.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_strtree.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5d01d0d6b23ce951d92da8d934f05445cdf172fe Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_strtree.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_testing.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_testing.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..83de46ff1daf513de7c9c379c2a7f76580f58245 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/__pycache__/test_testing.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/common.py b/vllm/lib/python3.10/site-packages/shapely/tests/common.py new file mode 100644 index 0000000000000000000000000000000000000000..3265a35c338bbabf9ef87ee5633e9b2762b4fbce --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/common.py @@ -0,0 +1,125 @@ +from contextlib import contextmanager + +import numpy as np +import pytest + +import shapely + +shapely20_todo = pytest.mark.xfail( + strict=False, reason="Not yet implemented for Shapely 2.0" +) + +point_polygon_testdata = ( + shapely.points(np.arange(6), np.arange(6)), + shapely.box(2, 2, 4, 4), +) +point = shapely.Point(2, 3) +line_string = shapely.LineString([(0, 0), (1, 0), (1, 1)]) +linear_ring = shapely.LinearRing([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]) +polygon = shapely.Polygon([(0, 0), (2, 0), (2, 2), (0, 2), (0, 0)]) +multi_point = shapely.MultiPoint([(0, 0), (1, 2)]) +multi_line_string = shapely.MultiLineString([[(0, 0), (1, 2)]]) +multi_polygon = shapely.multipolygons( + [ + [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)], + [(2.1, 2.1), (2.2, 2.1), (2.2, 2.2), (2.1, 2.2), (2.1, 2.1)], + ] +) +geometry_collection = shapely.GeometryCollection( + [shapely.Point(51, -1), shapely.LineString([(52, -1), (49, 2)])] +) +point_z = shapely.Point(2, 3, 4) +line_string_z = shapely.LineString([(0, 0, 4), (1, 0, 4), (1, 1, 4)]) +polygon_z = shapely.Polygon([(0, 0, 4), (2, 0, 4), (2, 2, 4), (0, 2, 4), (0, 0, 4)]) +geometry_collection_z = shapely.GeometryCollection([point_z, line_string_z]) +polygon_with_hole = shapely.Polygon( + [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)], + holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]], +) +empty_point = shapely.from_wkt("POINT EMPTY") +empty_point_z = shapely.from_wkt("POINT Z EMPTY") +empty_line_string = shapely.from_wkt("LINESTRING EMPTY") +empty_line_string_z = shapely.from_wkt("LINESTRING Z EMPTY") +empty_polygon = shapely.from_wkt("POLYGON EMPTY") +empty = shapely.from_wkt("GEOMETRYCOLLECTION EMPTY") +multi_point_z = shapely.MultiPoint([(0, 0, 4), (1, 2, 4)]) +multi_line_string_z = shapely.MultiLineString([[(0, 0, 4), (1, 2, 4)]]) +multi_polygon_z = shapely.multipolygons( + [ + [(0, 0, 4), (1, 0, 4), (1, 1, 4), (0, 1, 4), (0, 0, 4)], + [(2.1, 2.1, 4), (2.2, 2.1, 4), (2.2, 2.2, 4), (2.1, 2.2, 4), (2.1, 2.1, 4)], + ] +) +polygon_with_hole_z = shapely.Polygon( + [(0, 0, 4), (0, 10, 4), (10, 10, 4), (10, 0, 4), (0, 0, 4)], + holes=[[(2, 2, 4), (2, 4, 4), (4, 4, 4), (4, 2, 4), (2, 2, 4)]], +) + +all_types = ( + point, + line_string, + linear_ring, + polygon, + multi_point, + multi_line_string, + multi_polygon, + geometry_collection, + empty, +) + +all_types_z = ( + point_z, + line_string_z, + polygon_z, + multi_point_z, + multi_line_string_z, + multi_polygon_z, + polygon_with_hole_z, + geometry_collection_z, + empty_point_z, + empty_line_string_z, +) + + +@contextmanager +def ignore_invalid(condition=True): + if condition: + with np.errstate(invalid="ignore"): + yield + else: + yield + + +with ignore_invalid(): + line_string_nan = shapely.LineString([(np.nan, np.nan), (np.nan, np.nan)]) + + +class ArrayLike: + """ + Simple numpy Array like class that implements the + ufunc protocol. + """ + + def __init__(self, array): + self._array = np.asarray(array) + + def __len__(self): + return len(self._array) + + def __getitem(self, key): + return self._array[key] + + def __iter__(self): + return self._array.__iter__() + + def __array__(self): + return np.asarray(self._array) + + def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): + if method == "__call__": + inputs = [ + arg._array if isinstance(arg, self.__class__) else arg for arg in inputs + ] + return self.__class__(ufunc(*inputs, **kwargs)) + else: + return NotImplemented diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/__init__.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..84a99686a836eaa80d5fc19a4121a8a4952fad8c Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/__init__.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_collection.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_collection.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e531ecdcea5cd760b6b39a2e6c5814f89fce9b36 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_collection.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_coords.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_coords.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..58194c9d52e92d63fef3e7b82d7c044cdf7f1eb6 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_coords.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_decimal.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_decimal.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b0e4cf859880a54475938c056365c85337a22265 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_decimal.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_emptiness.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_emptiness.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..118314debfacdc70d6533442b01e3c3fad8320cd Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_emptiness.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_equality.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_equality.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..84d0abda2093b9b5ae5050a065d550ca89064daa Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_equality.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_format.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_format.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..173b9f9e01de6788c8ba59e22fa3dbbcb04d4e20 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_format.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_geometry_base.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_geometry_base.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..be89fff5ab019fabd90353de78ecdc8888bf1b69 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_geometry_base.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_hash.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_hash.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..054cf70ad50df29894bc82e37e4c872943a9e76d Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_hash.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_linestring.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_linestring.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a6b6126ee71c092bf8b36980cfe195b79196577d Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_linestring.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multi.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multi.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c4dea54dc95ef3909134e06760c0adafa2781da4 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multi.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multilinestring.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multilinestring.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fd27928d5bbf4e468ee0fcd113b7f4c4368f6f0c Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multilinestring.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multipoint.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multipoint.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..87931ba035d90448f2f6d9aae86ae637ef834f88 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multipoint.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multipolygon.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multipolygon.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6739c471363ec541f78c8ac04f28988e4909edb0 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_multipolygon.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_point.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_point.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..273000393c90075fd44cdb7db213d8302863e989 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_point.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_polygon.cpython-310.pyc b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_polygon.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cffa70714992dd9dd82702f0520f2b273801c24c Binary files /dev/null and b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/__pycache__/test_polygon.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_collection.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_collection.py new file mode 100644 index 0000000000000000000000000000000000000000..606a6676464a94024cb4b1d6f6d776ac53b317cc --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_collection.py @@ -0,0 +1,82 @@ +import numpy as np +import pytest + +from shapely import GeometryCollection, LineString, Point, wkt +from shapely.geometry import shape + + +@pytest.fixture() +def geometrycollection_geojson(): + return { + "type": "GeometryCollection", + "geometries": [ + {"type": "Point", "coordinates": (0, 3, 0)}, + {"type": "LineString", "coordinates": ((2, 0), (1, 0))}, + ], + } + + +@pytest.mark.parametrize( + "geom", + [ + GeometryCollection(), + shape({"type": "GeometryCollection", "geometries": []}), + wkt.loads("GEOMETRYCOLLECTION EMPTY"), + ], +) +def test_empty(geom): + assert geom.geom_type == "GeometryCollection" + assert geom.is_empty + assert len(geom.geoms) == 0 + assert list(geom.geoms) == [] + + +def test_empty_subgeoms(): + geom = GeometryCollection([Point(), LineString()]) + assert geom.geom_type == "GeometryCollection" + assert geom.is_empty + assert len(geom.geoms) == 2 + assert list(geom.geoms) == [Point(), LineString()] + + +def test_child_with_deleted_parent(): + # test that we can remove a collection while keeping + # children around + a = LineString([(0, 0), (1, 1), (1, 2), (2, 2)]) + b = LineString([(0, 0), (1, 1), (2, 1), (2, 2)]) + collection = a.intersection(b) + + child = collection.geoms[0] + # delete parent of child + del collection + + # access geometry, this should not seg fault as 1.2.15 did + assert child.wkt is not None + + +def test_from_geojson(geometrycollection_geojson): + geom = shape(geometrycollection_geojson) + assert geom.geom_type == "GeometryCollection" + assert len(geom.geoms) == 2 + + geom_types = [g.geom_type for g in geom.geoms] + assert "Point" in geom_types + assert "LineString" in geom_types + + +def test_geointerface(geometrycollection_geojson): + geom = shape(geometrycollection_geojson) + assert geom.__geo_interface__ == geometrycollection_geojson + + +def test_len_raises(geometrycollection_geojson): + geom = shape(geometrycollection_geojson) + with pytest.raises(TypeError): + len(geom) + + +def test_numpy_object_array(): + geom = GeometryCollection([LineString([(0, 0), (1, 1)])]) + ar = np.empty(1, object) + ar[:] = [geom] + assert ar[0] == geom diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_coords.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_coords.py new file mode 100644 index 0000000000000000000000000000000000000000..e13416033fc714690d225e36ba4afafb3fa6ef27 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_coords.py @@ -0,0 +1,102 @@ +import numpy as np +import pytest + +from shapely import LineString +from shapely.tests.common import line_string, line_string_z, point, point_z + + +class TestCoords: + """ + Shapely assumes contiguous C-order float64 data for internal ops. + Data should be converted to contiguous float64 if numpy exists. + c9a0707 broke this a little bit. + """ + + def test_data_promotion(self): + coords = np.array([[12, 34], [56, 78]], dtype=np.float32) + processed_coords = np.array(LineString(coords).coords) + + assert coords.tolist() == processed_coords.tolist() + + def test_data_destriding(self): + coords = np.array([[12, 34], [56, 78]], dtype=np.float32) + + # Easy way to introduce striding: reverse list order + processed_coords = np.array(LineString(coords[::-1]).coords) + + assert coords[::-1].tolist() == processed_coords.tolist() + + +class TestCoordsGetItem: + def test_index_2d_coords(self): + c = [(float(x), float(-x)) for x in range(4)] + g = LineString(c) + for i in range(-4, 4): + assert g.coords[i] == c[i] + with pytest.raises(IndexError): + g.coords[4] + with pytest.raises(IndexError): + g.coords[-5] + + def test_index_3d_coords(self): + c = [(float(x), float(-x), float(x * 2)) for x in range(4)] + g = LineString(c) + for i in range(-4, 4): + assert g.coords[i] == c[i] + with pytest.raises(IndexError): + g.coords[4] + with pytest.raises(IndexError): + g.coords[-5] + + def test_index_coords_misc(self): + g = LineString() # empty + with pytest.raises(IndexError): + g.coords[0] + with pytest.raises(TypeError): + g.coords[0.0] + + def test_slice_2d_coords(self): + c = [(float(x), float(-x)) for x in range(4)] + g = LineString(c) + assert g.coords[1:] == c[1:] + assert g.coords[:-1] == c[:-1] + assert g.coords[::-1] == c[::-1] + assert g.coords[::2] == c[::2] + assert g.coords[:4] == c[:4] + assert g.coords[4:] == c[4:] == [] + + def test_slice_3d_coords(self): + c = [(float(x), float(-x), float(x * 2)) for x in range(4)] + g = LineString(c) + assert g.coords[1:] == c[1:] + assert g.coords[:-1] == c[:-1] + assert g.coords[::-1] == c[::-1] + assert g.coords[::2] == c[::2] + assert g.coords[:4] == c[:4] + assert g.coords[4:] == c[4:] == [] + + +class TestXY: + """New geometry/coordseq method 'xy' makes numpy interop easier""" + + def test_arrays(self): + x, y = LineString([(0, 0), (1, 1)]).xy + assert len(x) == 2 + assert list(x) == [0.0, 1.0] + assert len(y) == 2 + assert list(y) == [0.0, 1.0] + + +@pytest.mark.parametrize("geom", [point, point_z, line_string, line_string_z]) +def test_coords_array_copy(geom): + """Test CoordinateSequence.__array__ method.""" + coord_seq = geom.coords + assert np.array(coord_seq) is not np.array(coord_seq) + assert np.array(coord_seq, copy=True) is not np.array(coord_seq, copy=True) + + # Behaviour of copy=False is different between NumPy 1.x and 2.x + if int(np.version.short_version.split(".", 1)[0]) >= 2: + with pytest.raises(ValueError, match="A copy is always created"): + np.array(coord_seq, copy=False) + else: + assert np.array(coord_seq, copy=False) is np.array(coord_seq, copy=False) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_decimal.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_decimal.py new file mode 100644 index 0000000000000000000000000000000000000000..7c4317bea4be4074b4416c93f556fa1230cbecc4 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_decimal.py @@ -0,0 +1,117 @@ +from decimal import Decimal + +import pytest + +from shapely import ( + GeometryCollection, + LinearRing, + LineString, + MultiLineString, + MultiPoint, + MultiPolygon, + Point, + Polygon, +) + +items2d = [ + [(0.0, 0.0), (70.0, 120.0), (140.0, 0.0), (0.0, 0.0)], + [(60.0, 80.0), (80.0, 80.0), (70.0, 60.0), (60.0, 80.0)], +] + +items2d_mixed = [ + [ + (Decimal(0.0), Decimal(0.0)), + (Decimal(70.0), 120.0), + (140.0, Decimal(0.0)), + (0.0, 0.0), + ], + [ + (Decimal(60.0), Decimal(80.0)), + (Decimal(80.0), 80.0), + (70.0, Decimal(60.0)), + (60.0, 80.0), + ], +] + +items2d_decimal = [ + [ + (Decimal(0.0), Decimal(0.0)), + (Decimal(70.0), Decimal(120.0)), + (Decimal(140.0), Decimal(0.0)), + (Decimal(0.0), Decimal(0.0)), + ], + [ + (Decimal(60.0), Decimal(80.0)), + (Decimal(80.0), Decimal(80.0)), + (Decimal(70.0), Decimal(60.0)), + (Decimal(60.0), Decimal(80.0)), + ], +] + +items3d = [ + [(0.0, 0.0, 1), (70.0, 120.0, 2), (140.0, 0.0, 3), (0.0, 0.0, 1)], + [(60.0, 80.0, 1), (80.0, 80.0, 2), (70.0, 60.0, 3), (60.0, 80.0, 1)], +] + +items3d_mixed = [ + [ + (Decimal(0.0), Decimal(0.0), Decimal(1)), + (Decimal(70.0), 120.0, Decimal(2)), + (140.0, Decimal(0.0), 3), + (0.0, 0.0, 1), + ], + [ + (Decimal(60.0), Decimal(80.0), Decimal(1)), + (Decimal(80.0), 80.0, 2), + (70.0, Decimal(60.0), Decimal(3)), + (60.0, 80.0, 1), + ], +] + +items3d_decimal = [ + [ + (Decimal(0.0), Decimal(0.0), Decimal(1)), + (Decimal(70.0), Decimal(120.0), Decimal(2)), + (Decimal(140.0), Decimal(0.0), Decimal(3)), + (Decimal(0.0), Decimal(0.0), Decimal(1)), + ], + [ + (Decimal(60.0), Decimal(80.0), Decimal(1)), + (Decimal(80.0), Decimal(80.0), Decimal(2)), + (Decimal(70.0), Decimal(60.0), Decimal(3)), + (Decimal(60.0), Decimal(80.0), Decimal(1)), + ], +] + +all_geoms = [ + [ + Point(items[0][0]), + Point(*items[0][0]), + MultiPoint(items[0]), + LinearRing(items[0]), + LineString(items[0]), + MultiLineString(items), + Polygon(items[0]), + MultiPolygon( + [ + Polygon(items[1]), + Polygon(items[0], holes=items[1:]), + ] + ), + GeometryCollection([Point(items[0][0]), Polygon(items[0])]), + ] + for items in [ + items2d, + items2d_mixed, + items2d_decimal, + items3d, + items3d_mixed, + items3d_decimal, + ] +] + + +@pytest.mark.parametrize("geoms", list(zip(*all_geoms))) +def test_decimal(geoms): + assert geoms[0] == geoms[1] == geoms[2] + assert geoms[3] == geoms[4] == geoms[5] diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_emptiness.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_emptiness.py new file mode 100644 index 0000000000000000000000000000000000000000..005b2b8ecb88f5be4c72f63ce5737bc8a9bd9a68 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_emptiness.py @@ -0,0 +1,98 @@ +import math + +import numpy as np +import pytest + +from shapely import ( + GeometryCollection, + LinearRing, + LineString, + MultiLineString, + MultiPoint, + MultiPolygon, + Point, + Polygon, +) +from shapely.geometry import mapping, shape +from shapely.geometry.base import BaseGeometry, EmptyGeometry + + +def empty_generator(): + return iter([]) + + +class TestEmptiness: + def test_empty_class(self): + with pytest.warns(FutureWarning): + g = EmptyGeometry() + assert g.is_empty + + def test_empty_base(self): + with pytest.warns(FutureWarning): + g = BaseGeometry() + assert g.is_empty + + def test_empty_point(self): + assert Point().is_empty + + def test_empty_multipoint(self): + assert MultiPoint().is_empty + + def test_empty_geometry_collection(self): + assert GeometryCollection().is_empty + + def test_empty_linestring(self): + assert LineString().is_empty + assert LineString(None).is_empty + assert LineString([]).is_empty + assert LineString(empty_generator()).is_empty + + def test_empty_multilinestring(self): + assert MultiLineString([]).is_empty + + def test_empty_polygon(self): + assert Polygon().is_empty + assert Polygon(None).is_empty + assert Polygon([]).is_empty + assert Polygon(empty_generator()).is_empty + + def test_empty_multipolygon(self): + assert MultiPolygon([]).is_empty + + def test_empty_linear_ring(self): + assert LinearRing().is_empty + assert LinearRing(None).is_empty + assert LinearRing([]).is_empty + assert LinearRing(empty_generator()).is_empty + + +def test_numpy_object_array(): + geoms = [Point(), GeometryCollection()] + arr = np.empty(2, object) + arr[:] = geoms + + +def test_shape_empty(): + empty_mp = MultiPolygon() + empty_json = mapping(empty_mp) + empty_shape = shape(empty_json) + assert empty_shape.is_empty + + +@pytest.mark.parametrize( + "geom", + [ + Point(), + LineString(), + Polygon(), + MultiPoint(), + MultiLineString(), + MultiPolygon(), + GeometryCollection(), + LinearRing(), + ], +) +def test_empty_geometry_bounds(geom): + """The bounds of an empty geometry is a tuple of NaNs""" + assert len(geom.bounds) == 4 + assert all(math.isnan(v) for v in geom.bounds) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_equality.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_equality.py new file mode 100644 index 0000000000000000000000000000000000000000..c66a2e3793946fad590c63699bd67d1d93648d7c --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_equality.py @@ -0,0 +1,237 @@ +import numpy as np +import pytest + +import shapely +from shapely import LinearRing, LineString, MultiLineString, Point, Polygon +from shapely.tests.common import all_types, all_types_z, ignore_invalid + + +@pytest.mark.parametrize("geom", all_types + all_types_z) +def test_equality(geom): + assert geom == geom + transformed = shapely.transform(geom, lambda x: x, include_z=True) + assert geom == transformed + assert not (geom != transformed) + + +@pytest.mark.parametrize( + "left, right", + [ + # (slightly) different coordinate values + (LineString([(0, 0), (1, 1)]), LineString([(0, 0), (1, 2)])), + (LineString([(0, 0), (1, 1)]), LineString([(0, 0), (1, 1 + 1e-12)])), + # different coordinate order + (LineString([(0, 0), (1, 1)]), LineString([(1, 1), (0, 0)])), + # different number of coordinates (but spatially equal) + (LineString([(0, 0), (1, 1)]), LineString([(0, 0), (1, 1), (1, 1)])), + (LineString([(0, 0), (1, 1)]), LineString([(0, 0), (0.5, 0.5), (1, 1)])), + # different order of sub-geometries + ( + MultiLineString([[(1, 1), (2, 2)], [(2, 2), (3, 3)]]), + MultiLineString([[(2, 2), (3, 3)], [(1, 1), (2, 2)]]), + ), + ], +) +def test_equality_false(left, right): + assert left != right + + +with ignore_invalid(): + cases1 = [ + (LineString([(0, 1), (2, np.nan)]), LineString([(0, 1), (2, np.nan)])), + ( + LineString([(0, 1), (np.nan, np.nan)]), + LineString([(0, 1), (np.nan, np.nan)]), + ), + (LineString([(np.nan, 1), (2, 3)]), LineString([(np.nan, 1), (2, 3)])), + (LineString([(0, np.nan), (2, 3)]), LineString([(0, np.nan), (2, 3)])), + ( + LineString([(np.nan, np.nan), (np.nan, np.nan)]), + LineString([(np.nan, np.nan), (np.nan, np.nan)]), + ), + # NaN as explicit Z coordinate + # TODO: if first z is NaN -> considered as 2D -> tested below explicitly + # ( + # LineString([(0, 1, np.nan), (2, 3, np.nan)]), + # LineString([(0, 1, np.nan), (2, 3, np.nan)]), + # ), + ( + LineString([(0, 1, 2), (2, 3, np.nan)]), + LineString([(0, 1, 2), (2, 3, np.nan)]), + ), + # ( + # LineString([(0, 1, np.nan), (2, 3, 4)]), + # LineString([(0, 1, np.nan), (2, 3, 4)]), + # ), + ] + + +@pytest.mark.parametrize("left, right", cases1) +def test_equality_with_nan(left, right): + # TODO currently those evaluate as not equal, but we are considering to change this + # assert left == right + assert not (left == right) + # assert not (left != right) + assert left != right + + +with ignore_invalid(): + cases2 = [ + ( + LineString([(0, 1, np.nan), (2, 3, np.nan)]), + LineString([(0, 1, np.nan), (2, 3, np.nan)]), + ), + ( + LineString([(0, 1, np.nan), (2, 3, 4)]), + LineString([(0, 1, np.nan), (2, 3, 4)]), + ), + ] + + +@pytest.mark.parametrize("left, right", cases2) +def test_equality_with_nan_z(left, right): + # TODO: those are currently considered equal because z dimension is ignored + if shapely.geos_version < (3, 12, 0): + assert left == right + assert not (left != right) + else: + # on GEOS main z dimension is not ignored -> NaNs cause inequality + assert left != right + + +with ignore_invalid(): + cases3 = [ + (LineString([(0, np.nan), (2, 3)]), LineString([(0, 1), (2, 3)])), + (LineString([(0, 1), (2, np.nan)]), LineString([(0, 1), (2, 3)])), + (LineString([(0, 1, np.nan), (2, 3, 4)]), LineString([(0, 1, 2), (2, 3, 4)])), + (LineString([(0, 1, 2), (2, 3, np.nan)]), LineString([(0, 1, 2), (2, 3, 4)])), + ] + + +@pytest.mark.parametrize("left, right", cases3) +def test_equality_with_nan_false(left, right): + assert left != right + + +def test_equality_with_nan_z_false(): + with ignore_invalid(): + left = LineString([(0, 1, np.nan), (2, 3, np.nan)]) + right = LineString([(0, 1, np.nan), (2, 3, 4)]) + + if shapely.geos_version < (3, 10, 0): + # GEOS <= 3.9 fill the NaN with 0, so the z dimension is different + # assert left != right + # however, has_z still returns False, so z dimension is ignored in .coords + assert left == right + elif shapely.geos_version < (3, 12, 0): + # GEOS 3.10-3.11 ignore NaN for Z also when explicitly created with 3D + # and so the geometries are considered as 2D (and thus z dimension is ignored) + assert left == right + else: + assert left != right + + +def test_equality_z(): + # different dimensionality + geom1 = Point(0, 1) + geom2 = Point(0, 1, 0) + assert geom1 != geom2 + + # different dimensionality with NaN z + geom2 = Point(0, 1, np.nan) + if shapely.geos_version < (3, 10, 0): + # GEOS < 3.8 fill the NaN with 0, so the z dimension is different + # assert geom1 != geom2 + # however, has_z still returns False, so z dimension is ignored in .coords + assert geom1 == geom2 + elif shapely.geos_version < (3, 12, 0): + # GEOS 3.10-3.11 ignore NaN for Z also when explicitly created with 3D + # and so the geometries are considered as 2D (and thus z dimension is ignored) + assert geom1 == geom2 + else: + assert geom1 != geom2 + + +def test_equality_exact_type(): + # geometries with different type but same coord seq are not equal + geom1 = LineString([(0, 0), (1, 1), (0, 1), (0, 0)]) + geom2 = LinearRing([(0, 0), (1, 1), (0, 1), (0, 0)]) + geom3 = Polygon([(0, 0), (1, 1), (0, 1), (0, 0)]) + assert geom1 != geom2 + assert geom1 != geom3 + assert geom2 != geom3 + + # empty with different type + geom1 = shapely.from_wkt("POINT EMPTY") + geom2 = shapely.from_wkt("LINESTRING EMPTY") + assert geom1 != geom2 + + +def test_equality_polygon(): + # different exterior rings + geom1 = shapely.from_wkt("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))") + geom2 = shapely.from_wkt("POLYGON ((0 0, 10 0, 10 10, 0 15, 0 0))") + assert geom1 != geom2 + + # different number of holes + geom1 = shapely.from_wkt( + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 1))" + ) + geom2 = shapely.from_wkt( + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 1), (3 3, 4 3, 4 4, 3 3))" + ) + assert geom1 != geom2 + + # different order of holes + geom1 = shapely.from_wkt( + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (3 3, 4 3, 4 4, 3 3), (1 1, 2 1, 2 2, 1 1))" + ) + geom2 = shapely.from_wkt( + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 1), (3 3, 4 3, 4 4, 3 3))" + ) + assert geom1 != geom2 + + +@pytest.mark.parametrize("geom", all_types) +def test_comparison_notimplemented(geom): + # comparing to a non-geometry class should return NotImplemented in __eq__ + # to ensure proper delegation to other (eg to ensure comparison of scalar + # with array works) + # https://github.com/shapely/shapely/issues/1056 + assert geom.__eq__(1) is NotImplemented + + # with array + arr = np.array([geom, geom], dtype=object) + + result = arr == geom + assert isinstance(result, np.ndarray) + assert result.all() + + result = geom == arr + assert isinstance(result, np.ndarray) + assert result.all() + + result = arr != geom + assert isinstance(result, np.ndarray) + assert not result.any() + + result = geom != arr + assert isinstance(result, np.ndarray) + assert not result.any() + + +def test_comparison_not_supported(): + geom1 = Point(1, 1) + geom2 = Point(2, 2) + + with pytest.raises(TypeError, match="not supported between instances"): + geom1 > geom2 + + with pytest.raises(TypeError, match="not supported between instances"): + geom1 < geom2 + + with pytest.raises(TypeError, match="not supported between instances"): + geom1 >= geom2 + + with pytest.raises(TypeError, match="not supported between instances"): + geom1 <= geom2 diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_geometry_base.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_geometry_base.py new file mode 100644 index 0000000000000000000000000000000000000000..e50eb4215ab58e538d6c65bb4e583ba1279454c4 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_geometry_base.py @@ -0,0 +1,281 @@ +import platform +import weakref + +import numpy as np +import pytest + +import shapely +from shapely import ( + GeometryCollection, + LinearRing, + LineString, + MultiLineString, + MultiPoint, + MultiPolygon, + Point, + Polygon, +) +from shapely.errors import ShapelyDeprecationWarning +from shapely.testing import assert_geometries_equal + + +def test_polygon(): + assert bool(Polygon()) is False + + +def test_linestring(): + assert bool(LineString()) is False + + +def test_point(): + assert bool(Point()) is False + + +def test_geometry_collection(): + assert bool(GeometryCollection()) is False + + +geometries_all_types = [ + Point(1, 1), + LinearRing([(0, 0), (1, 1), (0, 1), (0, 0)]), + LineString([(0, 0), (1, 1), (0, 1), (0, 0)]), + Polygon([(0, 0), (1, 1), (0, 1), (0, 0)]), + MultiPoint([(1, 1)]), + MultiLineString([[(0, 0), (1, 1), (0, 1), (0, 0)]]), + MultiPolygon([Polygon([(0, 0), (1, 1), (0, 1), (0, 0)])]), + GeometryCollection([Point(1, 1)]), +] + + +@pytest.mark.skipif( + platform.python_implementation() == "PyPy", + reason="Setting custom attributes doesn't fail on PyPy", +) +@pytest.mark.parametrize("geom", geometries_all_types) +def test_setattr_disallowed(geom): + with pytest.raises(AttributeError): + geom.name = "test" + + +@pytest.mark.parametrize("geom", geometries_all_types) +def test_weakrefable(geom): + _ = weakref.ref(geom) + + +def test_base_class_not_callable(): + with pytest.raises(TypeError): + shapely.Geometry("POINT (1 1)") + + +def test_GeometryType_deprecated(): + geom = Point(1, 1) + + with pytest.warns(ShapelyDeprecationWarning): + geom_type = geom.geometryType() + + assert geom_type == geom.geom_type + + +def test_type_deprecated(): + geom = Point(1, 1) + + with pytest.warns(ShapelyDeprecationWarning): + geom_type = geom.type + + assert geom_type == geom.geom_type + + +@pytest.mark.skipif(shapely.geos_version < (3, 10, 0), reason="GEOS < 3.10") +def test_segmentize(): + line = LineString([(0, 0), (0, 10)]) + result = line.segmentize(max_segment_length=5) + assert result.equals(LineString([(0, 0), (0, 5), (0, 10)])) + + +@pytest.mark.skipif(shapely.geos_version < (3, 7, 0), reason="GEOS < 3.7") +def test_reverse(): + coords = [(0, 0), (1, 2)] + line = LineString(coords) + result = line.reverse() + assert result.coords[:] == coords[::-1] + + +@pytest.mark.skipif(shapely.geos_version < (3, 9, 0), reason="GEOS < 3.9") +@pytest.mark.parametrize( + "op", ["union", "intersection", "difference", "symmetric_difference"] +) +@pytest.mark.parametrize("grid_size", [0, 1, 2]) +def test_binary_op_grid_size(op, grid_size): + geom1 = shapely.box(0, 0, 2.5, 2.5) + geom2 = shapely.box(2, 2, 3, 3) + + result = getattr(geom1, op)(geom2, grid_size=grid_size) + expected = getattr(shapely, op)(geom1, geom2, grid_size=grid_size) + assert result == expected + + +@pytest.mark.skipif(shapely.geos_version < (3, 10, 0), reason="GEOS < 3.10") +def test_dwithin(): + point = Point(1, 1) + line = LineString([(0, 0), (0, 10)]) + assert point.dwithin(line, 0.5) is False + assert point.dwithin(line, 1.5) is True + + +def test_contains_properly(): + polygon = Polygon([(0, 0), (10, 10), (10, -10)]) + line = LineString([(0, 0), (10, 0)]) + assert polygon.contains_properly(line) is False + assert polygon.contains(line) is True + + +@pytest.mark.parametrize( + "op", ["convex_hull", "envelope", "oriented_envelope", "minimum_rotated_rectangle"] +) +def test_constructive_properties(op): + geom = LineString([(0, 0), (0, 10), (10, 10)]) + result = getattr(geom, op) + expected = getattr(shapely, op)(geom) + assert result == expected + + +@pytest.mark.parametrize( + "op", + [ + "crosses", + "contains", + "contains_properly", + "covered_by", + "covers", + "disjoint", + "equals", + "intersects", + "overlaps", + "touches", + "within", + ], +) +def test_array_argument_binary_predicates(op): + polygon = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]) + points = shapely.points([(0, 0), (0.5, 0.5), (1, 1)]) + + result = getattr(polygon, op)(points) + assert isinstance(result, np.ndarray) + expected = np.array([getattr(polygon, op)(p) for p in points], dtype=bool) + np.testing.assert_array_equal(result, expected) + + # check scalar + result = getattr(polygon, op)(points[0]) + assert type(result) is bool + + +@pytest.mark.parametrize( + "op, kwargs", + [ + pytest.param( + "dwithin", + dict(distance=0.5), + marks=pytest.mark.skipif( + shapely.geos_version < (3, 10, 0), reason="GEOS < 3.10" + ), + ), + ("equals_exact", dict(tolerance=0.01)), + ("relate_pattern", dict(pattern="T*F**F***")), + ], +) +def test_array_argument_binary_predicates2(op, kwargs): + polygon = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]) + points = shapely.points([(0, 0), (0.5, 0.5), (1, 1)]) + + result = getattr(polygon, op)(points, **kwargs) + assert isinstance(result, np.ndarray) + expected = np.array([getattr(polygon, op)(p, **kwargs) for p in points], dtype=bool) + np.testing.assert_array_equal(result, expected) + + # check scalar + result = getattr(polygon, op)(points[0], **kwargs) + assert type(result) is bool + + +@pytest.mark.parametrize( + "op", + [ + "difference", + "intersection", + "symmetric_difference", + "union", + ], +) +def test_array_argument_binary_geo(op): + box = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]) + polygons = shapely.buffer(shapely.points([(0, 0), (0.5, 0.5), (1, 1)]), 0.5) + + result = getattr(box, op)(polygons) + assert isinstance(result, np.ndarray) + expected = np.array([getattr(box, op)(g) for g in polygons], dtype=object) + assert_geometries_equal(result, expected) + + # check scalar + result = getattr(box, op)(polygons[0]) + assert isinstance(result, (Polygon, MultiPolygon)) + + +@pytest.mark.parametrize("op", ["distance", "hausdorff_distance"]) +def test_array_argument_float(op): + polygon = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]) + points = shapely.points([(0, 0), (0.5, 0.5), (1, 1)]) + + result = getattr(polygon, op)(points) + assert isinstance(result, np.ndarray) + expected = np.array([getattr(polygon, op)(p) for p in points], dtype="float64") + np.testing.assert_array_equal(result, expected) + + # check scalar + result = getattr(polygon, op)(points[0]) + assert type(result) is float + + +@pytest.mark.parametrize("op", ["line_interpolate_point", "interpolate"]) +def test_array_argument_linear_point(op): + line = LineString([(0, 0), (0, 1), (1, 1)]) + distances = np.array([0, 0.5, 1]) + + result = getattr(line, op)(distances) + assert isinstance(result, np.ndarray) + expected = np.array( + [line.line_interpolate_point(d) for d in distances], dtype=object + ) + assert_geometries_equal(result, expected) + + # check scalar + result = getattr(line, op)(distances[0]) + assert isinstance(result, Point) + + +@pytest.mark.parametrize("op", ["line_locate_point", "project"]) +def test_array_argument_linear_float(op): + line = LineString([(0, 0), (0, 1), (1, 1)]) + points = shapely.points([(0, 0), (0.5, 0.5), (1, 1)]) + + result = getattr(line, op)(points) + assert isinstance(result, np.ndarray) + expected = np.array([line.line_locate_point(p) for p in points], dtype="float64") + np.testing.assert_array_equal(result, expected) + + # check scalar + result = getattr(line, op)(points[0]) + assert type(result) is float + + +def test_array_argument_buffer(): + point = Point(1, 1) + distances = np.array([0, 0.5, 1]) + + result = point.buffer(distances) + assert isinstance(result, np.ndarray) + expected = np.array([point.buffer(d) for d in distances], dtype=object) + assert_geometries_equal(result, expected) + + # check scalar + result = point.buffer(distances[0]) + assert isinstance(result, Polygon) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_hash.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_hash.py new file mode 100644 index 0000000000000000000000000000000000000000..f54f88548c2f4422d86a74900fcd5f7197e6b3ce --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_hash.py @@ -0,0 +1,28 @@ +import pytest + +import shapely +from shapely.affinity import translate +from shapely.geometry import GeometryCollection, LineString, MultiPoint, Point + + +@pytest.mark.parametrize( + "geom", + [ + Point(1, 2), + MultiPoint([(1, 2), (3, 4)]), + LineString([(1, 2), (3, 4)]), + Point(0, 0).buffer(1.0), + GeometryCollection([Point(1, 2), LineString([(1, 2), (3, 4)])]), + ], + ids=[ + "Point", + "MultiPoint", + "LineString", + "Polygon", + "GeometryCollection", + ], +) +def test_hash(geom): + h1 = hash(geom) + assert h1 == hash(shapely.from_wkb(geom.wkb)) + assert h1 != hash(translate(geom, 1.0, 2.0)) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_linestring.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_linestring.py new file mode 100644 index 0000000000000000000000000000000000000000..adf0ec29596e96e1872d8433fcbe8a296c194acf --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_linestring.py @@ -0,0 +1,213 @@ +import numpy as np +import pytest + +import shapely +from shapely import LinearRing, LineString, Point +from shapely.coords import CoordinateSequence + + +def test_from_coordinate_sequence(): + # From coordinate tuples + line = LineString([(1.0, 2.0), (3.0, 4.0)]) + assert len(line.coords) == 2 + assert line.coords[:] == [(1.0, 2.0), (3.0, 4.0)] + + line = LineString([(1.0, 2.0), (3.0, 4.0)]) + assert line.coords[:] == [(1.0, 2.0), (3.0, 4.0)] + + +def test_from_coordinate_sequence_3D(): + line = LineString([(1.0, 2.0, 3.0), (3.0, 4.0, 5.0)]) + assert line.has_z + assert line.coords[:] == [(1.0, 2.0, 3.0), (3.0, 4.0, 5.0)] + + +def test_from_points(): + # From Points + line = LineString([Point(1.0, 2.0), Point(3.0, 4.0)]) + assert line.coords[:] == [(1.0, 2.0), (3.0, 4.0)] + + line = LineString([Point(1.0, 2.0), Point(3.0, 4.0)]) + assert line.coords[:] == [(1.0, 2.0), (3.0, 4.0)] + + +def test_from_mix(): + # From mix of tuples and Points + line = LineString([Point(1.0, 2.0), (2.0, 3.0), Point(3.0, 4.0)]) + assert line.coords[:] == [(1.0, 2.0), (2.0, 3.0), (3.0, 4.0)] + + +def test_from_linestring(): + # From another linestring + line = LineString([(1.0, 2.0), (3.0, 4.0)]) + copy = LineString(line) + assert copy.coords[:] == [(1.0, 2.0), (3.0, 4.0)] + assert copy.geom_type == "LineString" + + +def test_from_linearring(): + coords = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)] + ring = LinearRing(coords) + copy = LineString(ring) + assert copy.coords[:] == coords + assert copy.geom_type == "LineString" + + +def test_from_linestring_z(): + coords = [(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)] + line = LineString(coords) + copy = LineString(line) + assert copy.coords[:] == coords + assert copy.geom_type == "LineString" + + +def test_from_generator(): + gen = (coord for coord in [(1.0, 2.0), (3.0, 4.0)]) + line = LineString(gen) + assert line.coords[:] == [(1.0, 2.0), (3.0, 4.0)] + + +def test_from_empty(): + line = LineString() + assert line.is_empty + assert isinstance(line.coords, CoordinateSequence) + assert line.coords[:] == [] + + line = LineString([]) + assert line.is_empty + assert isinstance(line.coords, CoordinateSequence) + assert line.coords[:] == [] + + +def test_from_numpy(): + # Construct from a numpy array + line = LineString(np.array([[1.0, 2.0], [3.0, 4.0]])) + assert line.coords[:] == [(1.0, 2.0), (3.0, 4.0)] + + +def test_numpy_empty_linestring_coords(): + # Check empty + line = LineString([]) + la = np.asarray(line.coords) + + assert la.shape == (0, 2) + + +def test_numpy_object_array(): + geom = LineString([(0.0, 0.0), (0.0, 1.0)]) + ar = np.empty(1, object) + ar[:] = [geom] + assert ar[0] == geom + + +@pytest.mark.filterwarnings("ignore:Creating an ndarray from ragged nested sequences:") +def test_from_invalid_dim(): + # TODO(shapely-2.0) better error message? + # pytest.raises(ValueError, match="at least 2 coordinate tuples|at least 2 coordinates"): + with pytest.raises(shapely.GEOSException): + LineString([(1, 2)]) + + # exact error depends on numpy version + with pytest.raises((ValueError, TypeError)): + LineString([(1, 2, 3), (4, 5)]) + + with pytest.raises((ValueError, TypeError)): + LineString([(1, 2), (3, 4, 5)]) + + msg = r"The ordinate \(last\) dimension should be 2 or 3, got {}" + with pytest.raises(ValueError, match=msg.format(4)): + LineString([(1, 2, 3, 4), (4, 5, 6, 7)]) + + with pytest.raises(ValueError, match=msg.format(1)): + LineString([(1,), (4,)]) + + +def test_from_single_coordinate(): + """Test for issue #486""" + coords = [[-122.185933073564, 37.3629353839073]] + with pytest.raises(shapely.GEOSException): + ls = LineString(coords) + ls.geom_type # caused segfault before fix + + +class TestLineString: + def test_linestring(self): + + # From coordinate tuples + line = LineString([(1.0, 2.0), (3.0, 4.0)]) + assert len(line.coords) == 2 + assert line.coords[:] == [(1.0, 2.0), (3.0, 4.0)] + + # Bounds + assert line.bounds == (1.0, 2.0, 3.0, 4.0) + + # Coordinate access + assert tuple(line.coords) == ((1.0, 2.0), (3.0, 4.0)) + assert line.coords[0] == (1.0, 2.0) + assert line.coords[1] == (3.0, 4.0) + with pytest.raises(IndexError): + line.coords[2] # index out of range + + # Geo interface + assert line.__geo_interface__ == { + "type": "LineString", + "coordinates": ((1.0, 2.0), (3.0, 4.0)), + } + + def test_linestring_empty(self): + # Test Non-operability of Null geometry + l_null = LineString() + assert l_null.wkt == "LINESTRING EMPTY" + assert l_null.length == 0.0 + + def test_equals_argument_order(self): + """ + Test equals predicate functions correctly regardless of the order + of the inputs. See issue #317. + """ + coords = ((0, 0), (1, 0), (1, 1), (0, 0)) + ls = LineString(coords) + lr = LinearRing(coords) + + assert ls.__eq__(lr) is False # previously incorrectly returned True + assert lr.__eq__(ls) is False + assert (ls == lr) is False + assert (lr == ls) is False + + ls_clone = LineString(coords) + lr_clone = LinearRing(coords) + + assert ls.__eq__(ls_clone) is True + assert lr.__eq__(lr_clone) is True + assert (ls == ls_clone) is True + assert (lr == lr_clone) is True + + def test_numpy_linestring_coords(self): + from numpy.testing import assert_array_equal + + line = LineString([(1.0, 2.0), (3.0, 4.0)]) + expected = np.array([[1.0, 2.0], [3.0, 4.0]]) + + # Coordinate sequences can be adapted as well + la = np.asarray(line.coords) + assert_array_equal(la, expected) + + +def test_linestring_immutable(): + line = LineString([(1.0, 2.0), (3.0, 4.0)]) + + with pytest.raises(AttributeError): + line.coords = [(-1.0, -1.0), (1.0, 1.0)] + + with pytest.raises(TypeError): + line.coords[0] = (-1.0, -1.0) + + +def test_linestring_array_coercion(): + # don't convert to array of coordinates, keep objects + line = LineString([(1.0, 2.0), (3.0, 4.0)]) + arr = np.array(line) + assert arr.ndim == 0 + assert arr.size == 1 + assert arr.dtype == np.dtype("object") + assert arr.item() == line diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_multi.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_multi.py new file mode 100644 index 0000000000000000000000000000000000000000..08d4666cbdd486fb42717508e08e5be6d0d528db --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_multi.py @@ -0,0 +1,11 @@ +import numpy as np + +test_int_types = [int, np.int16, np.int32, np.int64] + + +class MultiGeometryTestCase: + def subgeom_access_test(self, cls, geoms): + geom = cls(geoms) + for t in test_int_types: + for i, g in enumerate(geoms): + assert geom.geoms[t(i)] == geoms[i] diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_multipoint.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_multipoint.py new file mode 100644 index 0000000000000000000000000000000000000000..2e8acb67bc943f4c1e7847238eb5f236634a05e3 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_multipoint.py @@ -0,0 +1,78 @@ +import numpy as np +import pytest + +from shapely import MultiPoint, Point +from shapely.errors import EmptyPartError +from shapely.geometry.base import dump_coords +from shapely.tests.geometry.test_multi import MultiGeometryTestCase + + +class TestMultiPoint(MultiGeometryTestCase): + def test_multipoint(self): + + # From coordinate tuples + geom = MultiPoint([(1.0, 2.0), (3.0, 4.0)]) + assert len(geom.geoms) == 2 + assert dump_coords(geom) == [[(1.0, 2.0)], [(3.0, 4.0)]] + + # From points + geom = MultiPoint([Point(1.0, 2.0), Point(3.0, 4.0)]) + assert len(geom.geoms) == 2 + assert dump_coords(geom) == [[(1.0, 2.0)], [(3.0, 4.0)]] + + # From another multi-point + geom2 = MultiPoint(geom) + assert len(geom2.geoms) == 2 + assert dump_coords(geom2) == [[(1.0, 2.0)], [(3.0, 4.0)]] + + # Sub-geometry Access + assert isinstance(geom.geoms[0], Point) + assert geom.geoms[0].x == 1.0 + assert geom.geoms[0].y == 2.0 + with pytest.raises(IndexError): # index out of range + geom.geoms[2] + + # Geo interface + assert geom.__geo_interface__ == { + "type": "MultiPoint", + "coordinates": ((1.0, 2.0), (3.0, 4.0)), + } + + def test_multipoint_from_numpy(self): + # Construct from a numpy array + geom = MultiPoint(np.array([[0.0, 0.0], [1.0, 2.0]])) + assert isinstance(geom, MultiPoint) + assert len(geom.geoms) == 2 + assert dump_coords(geom) == [[(0.0, 0.0)], [(1.0, 2.0)]] + + def test_subgeom_access(self): + p0 = Point(1.0, 2.0) + p1 = Point(3.0, 4.0) + self.subgeom_access_test(MultiPoint, [p0, p1]) + + def test_create_multi_with_empty_component(self): + msg = "Can't create MultiPoint with empty component" + with pytest.raises(EmptyPartError, match=msg): + MultiPoint([Point(0, 0), Point()]).wkt + + +def test_multipoint_array_coercion(): + geom = MultiPoint([(1.0, 2.0), (3.0, 4.0)]) + arr = np.array(geom) + assert arr.ndim == 0 + assert arr.size == 1 + assert arr.dtype == np.dtype("object") + assert arr.item() == geom + + +def test_numpy_object_array(): + geom = MultiPoint([(1.0, 2.0), (3.0, 4.0)]) + ar = np.empty(1, object) + ar[:] = [geom] + assert ar[0] == geom + + +def test_len_raises(): + geom = MultiPoint([[5.0, 6.0], [7.0, 8.0]]) + with pytest.raises(TypeError): + len(geom) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_multipolygon.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_multipolygon.py new file mode 100644 index 0000000000000000000000000000000000000000..62a9216f51706576f1fecda916588486d286252c --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_multipolygon.py @@ -0,0 +1,134 @@ +import numpy as np +import pytest + +from shapely import MultiPolygon, Polygon +from shapely.geometry.base import dump_coords +from shapely.tests.geometry.test_multi import MultiGeometryTestCase + + +class TestMultiPolygon(MultiGeometryTestCase): + def test_multipolygon(self): + # From coordinate tuples + coords = [ + ( + ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)), + [((0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25))], + ) + ] + geom = MultiPolygon(coords) + assert isinstance(geom, MultiPolygon) + assert len(geom.geoms) == 1 + assert dump_coords(geom) == [ + [ + (0.0, 0.0), + (0.0, 1.0), + (1.0, 1.0), + (1.0, 0.0), + (0.0, 0.0), + [(0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25), (0.25, 0.25)], + ] + ] + + # Or without holes + coords2 = [(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)),)] + geom = MultiPolygon(coords2) + assert isinstance(geom, MultiPolygon) + assert len(geom.geoms) == 1 + assert dump_coords(geom) == [ + [ + (0.0, 0.0), + (0.0, 1.0), + (1.0, 1.0), + (1.0, 0.0), + (0.0, 0.0), + ] + ] + + # Or from polygons + p = Polygon( + ((0, 0), (0, 1), (1, 1), (1, 0)), + [((0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25))], + ) + geom = MultiPolygon([p]) + assert len(geom.geoms) == 1 + assert dump_coords(geom) == [ + [ + (0.0, 0.0), + (0.0, 1.0), + (1.0, 1.0), + (1.0, 0.0), + (0.0, 0.0), + [(0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25), (0.25, 0.25)], + ] + ] + + # Or from another multi-polygon + geom2 = MultiPolygon(geom) + assert len(geom2.geoms) == 1 + assert dump_coords(geom2) == [ + [ + (0.0, 0.0), + (0.0, 1.0), + (1.0, 1.0), + (1.0, 0.0), + (0.0, 0.0), + [(0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25), (0.25, 0.25)], + ] + ] + + # Sub-geometry Access + assert isinstance(geom.geoms[0], Polygon) + assert dump_coords(geom.geoms[0]) == [ + (0.0, 0.0), + (0.0, 1.0), + (1.0, 1.0), + (1.0, 0.0), + (0.0, 0.0), + [(0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25), (0.25, 0.25)], + ] + with pytest.raises(IndexError): # index out of range + geom.geoms[1] + + # Geo interface + assert geom.__geo_interface__ == { + "type": "MultiPolygon", + "coordinates": [ + ( + ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)), + ((0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25), (0.25, 0.25)), + ) + ], + } + + def test_subgeom_access(self): + poly0 = Polygon([(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)]) + poly1 = Polygon([(0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25)]) + self.subgeom_access_test(MultiPolygon, [poly0, poly1]) + + +def test_fail_list_of_multipolygons(): + """A list of multipolygons is not a valid multipolygon ctor argument""" + multi = MultiPolygon( + [ + ( + ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)), + [((0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25))], + ) + ] + ) + with pytest.raises(ValueError): + MultiPolygon([multi]) + + +def test_numpy_object_array(): + geom = MultiPolygon( + [ + ( + ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)), + [((0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25))], + ) + ] + ) + ar = np.empty(1, object) + ar[:] = [geom] + assert ar[0] == geom diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_point.py b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_point.py new file mode 100644 index 0000000000000000000000000000000000000000..89967b2e67203133cf69fc3e313ba816e8c02064 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/geometry/test_point.py @@ -0,0 +1,188 @@ +import numpy as np +import pytest + +from shapely import Point +from shapely.coords import CoordinateSequence +from shapely.errors import DimensionError + + +def test_from_coordinates(): + # 2D points + p = Point(1.0, 2.0) + assert p.coords[:] == [(1.0, 2.0)] + assert p.has_z is False + + # 3D Point + p = Point(1.0, 2.0, 3.0) + assert p.coords[:] == [(1.0, 2.0, 3.0)] + assert p.has_z + + # empty + p = Point() + assert p.is_empty + assert isinstance(p.coords, CoordinateSequence) + assert p.coords[:] == [] + + +def test_from_sequence(): + # From single coordinate pair + p = Point((3.0, 4.0)) + assert p.coords[:] == [(3.0, 4.0)] + p = Point([3.0, 4.0]) + assert p.coords[:] == [(3.0, 4.0)] + + # From coordinate sequence + p = Point([(3.0, 4.0)]) + assert p.coords[:] == [(3.0, 4.0)] + p = Point([[3.0, 4.0]]) + assert p.coords[:] == [(3.0, 4.0)] + + # 3D + p = Point((3.0, 4.0, 5.0)) + assert p.coords[:] == [(3.0, 4.0, 5.0)] + p = Point([3.0, 4.0, 5.0]) + assert p.coords[:] == [(3.0, 4.0, 5.0)] + p = Point([(3.0, 4.0, 5.0)]) + assert p.coords[:] == [(3.0, 4.0, 5.0)] + + +def test_from_numpy(): + # Construct from a numpy array + p = Point(np.array([1.0, 2.0])) + assert p.coords[:] == [(1.0, 2.0)] + + p = Point(np.array([1.0, 2.0, 3.0])) + assert p.coords[:] == [(1.0, 2.0, 3.0)] + + +def test_from_numpy_xy(): + # Construct from separate x, y numpy arrays - if those are length 1, + # this is allowed for compat with shapely 1.8 + # (https://github.com/shapely/shapely/issues/1587) + p = Point(np.array([1.0]), np.array([2.0])) + assert p.coords[:] == [(1.0, 2.0)] + + p = Point(np.array([1.0]), np.array([2.0]), np.array([3.0])) + assert p.coords[:] == [(1.0, 2.0, 3.0)] + + +def test_from_point(): + # From another point + p = Point(3.0, 4.0) + q = Point(p) + assert q.coords[:] == [(3.0, 4.0)] + + p = Point(3.0, 4.0, 5.0) + q = Point(p) + assert q.coords[:] == [(3.0, 4.0, 5.0)] + + +def test_from_generator(): + gen = (coord for coord in [(1.0, 2.0)]) + p = Point(gen) + assert p.coords[:] == [(1.0, 2.0)] + + +def test_from_invalid(): + + with pytest.raises(TypeError, match="takes at most 3 arguments"): + Point(1, 2, 3, 4) + + # this worked in shapely 1.x, just ignoring the other coords + with pytest.raises( + ValueError, match="takes only scalar or 1-size vector arguments" + ): + Point([(2, 3), (11, 4)]) + + +class TestPoint: + def test_point(self): + + # Test 2D points + p = Point(1.0, 2.0) + assert p.x == 1.0 + assert type(p.x) is float + assert p.y == 2.0 + assert type(p.y) is float + assert p.coords[:] == [(1.0, 2.0)] + assert str(p) == p.wkt + assert p.has_z is False + with pytest.raises(DimensionError): + p.z + + # Check 3D + p = Point(1.0, 2.0, 3.0) + assert p.coords[:] == [(1.0, 2.0, 3.0)] + assert str(p) == p.wkt + assert p.has_z is True + assert p.z == 3.0 + assert type(p.z) is float + + # Coordinate access + p = Point((3.0, 4.0)) + assert p.x == 3.0 + assert p.y == 4.0 + assert tuple(p.coords) == ((3.0, 4.0),) + assert p.coords[0] == (3.0, 4.0) + with pytest.raises(IndexError): # index out of range + p.coords[1] + + # Bounds + assert p.bounds == (3.0, 4.0, 3.0, 4.0) + + # Geo interface + assert p.__geo_interface__ == {"type": "Point", "coordinates": (3.0, 4.0)} + + def test_point_empty(self): + # Test Non-operability of Null geometry + p_null = Point() + assert p_null.wkt == "POINT EMPTY" + assert p_null.coords[:] == [] + assert p_null.area == 0.0 + + def test_coords(self): + # From Array.txt + p = Point(0.0, 0.0, 1.0) + coords = p.coords[0] + assert coords == (0.0, 0.0, 1.0) + + # Convert to Numpy array, passing through Python sequence + a = np.asarray(coords) + assert a.ndim == 1 + assert a.size == 3 + assert a.shape == (3,) + + +def test_point_immutable(): + p = Point(3.0, 4.0) + + with pytest.raises(AttributeError): + p.coords = (2.0, 1.0) + + with pytest.raises(TypeError): + p.coords[0] = (2.0, 1.0) + + +def test_point_array_coercion(): + # don't convert to array of coordinates, keep objects + p = Point(3.0, 4.0) + arr = np.array(p) + assert arr.ndim == 0 + assert arr.size == 1 + assert arr.dtype == np.dtype("object") + assert arr.item() == p + + +def test_numpy_empty_point_coords(): + pe = Point() + + # Access the coords + a = np.asarray(pe.coords) + assert a.shape == (0, 2) + + +def test_numpy_object_array(): + geom = Point(3.0, 4.0) + ar = np.empty(1, object) + ar[:] = [geom] + assert ar[0] == geom diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/__init__.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..f77e7a5dbeb30f4ce48d27c6ab55a4c5b9552908 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/__init__.py @@ -0,0 +1,10 @@ +import sys + +import numpy + +from shapely.geos import geos_version_string + +# Show some diagnostic information; handy for CI +print("Python version: " + sys.version.replace("\n", " ")) +print("GEOS version: " + geos_version_string) +print("Numpy version: " + numpy.version.version) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_buffer.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_buffer.py new file mode 100644 index 0000000000000000000000000000000000000000..4ed8ce5a3af4f77bf14a98a74501272697c84ef4 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_buffer.py @@ -0,0 +1,172 @@ +import unittest + +import pytest + +from shapely import geometry +from shapely.constructive import BufferCapStyle, BufferJoinStyle +from shapely.geometry.base import CAP_STYLE, JOIN_STYLE + + +@pytest.mark.parametrize("distance", [float("nan"), float("inf")]) +def test_non_finite_distance(distance): + g = geometry.Point(0, 0) + with pytest.raises(ValueError, match="distance must be finite"): + g.buffer(distance) + + +class BufferTests(unittest.TestCase): + """Test Buffer Point/Line/Polygon with and without single_sided params""" + + def test_empty(self): + g = geometry.Point(0, 0) + h = g.buffer(0) + assert h.is_empty + + def test_point(self): + g = geometry.Point(0, 0) + h = g.buffer(1, quad_segs=1) + assert h.geom_type == "Polygon" + expected_coord = [(1.0, 0.0), (0, -1.0), (-1.0, 0), (0, 1.0), (1.0, 0.0)] + for index, coord in enumerate(h.exterior.coords): + assert coord[0] == pytest.approx(expected_coord[index][0]) + assert coord[1] == pytest.approx(expected_coord[index][1]) + + def test_point_single_sidedd(self): + g = geometry.Point(0, 0) + h = g.buffer(1, quad_segs=1, single_sided=True) + assert h.geom_type == "Polygon" + expected_coord = [(1.0, 0.0), (0, -1.0), (-1.0, 0), (0, 1.0), (1.0, 0.0)] + for index, coord in enumerate(h.exterior.coords): + assert coord[0] == pytest.approx(expected_coord[index][0]) + assert coord[1] == pytest.approx(expected_coord[index][1]) + + def test_line(self): + g = geometry.LineString([[0, 0], [0, 1]]) + h = g.buffer(1, quad_segs=1) + assert h.geom_type == "Polygon" + expected_coord = [ + (-1.0, 1.0), + (0, 2.0), + (1.0, 1.0), + (1.0, 0.0), + (0, -1.0), + (-1.0, 0.0), + (-1.0, 1.0), + ] + for index, coord in enumerate(h.exterior.coords): + assert coord[0] == pytest.approx(expected_coord[index][0]) + assert coord[1] == pytest.approx(expected_coord[index][1]) + + def test_line_single_sideded_left(self): + g = geometry.LineString([[0, 0], [0, 1]]) + h = g.buffer(1, quad_segs=1, single_sided=True) + assert h.geom_type == "Polygon" + expected_coord = [(0.0, 1.0), (0.0, 0.0), (-1.0, 0.0), (-1.0, 1.0), (0.0, 1.0)] + for index, coord in enumerate(h.exterior.coords): + assert coord[0] == pytest.approx(expected_coord[index][0]) + assert coord[1] == pytest.approx(expected_coord[index][1]) + + def test_line_single_sideded_right(self): + g = geometry.LineString([[0, 0], [0, 1]]) + h = g.buffer(-1, quad_segs=1, single_sided=True) + assert h.geom_type == "Polygon" + expected_coord = [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)] + for index, coord in enumerate(h.exterior.coords): + assert coord[0] == pytest.approx(expected_coord[index][0]) + assert coord[1] == pytest.approx(expected_coord[index][1]) + + def test_polygon(self): + g = geometry.Polygon([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]) + h = g.buffer(1, quad_segs=1) + assert h.geom_type == "Polygon" + expected_coord = [ + (-1.0, 0.0), + (-1.0, 1.0), + (0.0, 2.0), + (1.0, 2.0), + (2.0, 1.0), + (2.0, 0.0), + (1.0, -1.0), + (0.0, -1.0), + (-1.0, 0.0), + ] + for index, coord in enumerate(h.exterior.coords): + assert coord[0] == pytest.approx(expected_coord[index][0]) + assert coord[1] == pytest.approx(expected_coord[index][1]) + + def test_polygon_single_sideded(self): + g = geometry.Polygon([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]) + h = g.buffer(1, quad_segs=1, single_sided=True) + assert h.geom_type == "Polygon" + expected_coord = [ + (-1.0, 0.0), + (-1.0, 1.0), + (0.0, 2.0), + (1.0, 2.0), + (2.0, 1.0), + (2.0, 0.0), + (1.0, -1.0), + (0.0, -1.0), + (-1.0, 0.0), + ] + for index, coord in enumerate(h.exterior.coords): + assert coord[0] == pytest.approx(expected_coord[index][0]) + assert coord[1] == pytest.approx(expected_coord[index][1]) + + def test_enum_values(self): + assert CAP_STYLE.round == 1 + assert CAP_STYLE.round == BufferCapStyle.round + assert CAP_STYLE.flat == 2 + assert CAP_STYLE.flat == BufferCapStyle.flat + assert CAP_STYLE.square == 3 + assert CAP_STYLE.square == BufferCapStyle.square + + assert JOIN_STYLE.round == 1 + assert JOIN_STYLE.round == BufferJoinStyle.round + assert JOIN_STYLE.mitre == 2 + assert JOIN_STYLE.mitre == BufferJoinStyle.mitre + assert JOIN_STYLE.bevel == 3 + assert JOIN_STYLE.bevel == BufferJoinStyle.bevel + + def test_cap_style(self): + g = geometry.LineString([[0, 0], [1, 0]]) + h = g.buffer(1, cap_style=BufferCapStyle.round) + assert h == g.buffer(1, cap_style=CAP_STYLE.round) + assert h == g.buffer(1, cap_style="round") + + h = g.buffer(1, cap_style=BufferCapStyle.flat) + assert h == g.buffer(1, cap_style=CAP_STYLE.flat) + assert h == g.buffer(1, cap_style="flat") + + h = g.buffer(1, cap_style=BufferCapStyle.square) + assert h == g.buffer(1, cap_style=CAP_STYLE.square) + assert h == g.buffer(1, cap_style="square") + + def test_buffer_style(self): + g = geometry.LineString([[0, 0], [1, 0]]) + h = g.buffer(1, join_style=BufferJoinStyle.round) + assert h == g.buffer(1, join_style=JOIN_STYLE.round) + assert h == g.buffer(1, join_style="round") + + h = g.buffer(1, join_style=BufferJoinStyle.mitre) + assert h == g.buffer(1, join_style=JOIN_STYLE.mitre) + assert h == g.buffer(1, join_style="mitre") + + h = g.buffer(1, join_style=BufferJoinStyle.bevel) + assert h == g.buffer(1, join_style=JOIN_STYLE.bevel) + assert h == g.buffer(1, join_style="bevel") + + +def test_deprecated_quadsegs(): + point = geometry.Point(0, 0) + with pytest.warns(FutureWarning): + result = point.buffer(1, quadsegs=1) + expected = point.buffer(1, quad_segs=1) + assert result.equals(expected) + + +def test_resolution_alias(): + point = geometry.Point(0, 0) + result = point.buffer(1, resolution=1) + expected = point.buffer(1, quad_segs=1) + assert result.equals(expected) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_cga.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_cga.py new file mode 100644 index 0000000000000000000000000000000000000000..d96257411dc2cd2188dcdc4b7cfa683d6a56fbd1 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_cga.py @@ -0,0 +1,51 @@ +import unittest + +import pytest + +from shapely.geometry.polygon import LinearRing, orient, Polygon, signed_area + + +class SignedAreaTestCase(unittest.TestCase): + def test_triangle(self): + tri = LinearRing([(0, 0), (2, 5), (7, 0)]) + assert signed_area(tri) == pytest.approx(-7 * 5 / 2) + + def test_square(self): + xmin, xmax = (-1, 1) + ymin, ymax = (-2, 3) + rect = LinearRing( + [(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)] + ) + assert signed_area(rect) == pytest.approx(10.0) + + +class RingOrientationTestCase(unittest.TestCase): + def test_ccw(self): + ring = LinearRing([(1, 0), (0, 1), (0, 0)]) + assert ring.is_ccw + + def test_cw(self): + ring = LinearRing([(0, 0), (0, 1), (1, 0)]) + assert not ring.is_ccw + + +class PolygonOrienterTestCase(unittest.TestCase): + def test_no_holes(self): + ring = LinearRing([(0, 0), (0, 1), (1, 0)]) + polygon = Polygon(ring) + assert not polygon.exterior.is_ccw + polygon = orient(polygon, 1) + assert polygon.exterior.is_ccw + + def test_holes(self): + # fmt: off + polygon = Polygon( + [(0, 0), (0, 1), (1, 0)], + [[(0.5, 0.25), (0.25, 0.5), (0.25, 0.25)]] + ) + # fmt: on + assert not polygon.exterior.is_ccw + assert polygon.interiors[0].is_ccw + polygon = orient(polygon, 1) + assert polygon.exterior.is_ccw + assert not polygon.interiors[0].is_ccw diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_invalid_geometries.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_invalid_geometries.py new file mode 100644 index 0000000000000000000000000000000000000000..5e8ef92549934691b30c873a79bcb6c02544053a --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_invalid_geometries.py @@ -0,0 +1,28 @@ +"""Test recovery from operation on invalid geometries +""" + +import unittest + +import pytest + +import shapely +from shapely.errors import TopologicalError +from shapely.geometry import Polygon + + +class InvalidGeometriesTestCase(unittest.TestCase): + def test_invalid_intersection(self): + # Make a self-intersecting polygon + polygon_invalid = Polygon([(0, 0), (1, 1), (1, -1), (0, 1), (0, 0)]) + assert not polygon_invalid.is_valid + + # Intersect with a valid polygon + polygon = Polygon([(-0.5, -0.5), (-0.5, 0.5), (0.5, 0.5), (0.5, -5)]) + assert polygon.is_valid + assert polygon_invalid.intersects(polygon) + + with pytest.raises((TopologicalError, shapely.GEOSException)): + polygon_invalid.intersection(polygon) + with pytest.raises((TopologicalError, shapely.GEOSException)): + polygon.intersection(polygon_invalid) + return diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_linemerge.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_linemerge.py new file mode 100644 index 0000000000000000000000000000000000000000..2583895328344169c91aa9e2d2db0e7d3aac754e --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_linemerge.py @@ -0,0 +1,44 @@ +import unittest + +from shapely.geometry import LineString, MultiLineString +from shapely.ops import linemerge + + +class LineMergeTestCase(unittest.TestCase): + def test_linemerge(self): + + lines = MultiLineString([[(0, 0), (1, 1)], [(2, 0), (2, 1), (1, 1)]]) + result = linemerge(lines) + assert isinstance(result, LineString) + assert not result.is_ring + assert len(result.coords) == 4 + assert result.coords[0] == (0.0, 0.0) + assert result.coords[3] == (2.0, 0.0) + + lines2 = MultiLineString([((0, 0), (1, 1)), ((0, 0), (2, 0), (2, 1), (1, 1))]) + result = linemerge(lines2) + assert result.is_ring + assert len(result.coords) == 5 + + lines3 = [ + LineString([(0, 0), (1, 1)]), + LineString([(0, 0), (0, 1)]), + ] + result = linemerge(lines3) + assert not result.is_ring + assert len(result.coords) == 3 + assert result.coords[0] == (0.0, 1.0) + assert result.coords[2] == (1.0, 1.0) + + lines4 = [ + [(0, 0), (1, 1)], + [(0, 0), (0, 1)], + ] + assert result.equals(linemerge(lines4)) + + lines5 = [ + ((0, 0), (1, 1)), + ((1, 0), (0, 1)), + ] + result = linemerge(lines5) + assert result.geom_type == "MultiLineString" diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_minimum_clearance.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_minimum_clearance.py new file mode 100644 index 0000000000000000000000000000000000000000..e7ea8e6e8641713f758ede9ba751fdd999bcdfac --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_minimum_clearance.py @@ -0,0 +1,40 @@ +""" +Tests for the minimum clearance property. +""" + +import math + +import pytest + +from shapely.geos import geos_version +from shapely.wkt import loads as load_wkt + +requires_geos_36 = pytest.mark.skipif( + geos_version < (3, 6, 0), reason="GEOS >= 3.6.0 is required." +) + + +@requires_geos_36 +def test_point(): + point = load_wkt("POINT (0 0)") + assert point.minimum_clearance == math.inf + + +@requires_geos_36 +def test_linestring(): + line = load_wkt("LINESTRING (0 0, 1 1, 2 2)") + assert round(line.minimum_clearance, 6) == 1.414214 + + +@requires_geos_36 +def test_simple_polygon(): + poly = load_wkt("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))") + assert poly.minimum_clearance == 1.0 + + +@requires_geos_36 +def test_more_complicated_polygon(): + poly = load_wkt( + "POLYGON ((20 20, 34 124, 70 140, 130 130, 70 100, 110 70, 170 20, 90 10, 20 20))" + ) + assert round(poly.minimum_clearance, 6) == 35.777088 diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_operators.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_operators.py new file mode 100644 index 0000000000000000000000000000000000000000..9b47e948cf5e77ff96f58a9712561df527903d9a --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_operators.py @@ -0,0 +1,60 @@ +import unittest + +from shapely.geometry import LineString, MultiPoint, Point, Polygon + + +class OperatorsTestCase(unittest.TestCase): + def test_point(self): + point = Point(0, 0) + point2 = Point(-1, 1) + assert point.union(point2).equals(point | point2) + assert (point & point2).is_empty + assert point.equals(point - point2) + assert point.symmetric_difference(point2).equals(point ^ point2) + assert point != point2 + point_dupe = Point(0, 0) + assert point, point_dupe + + def test_multipoint(self): + mp1 = MultiPoint([(0, 0), (1, 1)]) + mp1_dup = MultiPoint([(0, 0), (1, 1)]) + mp1_rev = MultiPoint([(1, 1), (0, 0)]) + mp2 = MultiPoint([(0, 0), (1, 1), (2, 2)]) + mp3 = MultiPoint([(0, 0), (1, 1), (2, 3)]) + + assert mp1 == mp1_dup + assert mp1 != mp1_rev + assert mp1 != mp2 + assert mp2 != mp3 + + p = Point(0, 0) + mp = MultiPoint([(0, 0)]) + assert p != mp + assert mp != p + + def test_polygon(self): + shell = ((0, 0), (3, 0), (3, 3), (0, 3)) + hole = ((1, 1), (2, 1), (2, 2), (1, 2)) + p_solid = Polygon(shell) + p2_solid = Polygon(shell) + p_hole = Polygon(shell, holes=[hole]) + p2_hole = Polygon(shell, holes=[hole]) + + assert p_solid == p2_solid + assert p_hole == p2_hole + assert p_solid != p_hole + + shell2 = ((-5, 2), (10.5, 3), (7, 3)) + p3_hole = Polygon(shell2, holes=[hole]) + assert p_hole != p3_hole + + def test_linestring(self): + line1 = LineString([(0, 0), (1, 1), (2, 2)]) + line2 = LineString([(0, 0), (2, 2)]) + line2_dup = LineString([(0, 0), (2, 2)]) + # .equals() indicates these are the same + assert line1.equals(line2) + # but != indicates these are different + assert line1 != line2 + # but dupes are the same with == + assert line2 == line2_dup diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_parallel_offset.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_parallel_offset.py new file mode 100644 index 0000000000000000000000000000000000000000..26ae927c28ca7911a45d4870feaa2675ae8e8781 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_parallel_offset.py @@ -0,0 +1,60 @@ +import unittest + +import pytest + +from shapely.geometry import LinearRing, LineString +from shapely.testing import assert_geometries_equal + + +@pytest.mark.parametrize("distance", [float("nan"), float("inf")]) +def test_non_finite_distance(distance): + g = LineString([(0, 0), (10, 0)]) + with pytest.raises(ValueError, match="distance must be finite"): + g.parallel_offset(distance) + + +class OperationsTestCase(unittest.TestCase): + def test_parallel_offset_linestring(self): + line1 = LineString([(0, 0), (10, 0)]) + left = line1.parallel_offset(5, "left") + assert_geometries_equal(left, LineString([(0, 5), (10, 5)])) + right = line1.parallel_offset(5, "right") + assert_geometries_equal(right, LineString([(10, -5), (0, -5)]), normalize=True) + right = line1.parallel_offset(-5, "left") + assert_geometries_equal(right, LineString([(10, -5), (0, -5)]), normalize=True) + left = line1.parallel_offset(-5, "right") + assert_geometries_equal(left, LineString([(0, 5), (10, 5)])) + + # by default, parallel_offset is right-handed + assert_geometries_equal(line1.parallel_offset(5), right) + + line2 = LineString([(0, 0), (5, 0), (5, -5)]) + assert_geometries_equal( + line2.parallel_offset(2, "left", join_style=3), + LineString([(0, 2), (5, 2), (7, 0), (7, -5)]), + ) + assert_geometries_equal( + line2.parallel_offset(2, "left", join_style=2), + LineString([(0, 2), (7, 2), (7, -5)]), + ) + # offset_curve alias + assert_geometries_equal( + line1.offset_curve(2, quad_segs=10), + line1.parallel_offset(2, "left", resolution=10), + ) + assert_geometries_equal( + line1.offset_curve(-2, join_style="mitre"), + line1.parallel_offset(2, "right", join_style=2), + ) + + def test_parallel_offset_linear_ring(self): + lr1 = LinearRing([(0, 0), (5, 0), (5, 5), (0, 5), (0, 0)]) + assert_geometries_equal( + lr1.parallel_offset(2, "left", resolution=1), + LineString([(2, 2), (3, 2), (3, 3), (2, 3), (2, 2)]), + ) + # offset_curve alias + assert_geometries_equal( + lr1.offset_curve(2, quad_segs=1), + lr1.parallel_offset(2, "left", resolution=1), + ) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_persist.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_persist.py new file mode 100644 index 0000000000000000000000000000000000000000..b86e8e88bd5fef1028411f02ac0db2e664530afd --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_persist.py @@ -0,0 +1,51 @@ +"""Persistence tests +""" +import pickle +import struct +import unittest + +from shapely import wkb, wkt +from shapely.geometry import Point + + +class PersistTestCase(unittest.TestCase): + def test_pickle(self): + + p = Point(0.0, 0.0) + data = pickle.dumps(p) + q = pickle.loads(data) + assert q.equals(p) + + def test_wkb(self): + + p = Point(0.0, 0.0) + wkb_big_endian = wkb.dumps(p, big_endian=True) + wkb_little_endian = wkb.dumps(p, big_endian=False) + # Regardless of byte order, loads ought to correctly recover the + # geometry + assert p.equals(wkb.loads(wkb_big_endian)) + assert p.equals(wkb.loads(wkb_little_endian)) + + def test_wkb_dumps_endianness(self): + + p = Point(0.5, 2.0) + wkb_big_endian = wkb.dumps(p, big_endian=True) + wkb_little_endian = wkb.dumps(p, big_endian=False) + assert wkb_big_endian != wkb_little_endian + # According to WKB specification in section 3.3 of OpenGIS + # Simple Features Specification for SQL, revision 1.1, the + # first byte of a WKB representation indicates byte order. + # Big-endian is 0, little-endian is 1. + assert wkb_big_endian[0] == 0 + assert wkb_little_endian[0] == 1 + # Check that the doubles (0.5, 2.0) are in correct byte order + double_size = struct.calcsize("d") + assert wkb_big_endian[(-2 * double_size) :] == struct.pack(">2d", p.x, p.y) + assert wkb_little_endian[(-2 * double_size) :] == struct.pack("<2d", p.x, p.y) + + def test_wkt(self): + p = Point(0.0, 0.0) + text = wkt.dumps(p) + assert text.startswith("POINT") + pt = wkt.loads(text) + assert pt.equals(p) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_polygonize.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_polygonize.py new file mode 100644 index 0000000000000000000000000000000000000000..caf1777b507ed7ecaf61b9e518aeb93cad13ee07 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_polygonize.py @@ -0,0 +1,44 @@ +import unittest + +from shapely.geometry import LineString, Point, Polygon +from shapely.geometry.base import dump_coords +from shapely.ops import polygonize, polygonize_full + + +class PolygonizeTestCase(unittest.TestCase): + def test_polygonize(self): + lines = [ + LineString([(0, 0), (1, 1)]), + LineString([(0, 0), (0, 1)]), + LineString([(0, 1), (1, 1)]), + LineString([(1, 1), (1, 0)]), + LineString([(1, 0), (0, 0)]), + LineString([(5, 5), (6, 6)]), + Point(0, 0), + ] + result = list(polygonize(lines)) + assert all(isinstance(x, Polygon) for x in result) + + def test_polygonize_full(self): + + lines2 = [ + [(0, 0), (1, 1)], + [(0, 0), (0, 1)], + [(0, 1), (1, 1)], + [(1, 1), (1, 0)], + [(1, 0), (0, 0)], + [(5, 5), (6, 6)], + [(1, 1), (100, 100)], + ] + + result2, cuts, dangles, invalids = polygonize_full(lines2) + assert len(result2.geoms) == 2 + assert all(isinstance(x, Polygon) for x in result2.geoms) + assert list(cuts.geoms) == [] + assert all(isinstance(x, LineString) for x in dangles.geoms) + + assert dump_coords(dangles) == [ + [(1.0, 1.0), (100.0, 100.0)], + [(5.0, 5.0), (6.0, 6.0)], + ] + assert list(invalids.geoms) == [] diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_products_z.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_products_z.py new file mode 100644 index 0000000000000000000000000000000000000000..96fa545067f9b8d0a7ac41d28f752211101abbf9 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_products_z.py @@ -0,0 +1,13 @@ +import unittest + +from shapely.geometry import LineString + + +class ProductZTestCase(unittest.TestCase): + def test_line_intersection(self): + line1 = LineString([(0, 0, 0), (1, 1, 1)]) + line2 = LineString([(0, 1, 1), (1, 0, 0)]) + interxn = line1.intersection(line2) + assert interxn.has_z + assert interxn._ndim == 3 + assert 0.0 <= interxn.z <= 1.0 diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_shared_paths.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_shared_paths.py new file mode 100644 index 0000000000000000000000000000000000000000..e7015e6c7077068f7cae5a9f579deaa29fa987fe --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_shared_paths.py @@ -0,0 +1,45 @@ +import unittest + +import pytest + +from shapely.errors import GeometryTypeError +from shapely.geometry import GeometryCollection, LineString, MultiLineString, Point +from shapely.ops import shared_paths + + +class SharedPaths(unittest.TestCase): + def test_shared_paths_forward(self): + g1 = LineString([(0, 0), (10, 0), (10, 5), (20, 5)]) + g2 = LineString([(5, 0), (15, 0)]) + result = shared_paths(g1, g2) + + assert isinstance(result, GeometryCollection) + assert len(result.geoms) == 2 + a, b = result.geoms + assert isinstance(a, MultiLineString) + assert len(a.geoms) == 1 + assert a.geoms[0].coords[:] == [(5, 0), (10, 0)] + assert b.is_empty + + def test_shared_paths_forward2(self): + g1 = LineString([(0, 0), (10, 0), (10, 5), (20, 5)]) + g2 = LineString([(15, 0), (5, 0)]) + result = shared_paths(g1, g2) + + assert isinstance(result, GeometryCollection) + assert len(result.geoms) == 2 + a, b = result.geoms + assert isinstance(b, MultiLineString) + assert len(b.geoms) == 1 + assert b.geoms[0].coords[:] == [(5, 0), (10, 0)] + assert a.is_empty + + def test_wrong_type(self): + g1 = Point(0, 0) + g2 = LineString([(5, 0), (15, 0)]) + + with pytest.raises(GeometryTypeError): + shared_paths(g1, g2) + + with pytest.raises(GeometryTypeError): + shared_paths(g2, g1) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_substring.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_substring.py new file mode 100644 index 0000000000000000000000000000000000000000..08c6570c1a95af00d5fcbeeb7624949f172c0c57 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_substring.py @@ -0,0 +1,220 @@ +import json +import unittest + +import pytest + +from shapely.errors import GeometryTypeError +from shapely.geometry import LineString, Point, shape +from shapely.ops import substring + + +class SubstringTestCase(unittest.TestCase): + def setUp(self): + self.point = Point(1, 1) + self.line1 = LineString([(0, 0), (2, 0)]) + self.line2 = LineString([(3, 0), (3, 6), (4.5, 6)]) + self.line3 = LineString((0, i) for i in range(5)) + + def test_return_startpoint(self): + assert substring(self.line1, -500, -600).equals(Point(0, 0)) + assert substring(self.line1, -500, -500).equals(Point(0, 0)) + assert substring(self.line1, -1, -1.1, True).equals(Point(0, 0)) + assert substring(self.line1, -1.1, -1.1, True).equals(Point(0, 0)) + + def test_return_endpoint(self): + assert substring(self.line1, 500, 600).equals(Point(2, 0)) + assert substring(self.line1, 500, 500).equals(Point(2, 0)) + assert substring(self.line1, 1, 1.1, True).equals(Point(2, 0)) + assert substring(self.line1, 1.1, 1.1, True).equals(Point(2, 0)) + + def test_return_midpoint(self): + assert substring(self.line1, 0.5, 0.5).equals(Point(0.5, 0)) + assert substring(self.line1, -0.5, -0.5).equals(Point(1.5, 0)) + assert substring(self.line1, 0.5, 0.5, True).equals(Point(1, 0)) + assert substring(self.line1, -0.5, -0.5, True).equals(Point(1, 0)) + + # Coming from opposite ends + assert substring(self.line1, 1.5, -0.5).equals(Point(1.5, 0)) + assert substring(self.line1, -0.5, 1.5).equals(Point(1.5, 0)) + assert substring(self.line1, -0.7, 0.3, True).equals(Point(0.6, 0)) + assert substring(self.line1, 0.3, -0.7, True).equals(Point(0.6, 0)) + + def test_return_startsubstring(self): + assert ( + substring(self.line1, -500, 0.6).wkt == LineString([(0, 0), (0.6, 0)]).wkt + ) + assert ( + substring(self.line1, -1.1, 0.6, True).wkt + == LineString([(0, 0), (1.2, 0)]).wkt + ) + + def test_return_startsubstring_reversed(self): + # not normalized + assert substring(self.line1, -1, -500).wkt == LineString([(1, 0), (0, 0)]).wkt + assert ( + substring(self.line3, 3.5, 0).wkt + == LineString([(0, 3.5), (0, 3), (0, 2), (0, 1), (0, 0)]).wkt + ) + assert ( + substring(self.line3, -1.5, -500).wkt + == LineString([(0, 2.5), (0, 2), (0, 1), (0, 0)]).wkt + ) + # normalized + assert ( + substring(self.line1, -0.5, -1.1, True).wkt + == LineString([(1.0, 0), (0, 0)]).wkt + ) + assert ( + substring(self.line3, 0.5, 0, True).wkt + == LineString([(0, 2.0), (0, 1), (0, 0)]).wkt + ) + assert ( + substring(self.line3, -0.5, -1.1, True).wkt + == LineString([(0, 2.0), (0, 1), (0, 0)]).wkt + ) + + def test_return_endsubstring(self): + assert substring(self.line1, 0.6, 500).wkt == LineString([(0.6, 0), (2, 0)]).wkt + assert ( + substring(self.line1, 0.6, 1.1, True).wkt + == LineString([(1.2, 0), (2, 0)]).wkt + ) + + def test_return_endsubstring_reversed(self): + # not normalized + assert substring(self.line1, 500, -1).wkt == LineString([(2, 0), (1, 0)]).wkt + assert ( + substring(self.line3, 4, 2.5).wkt + == LineString([(0, 4), (0, 3), (0, 2.5)]).wkt + ) + assert ( + substring(self.line3, 500, -1.5).wkt + == LineString([(0, 4), (0, 3), (0, 2.5)]).wkt + ) + # normalized + assert ( + substring(self.line1, 1.1, -0.5, True).wkt + == LineString([(2, 0), (1.0, 0)]).wkt + ) + assert ( + substring(self.line3, 1, 0.5, True).wkt + == LineString([(0, 4), (0, 3), (0, 2.0)]).wkt + ) + assert ( + substring(self.line3, 1.1, -0.5, True).wkt + == LineString([(0, 4), (0, 3), (0, 2.0)]).wkt + ) + + def test_return_midsubstring(self): + assert ( + substring(self.line1, 0.5, 0.6).wkt == LineString([(0.5, 0), (0.6, 0)]).wkt + ) + assert ( + substring(self.line1, -0.6, -0.5).wkt + == LineString([(1.4, 0), (1.5, 0)]).wkt + ) + assert ( + substring(self.line1, 0.5, 0.6, True).wkt + == LineString([(1, 0), (1.2, 0)]).wkt + ) + assert ( + substring(self.line1, -0.6, -0.5, True).wkt + == LineString([(0.8, 0), (1, 0)]).wkt + ) + + def test_return_midsubstring_reversed(self): + assert ( + substring(self.line1, 0.6, 0.5).wkt == LineString([(0.6, 0), (0.5, 0)]).wkt + ) + assert ( + substring(self.line1, -0.5, -0.6).wkt + == LineString([(1.5, 0), (1.4, 0)]).wkt + ) + assert ( + substring(self.line1, 0.6, 0.5, True).wkt + == LineString([(1.2, 0), (1, 0)]).wkt + ) + assert ( + substring(self.line1, -0.5, -0.6, True).wkt + == LineString([(1, 0), (0.8, 0)]).wkt + ) + + # with vertices + # not normalized + assert ( + substring(self.line3, 3.5, 2.5).wkt + == LineString([(0, 3.5), (0, 3), (0, 2.5)]).wkt + ) # (+, +) + assert ( + substring(self.line3, -0.5, -1.5).wkt + == LineString([(0, 3.5), (0, 3), (0, 2.5)]).wkt + ) # (-, -) + assert ( + substring(self.line3, 3.5, -1.5).wkt + == LineString([(0, 3.5), (0, 3), (0, 2.5)]).wkt + ) # (+, -) + assert ( + substring(self.line3, -0.5, 2.5).wkt + == LineString([(0, 3.5), (0, 3), (0, 2.5)]).wkt + ) # (-, +) + + # normalized + assert ( + substring(self.line3, 0.875, 0.625, True).wkt + == LineString([(0, 3.5), (0, 3), (0, 2.5)]).wkt + ) + assert ( + substring(self.line3, -0.125, -0.375, True).wkt + == LineString([(0, 3.5), (0, 3), (0, 2.5)]).wkt + ) + assert ( + substring(self.line3, 0.875, -0.375, True).wkt + == LineString([(0, 3.5), (0, 3), (0, 2.5)]).wkt + ) + assert ( + substring(self.line3, -0.125, 0.625, True).wkt + == LineString([(0, 3.5), (0, 3), (0, 2.5)]).wkt + ) + + def test_return_substring_with_vertices(self): + assert ( + substring(self.line2, 1, 7).wkt == LineString([(3, 1), (3, 6), (4, 6)]).wkt + ) + assert ( + substring(self.line2, 0.2, 0.9, True).wkt + == LineString([(3, 1.5), (3, 6), (3.75, 6)]).wkt + ) + assert ( + substring(self.line2, 0, 0.9, True).wkt + == LineString([(3, 0), (3, 6), (3.75, 6)]).wkt + ) + assert ( + substring(self.line2, 0.2, 1, True).wkt + == LineString([(3, 1.5), (3, 6), (4.5, 6)]).wkt + ) + + def test_return_substring_issue682(self): + assert list(substring(self.line2, 0.1, 0).coords) == [(3.0, 0.1), (3.0, 0.0)] + + def test_return_substring_issue848(self): + line = shape(json.loads(data_issue_848)) + cut_line = substring(line, 0.7, 0.8, normalized=True) + assert len(cut_line.coords) == 53 + + def test_raise_type_error(self): + with pytest.raises(GeometryTypeError): + substring(Point(0, 0), 0, 0) + + def test_return_z_coord_issue1699(self): + line_z = LineString([(0, 0, 0), (2, 0, 0)]) + assert ( + substring(line_z, 0, 0.5, True).wkt + == LineString([(0, 0, 0), (1, 0, 0)]).wkt + ) + assert ( + substring(line_z, 0.5, 0, True).wkt + == LineString([(1, 0, 0), (0, 0, 0)]).wkt + ) + + +data_issue_848 = '{"type": "LineString", "coordinates": [[-87.71314, 41.96793], [-87.71312, 41.96667], [-87.71311, 41.96643], [-87.7131, 41.96635], [-87.71309, 41.9663], [-87.71303, 41.96621], [-87.71298, 41.96615], [-87.71292, 41.96611], [-87.7128, 41.96607], [-87.71268, 41.96605], [-87.71255, 41.96605], [-87.7124, 41.96605], [-87.71219, 41.96605], [-87.71173, 41.96606], [-87.71108, 41.96607], [-87.71027, 41.96607], [-87.70884, 41.96609], [-87.70763, 41.96611], [-87.70645, 41.96612], [-87.70399, 41.96613], [-87.70267, 41.96614], [-87.70166, 41.96615], [-87.70075, 41.96615], [-87.69954, 41.96615], [-87.69873, 41.96616], [-87.69789, 41.96618], [-87.69675, 41.9662], [-87.69502, 41.96621], [-87.69411, 41.96621], [-87.69145, 41.96623], [-87.69026, 41.96624], [-87.68946, 41.96625], [-87.6885, 41.96625], [-87.68718, 41.96628], [-87.68545, 41.96631], [-87.68399, 41.96632], [-87.68271, 41.96635], [-87.68159, 41.96636], [-87.68034, 41.96638], [-87.67863, 41.96641], [-87.67766, 41.96642], [-87.67741, 41.96641], [-87.67722, 41.9664], [-87.67695, 41.96638], [-87.67665, 41.96632], [-87.67638, 41.96623], [-87.67613, 41.96612], [-87.67589, 41.96596], [-87.6757, 41.96579], [-87.67557, 41.96565], [-87.67544, 41.96547], [-87.67539, 41.96536], [-87.6753, 41.96519], [-87.67524, 41.96503], [-87.67523, 41.96491], [-87.67522, 41.96477], [-87.67521, 41.96457], [-87.6752, 41.96434], [-87.67519, 41.96371], [-87.67517, 41.96175], [-87.67513, 41.96077], [-87.67505, 41.95798], [-87.67501, 41.95666], [-87.67497, 41.95513], [-87.67496, 41.95452], [-87.67491, 41.95392], [-87.67487, 41.95302], [-87.67485, 41.95202], [-87.67484, 41.95101], [-87.67479, 41.94959], [-87.67476, 41.94859], [-87.67474, 41.94703], [-87.67468, 41.94596], [-87.67466, 41.94513], [-87.67463, 41.94494], [-87.67457, 41.94474], [-87.6745, 41.94455], [-87.67442, 41.94438], [-87.6743, 41.94424], [-87.67419, 41.94414], [-87.67405, 41.94404], [-87.67386, 41.94393], [-87.67367, 41.94386], [-87.67348, 41.9438], [-87.67334, 41.94376], [-87.67311, 41.94373], [-87.67289, 41.9437], [-87.67263, 41.94369], [-87.67234, 41.94369], [-87.6715, 41.9437], [-87.67088, 41.94371], [-87.66938, 41.94373], [-87.66749, 41.94377], [-87.66585, 41.94378], [-87.66508, 41.94379], [-87.66361, 41.94381], [-87.6591, 41.94391], [-87.65767, 41.94391], [-87.65608, 41.94393], [-87.6555, 41.94394], [-87.65521, 41.94394], [-87.65503, 41.94393], [-87.65488, 41.9439], [-87.6547, 41.94386], [-87.65454, 41.9438], [-87.65441, 41.94375], [-87.65425, 41.94364], [-87.6541, 41.94351], [-87.654, 41.94342], [-87.65392, 41.94331], [-87.65382, 41.94319], [-87.65375, 41.94306], [-87.65367, 41.94292], [-87.65361, 41.9428], [-87.65355, 41.94269], [-87.65351, 41.94257], [-87.65347, 41.94238], [-87.65345, 41.94218], [-87.65338, 41.93975], [-87.65337, 41.93939], [-87.65337, 41.93893], [-87.65336, 41.93865], [-87.65333, 41.93763], [-87.65331, 41.93717], [-87.65328, 41.93627], [-87.65327, 41.93603], [-87.65323, 41.93532], [-87.65322, 41.93491], [-87.6532, 41.93445], [-87.65314, 41.93312], [-87.65313, 41.93273], [-87.6531, 41.93218], [-87.65307, 41.93151], [-87.65305, 41.9309], [-87.65302, 41.9303], [-87.65299, 41.92951], [-87.65296, 41.9287], [-87.65295, 41.92842], [-87.65294, 41.92768], [-87.65292, 41.92715], [-87.65289, 41.92599], [-87.65288, 41.92537], [-87.65287, 41.92505], [-87.65282, 41.92352], [-87.65276, 41.92172], [-87.65274, 41.92113], [-87.65264, 41.91822], [-87.65264, 41.91808], [-87.65262, 41.91763], [-87.65261, 41.91718], [-87.65255, 41.91563], [-87.6525, 41.91406], [-87.65242, 41.91377], [-87.65234, 41.91362], [-87.65223, 41.91351], [-87.65208, 41.91339], [-87.65183, 41.91322], [-87.65093, 41.9126], [-87.65017, 41.91203], [-87.64985, 41.9118], [-87.64971, 41.91171], [-87.64957, 41.91164], [-87.64948, 41.9116], [-87.64939, 41.91158], [-87.6492, 41.91153], [-87.649, 41.9115], [-87.64883, 41.9115], [-87.64863, 41.9115], [-87.64792, 41.91151], [-87.64781, 41.9115], [-87.64768, 41.91146], [-87.64756, 41.91139], [-87.64745, 41.91122], [-87.6474, 41.91112], [-87.64739, 41.91101], [-87.64738, 41.91086], [-87.64736, 41.91071], [-87.64734, 41.91061], [-87.64728, 41.91051], [-87.64718, 41.91044], [-87.64709, 41.9104], [-87.64697, 41.91036], [-87.64682, 41.91034], [-87.64664, 41.91033], [-87.64646, 41.91033], [-87.6458, 41.91034], [-87.64523, 41.91034], [-87.64348, 41.91036], [-87.64255, 41.91039], [-87.641, 41.9104], [-87.64038, 41.9104], [-87.63975, 41.9104], [-87.6393, 41.91041], [-87.63814, 41.91042], [-87.63798, 41.91041], [-87.63787, 41.91039], [-87.63771, 41.91034], [-87.63757, 41.91027], [-87.63746, 41.91021], [-87.63736, 41.91011], [-87.6373, 41.90999], [-87.63727, 41.90986], [-87.63726, 41.90973], [-87.63725, 41.90951], [-87.63723, 41.90874], [-87.63718, 41.90758], [-87.63713, 41.90607], [-87.63711, 41.90543], [-87.63702, 41.90381], [-87.63702, 41.90368], [-87.63701, 41.90334], [-87.63699, 41.90322], [-87.63694, 41.90312], [-87.63688, 41.90299], [-87.63682, 41.90292], [-87.63671, 41.90279], [-87.63659, 41.90265], [-87.63653, 41.90255], [-87.63649, 41.90245], [-87.63646, 41.90235], [-87.63647, 41.90221], [-87.63647, 41.90211], [-87.6365, 41.90202], [-87.63653, 41.9019], [-87.63659, 41.90177], [-87.63666, 41.90156], [-87.63669, 41.90143], [-87.6367, 41.90131], [-87.6367, 41.90119], [-87.63664, 41.90029], [-87.63664, 41.90008], [-87.63662, 41.89975], [-87.63658, 41.89892], [-87.63657, 41.89867], [-87.63654, 41.89761], [-87.63654, 41.89738], [-87.63649, 41.89726], [-87.63641, 41.89715], [-87.63634, 41.89708], [-87.63623, 41.89699], [-87.63595, 41.89677], [-87.63583, 41.89667], [-87.63574, 41.89654], [-87.63569, 41.89645], [-87.63568, 41.89633], [-87.63565, 41.89542], [-87.63563, 41.89434], [-87.6356, 41.89327], [-87.63558, 41.89261], [-87.63554, 41.89147], [-87.63553, 41.89051], [-87.63548, 41.8903], [-87.6354, 41.89021], [-87.63533, 41.89012], [-87.63524, 41.89007], [-87.63508, 41.89001], [-87.63493, 41.88997], [-87.63475, 41.88994], [-87.63462, 41.88991], [-87.63447, 41.88989], [-87.63436, 41.88984], [-87.63425, 41.88979], [-87.63414, 41.8897], [-87.63407, 41.88962], [-87.63402, 41.88952], [-87.63399, 41.88943], [-87.63397, 41.88897], [-87.63396, 41.88707], [-87.63391, 41.88572], [-87.63389, 41.88441], [-87.63385, 41.8827], [-87.63384, 41.88144], [-87.63378, 41.88014], [-87.63374, 41.87872], [-87.63369, 41.87726], [-87.63369, 41.87706], [-87.63365, 41.87695], [-87.63359, 41.87691], [-87.63353, 41.87688], [-87.63345, 41.87686], [-87.63338, 41.87685], [-87.63263, 41.87685], [-87.63173, 41.87686], [-87.62925, 41.87689], [-87.62821, 41.87691], [-87.62757, 41.87693], [-87.6265, 41.87696], [-87.62635, 41.87696], [-87.62603, 41.87697], [-87.62605, 41.87831], [-87.6261, 41.87951], [-87.62616, 41.88203], [-87.62619, 41.88322], [-87.62622, 41.88443], [-87.62626, 41.88534], [-87.62625, 41.88552], [-87.62625, 41.88557], [-87.62627, 41.88562], [-87.6263, 41.88566], [-87.62635, 41.88569], [-87.62642, 41.88572], [-87.6265, 41.88573], [-87.62655, 41.88574], [-87.62661, 41.88574], [-87.62683, 41.88574], [-87.62784, 41.88574], [-87.62887, 41.88574], [-87.62948, 41.88574], [-87.62982, 41.88574], [-87.62992, 41.88574], [-87.63011, 41.88574], [-87.6302, 41.88574], [-87.63089, 41.88574], [-87.63204, 41.88574], [-87.63285, 41.88573], [-87.63391, 41.88572], [-87.63396, 41.88707], [-87.63397, 41.88897], [-87.63399, 41.88943], [-87.63402, 41.88952], [-87.63407, 41.88962], [-87.63414, 41.8897], [-87.63425, 41.88979], [-87.63436, 41.88984], [-87.63447, 41.88989], [-87.63462, 41.88991], [-87.63475, 41.88994], [-87.63493, 41.88997], [-87.63508, 41.89001], [-87.63524, 41.89007], [-87.63533, 41.89012], [-87.6354, 41.89021], [-87.63548, 41.8903], [-87.63553, 41.89051], [-87.63554, 41.89147], [-87.63558, 41.89261], [-87.6356, 41.89327], [-87.63563, 41.89434], [-87.63565, 41.89542], [-87.63568, 41.89633], [-87.63569, 41.89645], [-87.63574, 41.89654], [-87.63583, 41.89667], [-87.63595, 41.89677], [-87.63623, 41.89699], [-87.63634, 41.89708], [-87.63641, 41.89715], [-87.63649, 41.89726], [-87.63654, 41.89738], [-87.63654, 41.89761], [-87.63657, 41.89867], [-87.63658, 41.89892], [-87.63662, 41.89975], [-87.63664, 41.90008], [-87.63664, 41.90029], [-87.6367, 41.90119], [-87.6367, 41.90131], [-87.63669, 41.90143], [-87.63666, 41.90156], [-87.63659, 41.90177], [-87.63653, 41.9019], [-87.6365, 41.90202], [-87.63647, 41.90211], [-87.63647, 41.90221], [-87.63646, 41.90235], [-87.63649, 41.90245], [-87.63653, 41.90255], [-87.63659, 41.90265], [-87.63671, 41.90279], [-87.63682, 41.90292], [-87.63688, 41.90299], [-87.63694, 41.90312], [-87.63699, 41.90322], [-87.63701, 41.90334], [-87.63702, 41.90368], [-87.63702, 41.90381], [-87.63711, 41.90543], [-87.63713, 41.90607], [-87.63718, 41.90758], [-87.63723, 41.90874], [-87.63725, 41.90951], [-87.63726, 41.90973], [-87.63727, 41.90986], [-87.6373, 41.90999], [-87.63736, 41.91011], [-87.63746, 41.91021], [-87.63757, 41.91027], [-87.63771, 41.91034], [-87.63787, 41.91039], [-87.63798, 41.91041], [-87.63814, 41.91042], [-87.6393, 41.91041], [-87.63975, 41.9104], [-87.64038, 41.9104], [-87.641, 41.9104], [-87.64255, 41.91039], [-87.64348, 41.91036], [-87.64523, 41.91034], [-87.6458, 41.91034], [-87.64646, 41.91033], [-87.64664, 41.91033], [-87.64682, 41.91034], [-87.64697, 41.91036], [-87.64709, 41.9104], [-87.64718, 41.91044], [-87.64728, 41.91051], [-87.64734, 41.91061], [-87.64736, 41.91071], [-87.64738, 41.91086], [-87.64739, 41.91101], [-87.6474, 41.91112], [-87.64745, 41.91122], [-87.64756, 41.91139], [-87.64768, 41.91146], [-87.64781, 41.9115], [-87.64792, 41.91151], [-87.64863, 41.9115], [-87.64883, 41.9115], [-87.649, 41.9115], [-87.6492, 41.91153], [-87.64939, 41.91158], [-87.64948, 41.9116], [-87.64957, 41.91164], [-87.64971, 41.91171], [-87.64985, 41.9118], [-87.65017, 41.91203], [-87.65093, 41.9126], [-87.65183, 41.91322], [-87.65208, 41.91339], [-87.65223, 41.91351], [-87.65234, 41.91362], [-87.65242, 41.91377], [-87.6525, 41.91406], [-87.65255, 41.91563], [-87.65261, 41.91718], [-87.65262, 41.91763], [-87.65264, 41.91808], [-87.65264, 41.91822], [-87.65274, 41.92113], [-87.65276, 41.92172], [-87.65282, 41.92352], [-87.65287, 41.92505], [-87.65288, 41.92537], [-87.65289, 41.92599], [-87.65292, 41.92715], [-87.65294, 41.92768], [-87.65295, 41.92842], [-87.65296, 41.9287], [-87.65299, 41.92951], [-87.65302, 41.9303], [-87.65305, 41.9309], [-87.65307, 41.93151], [-87.6531, 41.93218], [-87.65313, 41.93273], [-87.65314, 41.93312], [-87.6532, 41.93445], [-87.65322, 41.93491], [-87.65323, 41.93532], [-87.65327, 41.93603], [-87.65328, 41.93627], [-87.65331, 41.93717], [-87.65333, 41.93763], [-87.65336, 41.93865], [-87.65337, 41.93893], [-87.65337, 41.93939], [-87.65338, 41.93975], [-87.65345, 41.94218], [-87.65347, 41.94238], [-87.65351, 41.94257], [-87.65355, 41.94269], [-87.65361, 41.9428], [-87.65367, 41.94292], [-87.65375, 41.94306], [-87.65382, 41.94319], [-87.65392, 41.94331], [-87.654, 41.94342], [-87.6541, 41.94351], [-87.65425, 41.94364], [-87.65441, 41.94375], [-87.65454, 41.9438], [-87.6547, 41.94386], [-87.65488, 41.9439], [-87.65503, 41.94393], [-87.65521, 41.94394], [-87.6555, 41.94394], [-87.65608, 41.94393], [-87.65767, 41.94391], [-87.6591, 41.94391], [-87.66361, 41.94381], [-87.66508, 41.94379], [-87.66585, 41.94378], [-87.66749, 41.94377], [-87.66938, 41.94373], [-87.67088, 41.94371], [-87.6715, 41.9437], [-87.67234, 41.94369], [-87.67263, 41.94369], [-87.67289, 41.9437], [-87.67311, 41.94373], [-87.67334, 41.94376], [-87.67348, 41.9438], [-87.67367, 41.94386], [-87.67386, 41.94393], [-87.67405, 41.94404], [-87.67419, 41.94414], [-87.6743, 41.94424], [-87.67442, 41.94438], [-87.6745, 41.94455], [-87.67457, 41.94474], [-87.67463, 41.94494], [-87.67466, 41.94513], [-87.67468, 41.94596], [-87.67474, 41.94703], [-87.67476, 41.94859], [-87.67479, 41.94959], [-87.67484, 41.95101], [-87.67485, 41.95202], [-87.67487, 41.95302], [-87.67491, 41.95392], [-87.67496, 41.95452], [-87.67497, 41.95513], [-87.67501, 41.95666], [-87.67505, 41.95798], [-87.67513, 41.96077], [-87.67517, 41.96175], [-87.67519, 41.96371], [-87.6752, 41.96434], [-87.67521, 41.96457], [-87.67522, 41.96477], [-87.67523, 41.96491], [-87.67524, 41.96503], [-87.6753, 41.96519], [-87.67539, 41.96536], [-87.67544, 41.96547], [-87.67557, 41.96565], [-87.6757, 41.96579], [-87.67589, 41.96596], [-87.67613, 41.96612], [-87.67638, 41.96623], [-87.67665, 41.96632], [-87.67695, 41.96638], [-87.67722, 41.9664], [-87.67741, 41.96641], [-87.67766, 41.96642], [-87.67863, 41.96641], [-87.68034, 41.96638], [-87.68159, 41.96636], [-87.68271, 41.96635], [-87.68399, 41.96632], [-87.68545, 41.96631], [-87.68718, 41.96628], [-87.6885, 41.96625], [-87.68946, 41.96625], [-87.69026, 41.96624], [-87.69145, 41.96623], [-87.69411, 41.96621], [-87.69502, 41.96621], [-87.69675, 41.9662], [-87.69789, 41.96618], [-87.69873, 41.96616], [-87.69954, 41.96615], [-87.70075, 41.96615], [-87.70166, 41.96615], [-87.70267, 41.96614], [-87.70399, 41.96613], [-87.70645, 41.96612], [-87.70763, 41.96611], [-87.70884, 41.96609], [-87.71027, 41.96607], [-87.71108, 41.96607], [-87.71173, 41.96606], [-87.71219, 41.96605], [-87.7124, 41.96605], [-87.71255, 41.96605], [-87.71268, 41.96605], [-87.7128, 41.96607], [-87.71292, 41.96611], [-87.71298, 41.96615], [-87.71303, 41.96621], [-87.71309, 41.9663], [-87.7131, 41.96635], [-87.71311, 41.96643], [-87.71312, 41.96667], [-87.71314, 41.96793]]}' diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_transform.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_transform.py new file mode 100644 index 0000000000000000000000000000000000000000..26a6f85486d2421c2ff66d95ec5a25f6c9b9ddb5 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_transform.py @@ -0,0 +1,80 @@ +import unittest + +import pytest + +from shapely import geometry +from shapely.ops import transform + + +class IdentityTestCase(unittest.TestCase): + """New geometry/coordseq method 'xy' makes numpy interop easier""" + + def func(self, x, y, z=None): + return tuple(c for c in [x, y, z] if c) + + def test_empty(self): + g = geometry.Point() + h = transform(self.func, g) + assert h.is_empty + + def test_point(self): + g = geometry.Point(0, 1) + h = transform(self.func, g) + assert h.geom_type == "Point" + assert list(h.coords) == [(0, 1)] + + def test_line(self): + g = geometry.LineString([(0, 1), (2, 3)]) + h = transform(self.func, g) + assert h.geom_type == "LineString" + assert list(h.coords) == [(0, 1), (2, 3)] + + def test_linearring(self): + g = geometry.LinearRing([(0, 1), (2, 3), (2, 2), (0, 1)]) + h = transform(self.func, g) + assert h.geom_type == "LinearRing" + assert list(h.coords) == [(0, 1), (2, 3), (2, 2), (0, 1)] + + def test_polygon(self): + g = geometry.Point(0, 1).buffer(1.0) + h = transform(self.func, g) + assert h.geom_type == "Polygon" + assert g.area == pytest.approx(h.area) + + def test_multipolygon(self): + g = geometry.MultiPoint([(0, 1), (0, 4)]).buffer(1.0) + h = transform(self.func, g) + assert h.geom_type == "MultiPolygon" + assert g.area == pytest.approx(h.area) + + +class LambdaTestCase(unittest.TestCase): + """New geometry/coordseq method 'xy' makes numpy interop easier""" + + def test_point(self): + g = geometry.Point(0, 1) + h = transform(lambda x, y, z=None: (x + 1.0, y + 1.0), g) + assert h.geom_type == "Point" + assert list(h.coords) == [(1.0, 2.0)] + + def test_line(self): + g = geometry.LineString([(0, 1), (2, 3)]) + h = transform(lambda x, y, z=None: (x + 1.0, y + 1.0), g) + assert h.geom_type == "LineString" + assert list(h.coords) == [(1.0, 2.0), (3.0, 4.0)] + + def test_polygon(self): + g = geometry.Point(0, 1).buffer(1.0) + h = transform(lambda x, y, z=None: (x + 1.0, y + 1.0), g) + assert h.geom_type == "Polygon" + assert g.area == pytest.approx(h.area) + assert h.centroid.x == pytest.approx(1.0) + assert h.centroid.y == pytest.approx(2.0) + + def test_multipolygon(self): + g = geometry.MultiPoint([(0, 1), (0, 4)]).buffer(1.0) + h = transform(lambda x, y, z=None: (x + 1.0, y + 1.0), g) + assert h.geom_type == "MultiPolygon" + assert g.area == pytest.approx(h.area) + assert h.centroid.x == pytest.approx(1.0) + assert h.centroid.y == pytest.approx(3.5) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_union.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_union.py new file mode 100644 index 0000000000000000000000000000000000000000..e332d32169eb5f0dea6fcb1d5ce768a3c851e132 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_union.py @@ -0,0 +1,70 @@ +import random +import unittest +from functools import partial +from itertools import islice + +import pytest + +from shapely.errors import ShapelyDeprecationWarning +from shapely.geometry import MultiPolygon, Point +from shapely.ops import cascaded_union, unary_union + + +def halton(base): + """Returns an iterator over an infinite Halton sequence""" + + def value(index): + result = 0.0 + f = 1.0 / base + i = index + while i > 0: + result += f * (i % base) + i = i // base + f = f / base + return result + + i = 1 + while i > 0: + yield value(i) + i += 1 + + +class UnionTestCase(unittest.TestCase): + def test_cascaded_union(self): + # cascaded_union is deprecated, as it was superseded by unary_union + + # Use a partial function to make 100 points uniformly distributed + # in a 40x40 box centered on 0,0. + + r = partial(random.uniform, -20.0, 20.0) + points = [Point(r(), r()) for i in range(100)] + + # Buffer the points, producing 100 polygon spots + spots = [p.buffer(2.5) for p in points] + + # Perform a cascaded union of the polygon spots, dissolving them + # into a collection of polygon patches + with pytest.warns(ShapelyDeprecationWarning, match="is deprecated"): + u = cascaded_union(spots) + assert u.geom_type in ("Polygon", "MultiPolygon") + + def setUp(self): + # Instead of random points, use deterministic, pseudo-random Halton + # sequences for repeatability sake. + self.coords = zip( + list(islice(halton(5), 20, 120)), + list(islice(halton(7), 20, 120)), + ) + + def test_unary_union(self): + patches = [Point(xy).buffer(0.05) for xy in self.coords] + u = unary_union(patches) + assert u.geom_type == "MultiPolygon" + assert u.area == pytest.approx(0.718572540569) + + def test_unary_union_multi(self): + # Test of multipart input based on comment by @schwehr at + # https://github.com/shapely/shapely/issues/47#issuecomment-21809308 + patches = MultiPolygon([Point(xy).buffer(0.05) for xy in self.coords]) + assert unary_union(patches).area == pytest.approx(0.71857254056) + assert unary_union([patches, patches]).area == pytest.approx(0.71857254056) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_validation.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_validation.py new file mode 100644 index 0000000000000000000000000000000000000000..9ec8663c7061904069b0a5d41f24e1d31619260c --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_validation.py @@ -0,0 +1,9 @@ +import unittest + +from shapely.geometry import Point +from shapely.validation import explain_validity + + +class ValidationTestCase(unittest.TestCase): + def test_valid(self): + assert explain_validity(Point(0, 0)) == "Valid Geometry" diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_vectorized.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_vectorized.py new file mode 100644 index 0000000000000000000000000000000000000000..0776d2ab3244fc110dbc3cc5b9047ce0e3c47448 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_vectorized.py @@ -0,0 +1,105 @@ +import unittest + +import numpy as np + +from shapely.geometry import box, MultiPolygon, Point + + +class VectorizedContainsTestCase(unittest.TestCase): + def assertContainsResults(self, geom, x, y): + from shapely.vectorized import contains + + result = contains(geom, x, y) + x = np.asanyarray(x) + y = np.asanyarray(y) + + self.assertIsInstance(result, np.ndarray) + self.assertEqual(result.dtype, bool) + + result_flat = result.flat + x_flat, y_flat = x.flat, y.flat + + # Do the equivalent operation, only slowly, comparing the result + # as we go. + for idx in range(x.size): + assert result_flat[idx] == geom.contains(Point(x_flat[idx], y_flat[idx])) + return result + + def construct_torus(self): + point = Point(0, 0) + return point.buffer(5).symmetric_difference(point.buffer(2.5)) + + def test_contains_poly(self): + y, x = np.mgrid[-10:10:5j], np.mgrid[-5:15:5j] + self.assertContainsResults(self.construct_torus(), x, y) + + def test_contains_point(self): + y, x = np.mgrid[-10:10:5j], np.mgrid[-5:15:5j] + self.assertContainsResults(Point(x[0], y[0]), x, y) + + def test_contains_linestring(self): + y, x = np.mgrid[-10:10:5j], np.mgrid[-5:15:5j] + self.assertContainsResults(Point(x[0], y[0]), x, y) + + def test_contains_multipoly(self): + y, x = np.mgrid[-10:10:5j], np.mgrid[-5:15:5j] + # Construct a geometry of the torus cut in half vertically. + cut_poly = box(-1, -10, -2.5, 10) + geom = self.construct_torus().difference(cut_poly) + assert isinstance(geom, MultiPolygon) + self.assertContainsResults(geom, x, y) + + def test_y_array_order(self): + y, x = np.mgrid[-10:10:5j, -5:15:5j] + y = y.copy("f") + self.assertContainsResults(self.construct_torus(), x, y) + + def test_x_array_order(self): + y, x = np.mgrid[-10:10:5j, -5:15:5j] + x = x.copy("f") + self.assertContainsResults(self.construct_torus(), x, y) + + def test_xy_array_order(self): + y, x = np.mgrid[-10:10:5j, -5:15:5j] + x = x.copy("f") + y = y.copy("f") + result = self.assertContainsResults(self.construct_torus(), x, y) + # Preserve the order + assert result.flags["F_CONTIGUOUS"] + + def test_array_dtype(self): + y, x = np.mgrid[-10:10:5j], np.mgrid[-5:15:5j] + x = x.astype(np.int16) + self.assertContainsResults(self.construct_torus(), x, y) + + def test_array_2d(self): + y, x = np.mgrid[-10:10:15j, -5:15:16j] + result = self.assertContainsResults(self.construct_torus(), x, y) + assert result.shape == x.shape + + def test_shapely_xy_attr_contains(self): + g = Point(0, 0).buffer(10.0) + self.assertContainsResults(self.construct_torus(), *g.exterior.xy) + + +class VectorizedTouchesTestCase(unittest.TestCase): + def test_touches(self): + from shapely.vectorized import touches + + y, x = np.mgrid[-2:3:6j, -1:3:5j] + geom = box(0, -1, 2, 2) + result = touches(geom, x, y) + expected = np.array( + [ + [False, False, False, False, False], + [False, True, True, True, False], + [False, True, False, True, False], + [False, True, False, True, False], + [False, True, True, True, False], + [False, False, False, False, False], + ], + dtype=bool, + ) + from numpy.testing import assert_array_equal + + assert_array_equal(result, expected) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_wkb.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_wkb.py new file mode 100644 index 0000000000000000000000000000000000000000..8df13666c8023081f9c10efc93f3d6f462d5a4c4 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_wkb.py @@ -0,0 +1,193 @@ +import binascii +import math +import struct +import sys + +import pytest + +from shapely import wkt +from shapely.geometry import Point +from shapely.geos import geos_version +from shapely.tests.legacy.conftest import shapely20_todo +from shapely.wkb import dump, dumps, load, loads + + +@pytest.fixture(scope="module") +def some_point(): + return Point(1.2, 3.4) + + +def bin2hex(value): + return binascii.b2a_hex(value).upper().decode("utf-8") + + +def hex2bin(value): + return binascii.a2b_hex(value) + + +def hostorder(fmt, value): + """Re-pack a hex WKB value to native endianness if needed + + This routine does not understand WKB format, so it must be provided a + struct module format string, without initial indicator character ("@=<>!"), + which will be interpreted as big- or little-endian with standard sizes + depending on the endian flag in the first byte of the value. + """ + + if fmt and fmt[0] in "@=<>!": + raise ValueError("Initial indicator character, one of @=<>!, in fmt") + if not fmt or fmt[0] not in "cbB": + raise ValueError("Missing endian flag in fmt") + + (hexendian,) = struct.unpack(fmt[0], hex2bin(value[:2])) + hexorder = {0: ">", 1: "<"}[hexendian] + sysorder = {"little": "<", "big": ">"}[sys.byteorder] + if hexorder == sysorder: + return value # Nothing to do + + return bin2hex( + struct.pack( + sysorder + fmt, + {">": 0, "<": 1}[sysorder], + *struct.unpack(hexorder + fmt, hex2bin(value))[1:] + ) + ) + + +def test_dumps_srid(some_point): + result = dumps(some_point) + assert bin2hex(result) == hostorder( + "BIdd", "0101000000333333333333F33F3333333333330B40" + ) + result = dumps(some_point, srid=4326) + assert bin2hex(result) == hostorder( + "BIIdd", "0101000020E6100000333333333333F33F3333333333330B40" + ) + + +def test_dumps_endianness(some_point): + result = dumps(some_point) + assert bin2hex(result) == hostorder( + "BIdd", "0101000000333333333333F33F3333333333330B40" + ) + result = dumps(some_point, big_endian=False) + assert bin2hex(result) == "0101000000333333333333F33F3333333333330B40" + result = dumps(some_point, big_endian=True) + assert bin2hex(result) == "00000000013FF3333333333333400B333333333333" + + +def test_dumps_hex(some_point): + result = dumps(some_point, hex=True) + assert result == hostorder("BIdd", "0101000000333333333333F33F3333333333330B40") + + +def test_loads_srid(): + # load a geometry which includes an srid + geom = loads(hex2bin("0101000020E6100000333333333333F33F3333333333330B40")) + assert isinstance(geom, Point) + assert geom.coords[:] == [(1.2, 3.4)] + # by default srid is not exported + result = dumps(geom) + assert bin2hex(result) == hostorder( + "BIdd", "0101000000333333333333F33F3333333333330B40" + ) + # include the srid in the output + result = dumps(geom, include_srid=True) + assert bin2hex(result) == hostorder( + "BIIdd", "0101000020E6100000333333333333F33F3333333333330B40" + ) + # replace geometry srid with another + result = dumps(geom, srid=27700) + assert bin2hex(result) == hostorder( + "BIIdd", "0101000020346C0000333333333333F33F3333333333330B40" + ) + + +def test_loads_hex(some_point): + assert loads(dumps(some_point, hex=True), hex=True) == some_point + + +def test_dump_load_binary(some_point, tmpdir): + file = tmpdir.join("test.wkb") + with open(file, "wb") as file_pointer: + dump(some_point, file_pointer) + with open(file, "rb") as file_pointer: + restored = load(file_pointer) + + assert some_point == restored + + +def test_dump_load_hex(some_point, tmpdir): + file = tmpdir.join("test.wkb") + with open(file, "w") as file_pointer: + dump(some_point, file_pointer, hex=True) + with open(file, "r") as file_pointer: + restored = load(file_pointer, hex=True) + + assert some_point == restored + + +# pygeos handles both bytes and str +@shapely20_todo +def test_dump_hex_load_binary(some_point, tmpdir): + """Asserts that reading a binary file as text (hex mode) fails.""" + file = tmpdir.join("test.wkb") + with open(file, "w") as file_pointer: + dump(some_point, file_pointer, hex=True) + + with pytest.raises(TypeError): + with open(file, "rb") as file_pointer: + load(file_pointer) + + +def test_dump_binary_load_hex(some_point, tmpdir): + """Asserts that reading a text file (hex mode) as binary fails.""" + file = tmpdir.join("test.wkb") + with open(file, "wb") as file_pointer: + dump(some_point, file_pointer) + + # TODO(shapely-2.0) on windows this doesn't seem to error with pygeos, + # but you get back a point with garbage coordinates + if sys.platform == "win32": + with open(file, "r") as file_pointer: + restored = load(file_pointer, hex=True) + assert some_point != restored + return + + with pytest.raises((UnicodeEncodeError, UnicodeDecodeError)): + with open(file, "r") as file_pointer: + load(file_pointer, hex=True) + + +requires_geos_380 = pytest.mark.xfail( + geos_version < (3, 8, 0), reason="GEOS >= 3.8.0 is required", strict=True +) + + +@requires_geos_380 +def test_point_empty(): + g = wkt.loads("POINT EMPTY") + result = dumps(g, big_endian=False) + # Use math.isnan for second part of the WKB representation there are + # many byte representations for NaN) + assert result[: -2 * 8] == b"\x01\x01\x00\x00\x00" + coords = struct.unpack("<2d", result[-2 * 8 :]) + assert len(coords) == 2 + assert all(math.isnan(val) for val in coords) + + +# Generally GEOS only serializes this correctly starting with GEOS 3.9 +# For some reason MacOS has different behaviour (it's actually correct for +# older GEOS versions, but not for GEOS 3.8) +@pytest.mark.xfail( + ( + geos_version < (3, 9, 0) + and not (geos_version < (3, 8, 0) and sys.platform == "darwin") + ), + reason="GEOS >= 3.9.0 is required", +) +def test_point_z_empty(): + g = wkt.loads("POINT Z EMPTY") + assert g.wkb_hex == hostorder( + "BIddd", "0101000080000000000000F87F000000000000F87F000000000000F87F" + ) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_wkt.py b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_wkt.py new file mode 100644 index 0000000000000000000000000000000000000000..571ce0ebcb31321230b76431ed224ca707f4339d --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/legacy/test_wkt.py @@ -0,0 +1,61 @@ +from math import pi + +import pytest + +from shapely.geometry import Point +from shapely.wkt import dump, dumps, load, loads + + +@pytest.fixture(scope="module") +def some_point(): + return Point(pi, -pi) + + +@pytest.fixture(scope="module") +def empty_geometry(): + return Point() + + +def test_wkt(some_point): + """.wkt and wkt.dumps() both do not trim by default.""" + assert some_point.wkt == f"POINT ({pi:.15f} {-pi:.15f})" + + +def test_wkt_null(empty_geometry): + assert empty_geometry.wkt == "POINT EMPTY" + + +def test_dump_load(some_point, tmpdir): + file = tmpdir.join("test.wkt") + with open(file, "w") as file_pointer: + dump(some_point, file_pointer) + with open(file, "r") as file_pointer: + restored = load(file_pointer) + + assert some_point == restored + + +def test_dump_load_null_geometry(empty_geometry, tmpdir): + file = tmpdir.join("test.wkt") + with open(file, "w") as file_pointer: + dump(empty_geometry, file_pointer) + with open(file, "r") as file_pointer: + restored = load(file_pointer) + + # This is does not work with __eq__(): + assert empty_geometry.equals(restored) + + +def test_dumps_loads(some_point): + assert dumps(some_point) == f"POINT ({pi:.16f} {-pi:.16f})" + assert loads(dumps(some_point)) == some_point + + +def test_dumps_loads_null_geometry(empty_geometry): + assert dumps(empty_geometry) == "POINT EMPTY" + # This is does not work with __eq__(): + assert loads(dumps(empty_geometry)).equals(empty_geometry) + + +def test_dumps_precision(some_point): + assert dumps(some_point, rounding_precision=4) == f"POINT ({pi:.4f} {-pi:.4f})" diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/test_constructive.py b/vllm/lib/python3.10/site-packages/shapely/tests/test_constructive.py new file mode 100644 index 0000000000000000000000000000000000000000..4ed7c8c7a286b2c09b7b50235bb1ada1a2b18c9f --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/test_constructive.py @@ -0,0 +1,1008 @@ +import numpy as np +import pytest + +import shapely +from shapely import ( + Geometry, + GeometryCollection, + GEOSException, + LinearRing, + LineString, + MultiLineString, + MultiPoint, + MultiPolygon, + Point, + Polygon, +) +from shapely.testing import assert_geometries_equal +from shapely.tests.common import ( + all_types, + ArrayLike, + empty, + empty_line_string, + empty_point, + empty_polygon, + ignore_invalid, + line_string, + multi_point, + point, + point_z, +) + +CONSTRUCTIVE_NO_ARGS = ( + shapely.boundary, + shapely.centroid, + shapely.convex_hull, + pytest.param( + shapely.concave_hull, + marks=pytest.mark.skipif( + shapely.geos_version < (3, 11, 0), reason="GEOS < 3.11" + ), + ), + shapely.envelope, + shapely.extract_unique_points, + shapely.node, + shapely.normalize, + shapely.point_on_surface, +) + +CONSTRUCTIVE_FLOAT_ARG = ( + shapely.buffer, + shapely.offset_curve, + shapely.delaunay_triangles, + shapely.simplify, + shapely.voronoi_polygons, +) + + +@pytest.mark.parametrize("geometry", all_types) +@pytest.mark.parametrize("func", CONSTRUCTIVE_NO_ARGS) +def test_no_args_array(geometry, func): + actual = func([geometry, geometry]) + assert actual.shape == (2,) + assert actual[0] is None or isinstance(actual[0], Geometry) + + +@pytest.mark.parametrize("geometry", all_types) +@pytest.mark.parametrize("func", CONSTRUCTIVE_FLOAT_ARG) +def test_float_arg_array(geometry, func): + if ( + func is shapely.offset_curve + and shapely.get_type_id(geometry) not in [1, 2] + and shapely.geos_version < (3, 11, 0) + ): + with pytest.raises(GEOSException, match="only accept linestrings"): + func([geometry, geometry], 0.0) + return + # voronoi_polygons emits an "invalid" warning when supplied with an empty + # point (see https://github.com/libgeos/geos/issues/515) + with ignore_invalid( + func is shapely.voronoi_polygons + and shapely.get_type_id(geometry) == 0 + and shapely.geos_version < (3, 12, 0) + ): + actual = func([geometry, geometry], 0.0) + assert actual.shape == (2,) + assert isinstance(actual[0], Geometry) + + +@pytest.mark.parametrize("geometry", all_types) +@pytest.mark.parametrize("reference", all_types) +def test_snap_array(geometry, reference): + actual = shapely.snap([geometry, geometry], [reference, reference], tolerance=1.0) + assert actual.shape == (2,) + assert isinstance(actual[0], Geometry) + + +@pytest.mark.parametrize("func", CONSTRUCTIVE_NO_ARGS) +def test_no_args_missing(func): + actual = func(None) + assert actual is None + + +@pytest.mark.parametrize("func", CONSTRUCTIVE_FLOAT_ARG) +def test_float_arg_missing(func): + actual = func(None, 1.0) + assert actual is None + + +@pytest.mark.parametrize("geometry", all_types) +@pytest.mark.parametrize("func", CONSTRUCTIVE_FLOAT_ARG) +def test_float_arg_nan(geometry, func): + actual = func(geometry, float("nan")) + assert actual is None + + +def test_buffer_cap_style_invalid(): + with pytest.raises(ValueError, match="'invalid' is not a valid option"): + shapely.buffer(point, 1, cap_style="invalid") + + +def test_buffer_join_style_invalid(): + with pytest.raises(ValueError, match="'invalid' is not a valid option"): + shapely.buffer(point, 1, join_style="invalid") + + +def test_snap_none(): + actual = shapely.snap(None, point, tolerance=1.0) + assert actual is None + + +@pytest.mark.parametrize("geometry", all_types) +def test_snap_nan_float(geometry): + actual = shapely.snap(geometry, point, tolerance=np.nan) + assert actual is None + + +@pytest.mark.skipif(shapely.geos_version < (3, 8, 0), reason="GEOS < 3.8") +def test_build_area_none(): + actual = shapely.build_area(None) + assert actual is None + + +@pytest.mark.skipif(shapely.geos_version < (3, 8, 0), reason="GEOS < 3.8") +@pytest.mark.parametrize( + "geom,expected", + [ + (point, empty), # a point has no area + (line_string, empty), # a line string has no area + # geometry collection of two polygons are combined into one + ( + GeometryCollection( + [ + Polygon([(0, 0), (0, 3), (3, 3), (3, 0), (0, 0)]), + Polygon([(1, 1), (2, 2), (1, 2), (1, 1)]), + ] + ), + Polygon( + [(0, 0), (0, 3), (3, 3), (3, 0), (0, 0)], + holes=[[(1, 1), (2, 2), (1, 2), (1, 1)]], + ), + ), + (empty, empty), + ([empty], [empty]), + ], +) +def test_build_area(geom, expected): + actual = shapely.build_area(geom) + assert actual is not expected + assert actual == expected + + +@pytest.mark.skipif(shapely.geos_version < (3, 8, 0), reason="GEOS < 3.8") +def test_make_valid_none(): + actual = shapely.make_valid(None) + assert actual is None + + +@pytest.mark.skipif(shapely.geos_version < (3, 8, 0), reason="GEOS < 3.8") +@pytest.mark.parametrize( + "geom,expected", + [ + (point, point), # a valid geometry stays the same (but is copied) + # an L shaped polygon without area is converted to a multilinestring + ( + Polygon([(0, 0), (1, 1), (1, 2), (1, 1), (0, 0)]), + MultiLineString([((1, 1), (1, 2)), ((0, 0), (1, 1))]), + ), + # a polygon with self-intersection (bowtie) is converted into polygons + ( + Polygon([(0, 0), (2, 2), (2, 0), (0, 2), (0, 0)]), + MultiPolygon( + [ + Polygon([(1, 1), (2, 2), (2, 0), (1, 1)]), + Polygon([(0, 0), (0, 2), (1, 1), (0, 0)]), + ] + ), + ), + (empty, empty), + ([empty], [empty]), + ], +) +def test_make_valid(geom, expected): + actual = shapely.make_valid(geom) + assert actual is not expected + # normalize needed to handle variation in output across GEOS versions + assert shapely.normalize(actual) == expected + + +@pytest.mark.skipif(shapely.geos_version < (3, 8, 0), reason="GEOS < 3.8") +@pytest.mark.parametrize( + "geom,expected", + [ + (all_types, all_types), + # first polygon is valid, second polygon has self-intersection + ( + [ + Polygon([(0, 0), (2, 2), (0, 2), (0, 0)]), + Polygon([(0, 0), (2, 2), (2, 0), (0, 2), (0, 0)]), + ], + [ + Polygon([(0, 0), (2, 2), (0, 2), (0, 0)]), + MultiPolygon( + [ + Polygon([(1, 1), (0, 0), (0, 2), (1, 1)]), + Polygon([(1, 1), (2, 2), (2, 0), (1, 1)]), + ] + ), + ], + ), + ([point, None, empty], [point, None, empty]), + ], +) +def test_make_valid_1d(geom, expected): + actual = shapely.make_valid(geom) + # normalize needed to handle variation in output across GEOS versions + assert np.all(shapely.normalize(actual) == shapely.normalize(expected)) + + +@pytest.mark.parametrize( + "geom,expected", + [ + (point, point), # a point is always in normalized form + # order coordinates of linestrings and parts of multi-linestring + ( + MultiLineString([((1, 1), (0, 0)), ((1, 1), (1, 2))]), + MultiLineString([((1, 1), (1, 2)), ((0, 0), (1, 1))]), + ), + ], +) +def test_normalize(geom, expected): + actual = shapely.normalize(geom) + assert actual == expected + + +def test_offset_curve_empty(): + with ignore_invalid(shapely.geos_version < (3, 12, 0)): + # Empty geometries emit an "invalid" warning + # (see https://github.com/libgeos/geos/issues/515) + actual = shapely.offset_curve(empty_line_string, 2.0) + assert shapely.is_empty(actual) + + +def test_offset_curve_distance_array(): + # check that kwargs are passed through + result = shapely.offset_curve([line_string, line_string], [-2.0, -3.0]) + assert result[0] == shapely.offset_curve(line_string, -2.0) + assert result[1] == shapely.offset_curve(line_string, -3.0) + + +def test_offset_curve_kwargs(): + # check that kwargs are passed through + result1 = shapely.offset_curve( + line_string, -2.0, quad_segs=2, join_style="mitre", mitre_limit=2.0 + ) + result2 = shapely.offset_curve(line_string, -2.0) + assert result1 != result2 + + +def test_offset_curve_non_scalar_kwargs(): + msg = "only accepts scalar values" + with pytest.raises(TypeError, match=msg): + shapely.offset_curve([line_string, line_string], 1, quad_segs=np.array([8, 9])) + + with pytest.raises(TypeError, match=msg): + shapely.offset_curve( + [line_string, line_string], 1, join_style=["round", "bevel"] + ) + + with pytest.raises(TypeError, match=msg): + shapely.offset_curve([line_string, line_string], 1, mitre_limit=[5.0, 6.0]) + + +def test_offset_curve_join_style_invalid(): + with pytest.raises(ValueError, match="'invalid' is not a valid option"): + shapely.offset_curve(line_string, 1.0, join_style="invalid") + + +@pytest.mark.skipif(shapely.geos_version < (3, 11, 0), reason="GEOS < 3.11") +@pytest.mark.parametrize( + "geom,expected", + [ + (LineString([(0, 0), (0, 0), (1, 0)]), LineString([(0, 0), (1, 0)])), + ( + LinearRing([(0, 0), (1, 2), (1, 2), (1, 3), (0, 0)]), + LinearRing([(0, 0), (1, 2), (1, 3), (0, 0)]), + ), + ( + Polygon([(0, 0), (0, 0), (1, 0), (1, 1), (1, 0), (0, 0)]), + Polygon([(0, 0), (1, 0), (1, 1), (1, 0), (0, 0)]), + ), + ( + Polygon( + [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)], + holes=[[(2, 2), (2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]], + ), + Polygon( + [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)], + holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]], + ), + ), + ( + MultiPolygon( + [ + Polygon([(0, 0), (0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]), + Polygon([(2, 2), (2, 2), (2, 3), (3, 3), (3, 2), (2, 2)]), + ] + ), + MultiPolygon( + [ + Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]), + Polygon([(2, 2), (2, 3), (3, 3), (3, 2), (2, 2)]), + ] + ), + ), + # points are unchanged + (point, point), + (point_z, point_z), + (multi_point, multi_point), + # empty geometries are unchanged + (empty_point, empty_point), + (empty_line_string, empty_line_string), + (empty, empty), + (empty_polygon, empty_polygon), + ], +) +def test_remove_repeated_points(geom, expected): + assert_geometries_equal(shapely.remove_repeated_points(geom, 0), expected) + + +@pytest.mark.skipif(shapely.geos_version < (3, 12, 0), reason="GEOS < 3.12") +@pytest.mark.parametrize( + "geom, tolerance", [[Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]), 2]] +) +def test_remove_repeated_points_invalid_result(geom, tolerance): + # Requiring GEOS 3.12 instead of 3.11 + # (GEOS 3.11 had a bug causing this to intermittently not fail) + with pytest.raises(shapely.GEOSException, match="Invalid number of points"): + shapely.remove_repeated_points(geom, tolerance) + + +@pytest.mark.skipif(shapely.geos_version < (3, 11, 0), reason="GEOS < 3.11") +def test_remove_repeated_points_none(): + assert shapely.remove_repeated_points(None, 1) is None + assert shapely.remove_repeated_points([None], 1).tolist() == [None] + + geometry = LineString([(0, 0), (0, 0), (1, 1)]) + expected = LineString([(0, 0), (1, 1)]) + result = shapely.remove_repeated_points([None, geometry], 1) + assert result[0] is None + assert_geometries_equal(result[1], expected) + + +@pytest.mark.skipif(shapely.geos_version < (3, 11, 0), reason="GEOS < 3.11") +@pytest.mark.parametrize("geom, tolerance", [("Not a geometry", 1), (1, 1)]) +def test_remove_repeated_points_invalid_type(geom, tolerance): + with pytest.raises(TypeError, match="One of the arguments is of incorrect type"): + shapely.remove_repeated_points(geom, tolerance) + + +@pytest.mark.skipif(shapely.geos_version < (3, 7, 0), reason="GEOS < 3.7") +@pytest.mark.parametrize( + "geom,expected", + [ + (LineString([(0, 0), (1, 2)]), LineString([(1, 2), (0, 0)])), + ( + LinearRing([(0, 0), (1, 2), (1, 3), (0, 0)]), + LinearRing([(0, 0), (1, 3), (1, 2), (0, 0)]), + ), + ( + Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]), + Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]), + ), + ( + Polygon( + [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)], + holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]], + ), + Polygon( + [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)], + holes=[[(2, 2), (4, 2), (4, 4), (2, 4), (2, 2)]], + ), + ), + pytest.param( + MultiLineString([[(0, 0), (1, 2)], [(3, 3), (4, 4)]]), + MultiLineString([[(1, 2), (0, 0)], [(4, 4), (3, 3)]]), + marks=pytest.mark.skipif( + shapely.geos_version < (3, 8, 1), reason="GEOS < 3.8.1" + ), + ), + ( + MultiPolygon( + [ + Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]), + Polygon([(2, 2), (2, 3), (3, 3), (3, 2), (2, 2)]), + ] + ), + MultiPolygon( + [ + Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]), + Polygon([(2, 2), (3, 2), (3, 3), (2, 3), (2, 2)]), + ] + ), + ), + # points are unchanged + (point, point), + (point_z, point_z), + (multi_point, multi_point), + # empty geometries are unchanged + (empty_point, empty_point), + (empty_line_string, empty_line_string), + (empty, empty), + (empty_polygon, empty_polygon), + ], +) +def test_reverse(geom, expected): + assert_geometries_equal(shapely.reverse(geom), expected) + + +@pytest.mark.skipif(shapely.geos_version < (3, 7, 0), reason="GEOS < 3.7") +def test_reverse_none(): + assert shapely.reverse(None) is None + assert shapely.reverse([None]).tolist() == [None] + + geometry = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]) + expected = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]) + result = shapely.reverse([None, geometry]) + assert result[0] is None + assert_geometries_equal(result[1], expected) + + +@pytest.mark.skipif(shapely.geos_version < (3, 7, 0), reason="GEOS < 3.7") +@pytest.mark.parametrize("geom", ["Not a geometry", 1]) +def test_reverse_invalid_type(geom): + with pytest.raises(TypeError, match="One of the arguments is of incorrect type"): + shapely.reverse(geom) + + +@pytest.mark.parametrize( + "geom,expected", + [ + # Point outside + (Point(0, 0), GeometryCollection()), + # Point inside + (Point(15, 15), Point(15, 15)), + # Point on boundary + (Point(15, 10), GeometryCollection()), + # Line outside + (LineString([(0, 0), (-5, 5)]), GeometryCollection()), + # Line inside + (LineString([(15, 15), (16, 15)]), LineString([(15, 15), (16, 15)])), + # Line on boundary + (LineString([(10, 15), (10, 10), (15, 10)]), GeometryCollection()), + # Line splitting rectangle + (LineString([(10, 5), (25, 20)]), LineString([(15, 10), (20, 15)])), + ], +) +def test_clip_by_rect(geom, expected): + actual = shapely.clip_by_rect(geom, 10, 10, 20, 20) + assert_geometries_equal(actual, expected) + + +@pytest.mark.parametrize( + "geom, rect, expected", + [ + # Polygon hole (CCW) fully on rectangle boundary""" + ( + Polygon( + ((0, 0), (0, 30), (30, 30), (30, 0), (0, 0)), + holes=[((10, 10), (20, 10), (20, 20), (10, 20), (10, 10))], + ), + (10, 10, 20, 20), + GeometryCollection(), + ), + # Polygon hole (CW) fully on rectangle boundary""" + ( + Polygon( + ((0, 0), (0, 30), (30, 30), (30, 0), (0, 0)), + holes=[((10, 10), (10, 20), (20, 20), (20, 10), (10, 10))], + ), + (10, 10, 20, 20), + GeometryCollection(), + ), + # Polygon fully within rectangle""" + ( + Polygon( + ((1, 1), (1, 30), (30, 30), (30, 1), (1, 1)), + holes=[((10, 10), (20, 10), (20, 20), (10, 20), (10, 10))], + ), + (0, 0, 40, 40), + Polygon( + ((1, 1), (1, 30), (30, 30), (30, 1), (1, 1)), + holes=[((10, 10), (20, 10), (20, 20), (10, 20), (10, 10))], + ), + ), + # Polygon overlapping rectanglez + ( + Polygon( + [(0, 0), (0, 30), (30, 30), (30, 0), (0, 0)], + holes=[[(10, 10), (20, 10), (20, 20), (10, 20), (10, 10)]], + ), + (5, 5, 15, 15), + Polygon([(5, 5), (5, 15), (10, 15), (10, 10), (15, 10), (15, 5), (5, 5)]), + ), + ], +) +def test_clip_by_rect_polygon(geom, rect, expected): + actual = shapely.clip_by_rect(geom, *rect) + assert_geometries_equal(actual, expected) + + +@pytest.mark.parametrize("geometry", all_types) +def test_clip_by_rect_array(geometry): + actual = shapely.clip_by_rect([geometry, geometry], 0.0, 0.0, 1.0, 1.0) + assert actual.shape == (2,) + assert actual[0] is None or isinstance(actual[0], Geometry) + + +def test_clip_by_rect_missing(): + actual = shapely.clip_by_rect(None, 0, 0, 1, 1) + assert actual is None + + +@pytest.mark.parametrize("geom", [empty, empty_line_string, empty_polygon]) +def test_clip_by_rect_empty(geom): + # TODO empty point + actual = shapely.clip_by_rect(geom, 0, 0, 1, 1) + assert actual == GeometryCollection() + + +def test_clip_by_rect_non_scalar_kwargs(): + msg = "only accepts scalar values" + with pytest.raises(TypeError, match=msg): + shapely.clip_by_rect([line_string, line_string], 0, 0, 1, np.array([0, 1])) + + +def test_polygonize(): + lines = [ + LineString([(0, 0), (1, 1)]), + LineString([(0, 0), (0, 1)]), + LineString([(0, 1), (1, 1)]), + LineString([(1, 1), (1, 0)]), + LineString([(1, 0), (0, 0)]), + LineString([(5, 5), (6, 6)]), + Point(0, 0), + None, + ] + result = shapely.polygonize(lines) + assert shapely.get_type_id(result) == 7 # GeometryCollection + expected = GeometryCollection( + [ + Polygon([(0, 0), (1, 1), (1, 0), (0, 0)]), + Polygon([(1, 1), (0, 0), (0, 1), (1, 1)]), + ] + ) + assert result == expected + + +def test_polygonize_array(): + lines = [ + LineString([(0, 0), (1, 1)]), + LineString([(0, 0), (0, 1)]), + LineString([(0, 1), (1, 1)]), + ] + expected = GeometryCollection([Polygon([(1, 1), (0, 0), (0, 1), (1, 1)])]) + result = shapely.polygonize(np.array(lines)) + assert isinstance(result, shapely.Geometry) + assert result == expected + + result = shapely.polygonize(np.array([lines])) + assert isinstance(result, np.ndarray) + assert result.shape == (1,) + assert result[0] == expected + + arr = np.array([lines, lines]) + assert arr.shape == (2, 3) + result = shapely.polygonize(arr) + assert isinstance(result, np.ndarray) + assert result.shape == (2,) + assert result[0] == expected + assert result[1] == expected + + arr = np.array([[lines, lines], [lines, lines], [lines, lines]]) + assert arr.shape == (3, 2, 3) + result = shapely.polygonize(arr) + assert isinstance(result, np.ndarray) + assert result.shape == (3, 2) + for res in result.flatten(): + assert res == expected + + +@pytest.mark.skipif( + np.__version__ < "1.15", + reason="axis keyword for generalized ufunc introduced in np 1.15", +) +def test_polygonize_array_axis(): + lines = [ + LineString([(0, 0), (1, 1)]), + LineString([(0, 0), (0, 1)]), + LineString([(0, 1), (1, 1)]), + ] + arr = np.array([lines, lines]) # shape (2, 3) + result = shapely.polygonize(arr, axis=1) + assert result.shape == (2,) + result = shapely.polygonize(arr, axis=0) + assert result.shape == (3,) + + +def test_polygonize_missing(): + # set of geometries that is all missing + result = shapely.polygonize([None, None]) + assert result == GeometryCollection() + + +def test_polygonize_full(): + lines = [ + None, + LineString([(0, 0), (1, 1)]), + LineString([(0, 0), (0, 1)]), + LineString([(0, 1), (1, 1)]), + LineString([(1, 1), (1, 0)]), + None, + LineString([(1, 0), (0, 0)]), + LineString([(5, 5), (6, 6)]), + LineString([(1, 1), (100, 100)]), + Point(0, 0), + None, + ] + result = shapely.polygonize_full(lines) + assert len(result) == 4 + assert all(shapely.get_type_id(geom) == 7 for geom in result) # GeometryCollection + polygons, cuts, dangles, invalid = result + expected_polygons = GeometryCollection( + [ + Polygon([(0, 0), (1, 1), (1, 0), (0, 0)]), + Polygon([(1, 1), (0, 0), (0, 1), (1, 1)]), + ] + ) + assert polygons == expected_polygons + assert cuts == GeometryCollection() + expected_dangles = GeometryCollection( + [LineString([(1, 1), (100, 100)]), LineString([(5, 5), (6, 6)])] + ) + assert dangles == expected_dangles + assert invalid == GeometryCollection() + + +def test_polygonize_full_array(): + lines = [ + LineString([(0, 0), (1, 1)]), + LineString([(0, 0), (0, 1)]), + LineString([(0, 1), (1, 1)]), + ] + expected = GeometryCollection([Polygon([(1, 1), (0, 0), (0, 1), (1, 1)])]) + result = shapely.polygonize_full(np.array(lines)) + assert len(result) == 4 + assert all(isinstance(geom, shapely.Geometry) for geom in result) + assert result[0] == expected + assert all(geom == GeometryCollection() for geom in result[1:]) + + result = shapely.polygonize_full(np.array([lines])) + assert len(result) == 4 + assert all(isinstance(geom, np.ndarray) for geom in result) + assert all(geom.shape == (1,) for geom in result) + assert result[0][0] == expected + assert all(geom[0] == GeometryCollection() for geom in result[1:]) + + arr = np.array([lines, lines]) + assert arr.shape == (2, 3) + result = shapely.polygonize_full(arr) + assert len(result) == 4 + assert all(isinstance(arr, np.ndarray) for arr in result) + assert all(arr.shape == (2,) for arr in result) + assert result[0][0] == expected + assert result[0][1] == expected + assert all(g == GeometryCollection() for geom in result[1:] for g in geom) + + arr = np.array([[lines, lines], [lines, lines], [lines, lines]]) + assert arr.shape == (3, 2, 3) + result = shapely.polygonize_full(arr) + assert len(result) == 4 + assert all(isinstance(arr, np.ndarray) for arr in result) + assert all(arr.shape == (3, 2) for arr in result) + for res in result[0].flatten(): + assert res == expected + for arr in result[1:]: + for res in arr.flatten(): + assert res == GeometryCollection() + + +@pytest.mark.skipif( + np.__version__ < "1.15", + reason="axis keyword for generalized ufunc introduced in np 1.15", +) +def test_polygonize_full_array_axis(): + lines = [ + LineString([(0, 0), (1, 1)]), + LineString([(0, 0), (0, 1)]), + LineString([(0, 1), (1, 1)]), + ] + arr = np.array([lines, lines]) # shape (2, 3) + result = shapely.polygonize_full(arr, axis=1) + assert len(result) == 4 + assert all(arr.shape == (2,) for arr in result) + result = shapely.polygonize_full(arr, axis=0) + assert len(result) == 4 + assert all(arr.shape == (3,) for arr in result) + + +def test_polygonize_full_missing(): + # set of geometries that is all missing + result = shapely.polygonize_full([None, None]) + assert len(result) == 4 + assert all(geom == GeometryCollection() for geom in result) + + +@pytest.mark.skipif(shapely.geos_version < (3, 10, 0), reason="GEOS < 3.10") +@pytest.mark.parametrize("geometry", all_types) +@pytest.mark.parametrize("max_segment_length", [-1, 0]) +def test_segmentize_invalid_max_segment_length(geometry, max_segment_length): + with pytest.raises(GEOSException, match="IllegalArgumentException"): + shapely.segmentize(geometry, max_segment_length=max_segment_length) + + +@pytest.mark.skipif(shapely.geos_version < (3, 10, 0), reason="GEOS < 3.10") +@pytest.mark.parametrize("geometry", all_types) +def test_segmentize_max_segment_length_nan(geometry): + actual = shapely.segmentize(geometry, max_segment_length=np.nan) + assert actual is None + + +@pytest.mark.skipif(shapely.geos_version < (3, 10, 0), reason="GEOS < 3.10") +@pytest.mark.parametrize( + "geometry", [empty, empty_point, empty_line_string, empty_polygon] +) +def test_segmentize_empty(geometry): + actual = shapely.segmentize(geometry, max_segment_length=5) + assert_geometries_equal(actual, geometry) + + +@pytest.mark.skipif(shapely.geos_version < (3, 10, 0), reason="GEOS < 3.10") +@pytest.mark.parametrize("geometry", [point, point_z, multi_point]) +def test_segmentize_no_change(geometry): + actual = shapely.segmentize(geometry, max_segment_length=5) + assert_geometries_equal(actual, geometry) + + +@pytest.mark.skipif(shapely.geos_version < (3, 10, 0), reason="GEOS < 3.10") +def test_segmentize_none(): + assert shapely.segmentize(None, max_segment_length=5) is None + + +@pytest.mark.skipif(shapely.geos_version < (3, 10, 0), reason="GEOS < 3.10") +@pytest.mark.parametrize( + "geometry,tolerance, expected", + [ + # tolerance greater than max edge length, no change + ( + LineString([(0, 0), (0, 10)]), + 20, + LineString([(0, 0), (0, 10)]), + ), + ( + Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]), + 20, + Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]), + ), + # tolerance causes one vertex per segment + ( + LineString([(0, 0), (0, 10)]), + 5, + LineString([(0, 0), (0, 5), (0, 10)]), + ), + ( + Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]), + 5, + Polygon( + [ + (0, 0), + (5, 0), + (10, 0), + (10, 5), + (10, 10), + (5, 10), + (0, 10), + (0, 5), + (0, 0), + ] + ), + ), + # ensure input arrays are broadcast correctly + ( + [ + LineString([(0, 0), (0, 10)]), + LineString([(0, 0), (0, 2)]), + ], + 5, + [ + LineString([(0, 0), (0, 5), (0, 10)]), + LineString([(0, 0), (0, 2)]), + ], + ), + ( + [ + LineString([(0, 0), (0, 10)]), + LineString([(0, 0), (0, 2)]), + ], + [5], + [ + LineString([(0, 0), (0, 5), (0, 10)]), + LineString([(0, 0), (0, 2)]), + ], + ), + ( + [ + LineString([(0, 0), (0, 10)]), + LineString([(0, 0), (0, 2)]), + ], + [5, 1.5], + [ + LineString([(0, 0), (0, 5), (0, 10)]), + LineString([(0, 0), (0, 1), (0, 2)]), + ], + ), + ], +) +def test_segmentize(geometry, tolerance, expected): + actual = shapely.segmentize(geometry, tolerance) + assert_geometries_equal(actual, expected) + + +@pytest.mark.skipif(shapely.geos_version < (3, 8, 0), reason="GEOS < 3.8") +@pytest.mark.parametrize("geometry", all_types) +def test_minimum_bounding_circle_all_types(geometry): + actual = shapely.minimum_bounding_circle([geometry, geometry]) + assert actual.shape == (2,) + assert actual[0] is None or isinstance(actual[0], Geometry) + + actual = shapely.minimum_bounding_circle(None) + assert actual is None + + +@pytest.mark.skipif(shapely.geos_version < (3, 8, 0), reason="GEOS < 3.8") +@pytest.mark.parametrize( + "geometry, expected", + [ + ( + Polygon([(0, 5), (5, 10), (10, 5), (5, 0), (0, 5)]), + shapely.buffer(Point(5, 5), 5), + ), + ( + LineString([(1, 0), (1, 10)]), + shapely.buffer(Point(1, 5), 5), + ), + ( + MultiPoint([(2, 2), (4, 2)]), + shapely.buffer(Point(3, 2), 1), + ), + ( + Point(2, 2), + Point(2, 2), + ), + ( + GeometryCollection(), + Polygon(), + ), + ], +) +def test_minimum_bounding_circle(geometry, expected): + actual = shapely.minimum_bounding_circle(geometry) + assert_geometries_equal(actual, expected) + + +@pytest.mark.skipif(shapely.geos_version < (3, 6, 0), reason="GEOS < 3.6") +@pytest.mark.parametrize("geometry", all_types) +def test_oriented_envelope_all_types(geometry): + actual = shapely.oriented_envelope([geometry, geometry]) + assert actual.shape == (2,) + assert actual[0] is None or isinstance(actual[0], Geometry) + + actual = shapely.oriented_envelope(None) + assert actual is None + + +@pytest.mark.parametrize( + "func", [shapely.oriented_envelope, shapely.minimum_rotated_rectangle] +) +@pytest.mark.parametrize( + "geometry, expected", + [ + ( + MultiPoint([(1.0, 1.0), (1.0, 5.0), (3.0, 6.0), (4.0, 2.0), (5.0, 5.0)]), + Polygon([(1.0, 1.0), (1.0, 6.0), (5.0, 6.0), (5.0, 1.0), (1.0, 1.0)]), + ), + ( + LineString([(1, 1), (5, 1), (10, 10)]), + Polygon([(1, 1), (3, -1), (12, 8), (10, 10), (1, 1)]), + ), + ( + Polygon([(1, 1), (15, 1), (5, 9), (1, 1)]), + Polygon([(1.0, 1.0), (5.0, 9.0), (16.2, 3.4), (12.2, -4.6), (1.0, 1.0)]), + ), + ( + LineString([(1, 1), (10, 1)]), + LineString([(1, 1), (10, 1)]), + ), + ( + Point(2, 2), + Point(2, 2), + ), + ( + GeometryCollection(), + Polygon(), + ), + ], +) +def test_oriented_envelope(geometry, expected, func): + actual = func(geometry) + assert_geometries_equal(actual, expected, normalize=True, tolerance=1e-3) + + +@pytest.mark.skipif( + shapely.geos_version >= (3, 12, 0) or shapely.geos_version < (3, 8, 0), + reason="GEOS >= 3.12", +) +@pytest.mark.parametrize( + "geometry, expected", + [ + ( + MultiPoint([(1.0, 1.0), (1.0, 5.0), (3.0, 6.0), (4.0, 2.0), (5.0, 5.0)]), + Polygon([(-0.2, 1.4), (1.5, 6.5), (5.1, 5.3), (3.4, 0.2), (-0.2, 1.4)]), + ), + ( + LineString([(1, 1), (5, 1), (10, 10)]), + Polygon([(1, 1), (3, -1), (12, 8), (10, 10), (1, 1)]), + ), + ( + Polygon([(1, 1), (15, 1), (5, 9), (1, 1)]), + Polygon([(1.0, 1.0), (1.0, 9.0), (15.0, 9.0), (15.0, 1.0), (1.0, 1.0)]), + ), + ( + LineString([(1, 1), (10, 1)]), + LineString([(1, 1), (10, 1)]), + ), + ( + Point(2, 2), + Point(2, 2), + ), + ( + GeometryCollection(), + Polygon(), + ), + ], +) +def test_oriented_envelope_pre_geos_312(geometry, expected): + # use private method (similar as direct shapely.lib.oriented_envelope) + # to cover the C code for older GEOS versions + actual = shapely.constructive._oriented_envelope_geos(geometry) + if shapely.geos_version < (3, 8, 0): + # For GEOS 3.7, the function returns 3D which was ignored in the old test: + assert shapely.equals(actual, expected).all() + else: + assert_geometries_equal(actual, expected, normalize=True, tolerance=1e-3) + + +def test_oriented_evelope_array_like(): + # https://github.com/shapely/shapely/issues/1929 + # because we have a custom python implementation, need to ensure this has + # the same capabilities as numpy ufuncs to work with array-likes + geometries = [Point(1, 1).buffer(1), Point(2, 2).buffer(1)] + actual = shapely.oriented_envelope(ArrayLike(geometries)) + assert isinstance(actual, ArrayLike) + expected = shapely.oriented_envelope(geometries) + assert_geometries_equal(np.asarray(actual), expected) + + +@pytest.mark.skipif(shapely.geos_version < (3, 11, 0), reason="GEOS < 3.11") +def test_concave_hull_kwargs(): + p = Point(10, 10) + mp = MultiPoint(p.buffer(5).exterior.coords[:] + p.buffer(4).exterior.coords[:]) + + result1 = shapely.concave_hull(mp, ratio=0.5) + assert len(result1.interiors) == 0 + result2 = shapely.concave_hull(mp, ratio=0.5, allow_holes=True) + assert len(result2.interiors) == 1 + + result3 = shapely.concave_hull(mp, ratio=0) + result4 = shapely.concave_hull(mp, ratio=1) + assert shapely.get_num_coordinates(result4) < shapely.get_num_coordinates(result3) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/test_coordinates.py b/vllm/lib/python3.10/site-packages/shapely/tests/test_coordinates.py new file mode 100644 index 0000000000000000000000000000000000000000..8a998daee5816b8ad0e8c357dd843ed0adc9f29f --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/test_coordinates.py @@ -0,0 +1,266 @@ +import numpy as np +import pytest +from numpy.testing import assert_allclose, assert_equal + +import shapely +from shapely import count_coordinates, get_coordinates, set_coordinates, transform +from shapely.tests.common import ( + empty, + empty_line_string_z, + empty_point, + empty_point_z, + geometry_collection, + geometry_collection_z, + line_string, + line_string_z, + linear_ring, + multi_line_string, + multi_point, + multi_polygon, + point, + point_z, + polygon, + polygon_with_hole, + polygon_z, +) + +nested_2 = shapely.geometrycollections([geometry_collection, point]) +nested_3 = shapely.geometrycollections([nested_2, point]) + + +@pytest.mark.parametrize( + "geoms,count", + [ + ([], 0), + ([empty], 0), + ([point, empty], 1), + ([empty, point, empty], 1), + ([point, None], 1), + ([None, point, None], 1), + ([point, point], 2), + ([point, point_z], 2), + ([line_string, linear_ring], 8), + ([polygon], 5), + ([polygon_with_hole], 10), + ([multi_point, multi_line_string], 4), + ([multi_polygon], 10), + ([geometry_collection], 3), + ([nested_2], 4), + ([nested_3], 5), + ], +) +def test_count_coords(geoms, count): + actual = count_coordinates(np.array(geoms, np.object_)) + assert actual == count + + +# fmt: off +@pytest.mark.parametrize("include_z", [True, False]) +@pytest.mark.parametrize( + "geoms,x,y", + [ + ([], [], []), + ([empty], [], []), + ([point, empty], [2], [3]), + ([empty, point, empty], [2], [3]), + ([point, None], [2], [3]), + ([None, point, None], [2], [3]), + ([point, point], [2, 2], [3, 3]), + ([line_string, linear_ring], [0, 1, 1, 0, 1, 1, 0, 0], [0, 0, 1, 0, 0, 1, 1, 0]), + ([polygon], [0, 2, 2, 0, 0], [0, 0, 2, 2, 0]), + ([polygon_with_hole], [0, 0, 10, 10, 0, 2, 2, 4, 4, 2], [0, 10, 10, 0, 0, 2, 4, 4, 2, 2]), + ([multi_point, multi_line_string], [0, 1, 0, 1], [0, 2, 0, 2]), + ([multi_polygon], [0, 1, 1, 0, 0, 2.1, 2.2, 2.2, 2.1, 2.1], [0, 0, 1, 1, 0, 2.1, 2.1, 2.2, 2.2, 2.1]), + ([geometry_collection], [51, 52, 49], [-1, -1, 2]), + ([nested_2], [51, 52, 49, 2], [-1, -1, 2, 3]), + ([nested_3], [51, 52, 49, 2, 2], [-1, -1, 2, 3, 3]), + ], +) # fmt: on +def test_get_coords(geoms, x, y, include_z): + actual = get_coordinates(np.array(geoms, np.object_), include_z=include_z) + if not include_z: + expected = np.array([x, y], np.float64).T + else: + expected = np.array([x, y, [np.nan] * len(x)], np.float64).T + assert_equal(actual, expected) + + +# fmt: off +@pytest.mark.parametrize( + "geoms,index", + [ + ([], []), + ([empty], []), + ([point, empty], [0]), + ([empty, point, empty], [1]), + ([point, None], [0]), + ([None, point, None], [1]), + ([point, point], [0, 1]), + ([point, line_string], [0, 1, 1, 1]), + ([line_string, point], [0, 0, 0, 1]), + ([line_string, linear_ring], [0, 0, 0, 1, 1, 1, 1, 1]), + ], +) # fmt: on +def test_get_coords_index(geoms, index): + _, actual = get_coordinates(np.array(geoms, np.object_), return_index=True) + expected = np.array(index, dtype=np.intp) + assert_equal(actual, expected) + + +@pytest.mark.parametrize("order", ["C", "F"]) +def test_get_coords_index_multidim(order): + geometry = np.array([[point, line_string], [empty, empty]], order=order) + expected = [0, 1, 1, 1] # would be [0, 2, 2, 2] with fortran order + _, actual = get_coordinates(geometry, return_index=True) + assert_equal(actual, expected) + + +# fmt: off +@pytest.mark.parametrize("include_z", [True, False]) +@pytest.mark.parametrize( + "geoms,x,y,z", + [ + ([point, point_z], [2, 2], [3, 3], [np.nan, 4]), + ([line_string_z], [0, 1, 1], [0, 0, 1], [4, 4, 4]), + ([polygon_z], [0, 2, 2, 0, 0], [0, 0, 2, 2, 0], [4, 4, 4, 4, 4]), + ([geometry_collection_z], [2, 0, 1, 1], [3, 0, 0, 1], [4, 4, 4, 4]), + ([point, empty_point], [2], [3], [np.nan]), + ], +) # fmt: on +def test_get_coords_3d(geoms, x, y, z, include_z): + actual = get_coordinates(np.array(geoms, np.object_), include_z=include_z) + if include_z: + expected = np.array([x, y, z], np.float64).T + else: + expected = np.array([x, y], np.float64).T + assert_equal(actual, expected) + + +@pytest.mark.parametrize("include_z", [True, False]) +@pytest.mark.parametrize( + "geoms,count,has_ring", + [ + ([], 0, False), + ([empty], 0, False), + ([empty_point], 0, False), + ([point, empty], 1, False), + ([empty, point, empty], 1, False), + ([point, None], 1, False), + ([None, point, None], 1, False), + ([point, point], 2, False), + ([point, point_z], 2, False), + ([line_string, linear_ring], 8, True), + ([line_string_z], 3, True), + ([polygon], 5, True), + ([polygon_z], 5, True), + ([polygon_with_hole], 10, True), + ([multi_point, multi_line_string], 4, False), + ([multi_polygon], 10, True), + ([geometry_collection], 3, False), + ([geometry_collection_z], 3, False), + ([nested_2], 4, False), + ([nested_3], 5, False), + ], +) +def test_set_coords(geoms, count, has_ring, include_z): + arr_geoms = np.array(geoms, np.object_) + n = 3 if include_z else 2 + coords = get_coordinates(arr_geoms, include_z=include_z) + np.random.random((1, n)) + new_geoms = set_coordinates(arr_geoms, coords) + assert_equal(coords, get_coordinates(new_geoms, include_z=include_z)) + + +def test_set_coords_nan(): + geoms = np.array([point]) + coords = np.array([[np.nan, np.inf]]) + new_geoms = set_coordinates(geoms, coords) + assert_equal(coords, get_coordinates(new_geoms)) + + +def test_set_coords_breaks_ring(): + with pytest.raises(shapely.GEOSException): + set_coordinates(linear_ring, np.random.random((5, 2))) + + +def test_set_coords_0dim(): + # a geometry input returns a geometry + actual = set_coordinates(point, [[1, 1]]) + assert isinstance(actual, shapely.Geometry) + # a 0-dim array input returns a 0-dim array + actual = set_coordinates(np.asarray(point), [[1, 1]]) + assert isinstance(actual, np.ndarray) + assert actual.ndim == 0 + + +@pytest.mark.parametrize("include_z", [True, False]) +def test_set_coords_mixed_dimension(include_z): + geoms = np.array([point, point_z], dtype=object) + coords = get_coordinates(geoms, include_z=include_z) + new_geoms = set_coordinates(geoms, coords * 2) + if include_z: + # preserve original dimensionality + assert not shapely.has_z(new_geoms[0]) + assert shapely.has_z(new_geoms[1]) + else: + # all 2D + assert not shapely.has_z(new_geoms).any() + + +@pytest.mark.parametrize("include_z", [True, False]) +@pytest.mark.parametrize( + "geoms", + [[], [empty], [None, point, None], [nested_3], [point, point_z], [line_string_z]], +) +def test_transform(geoms, include_z): + geoms = np.array(geoms, np.object_) + coordinates_before = get_coordinates(geoms, include_z=include_z) + new_geoms = transform(geoms, lambda x: x + 1, include_z=include_z) + assert new_geoms is not geoms + coordinates_after = get_coordinates(new_geoms, include_z=include_z) + assert_allclose(coordinates_before + 1, coordinates_after, equal_nan=True) + + +def test_transform_0dim(): + # a geometry input returns a geometry + actual = transform(point, lambda x: x + 1) + assert isinstance(actual, shapely.Geometry) + # a 0-dim array input returns a 0-dim array + actual = transform(np.asarray(point), lambda x: x + 1) + assert isinstance(actual, np.ndarray) + assert actual.ndim == 0 + + +def test_transform_check_shape(): + def remove_coord(arr): + return arr[:-1] + + with pytest.raises(ValueError): + transform(linear_ring, remove_coord) + + +def test_transform_correct_coordinate_dimension(): + # ensure that new geometry is 2D with include_z=False + geom = line_string_z + assert shapely.get_coordinate_dimension(geom) == 3 + new_geom = transform(geom, lambda x: x + 1, include_z=False) + assert shapely.get_coordinate_dimension(new_geom) == 2 + + +@pytest.mark.parametrize("geom", [ + pytest.param(empty_point_z, marks=pytest.mark.skipif(shapely.geos_version < (3, 9, 0), reason="Empty points don't have a dimensionality before GEOS 3.9")), + empty_line_string_z, +]) +def test_transform_empty_preserve_z(geom): + assert shapely.get_coordinate_dimension(geom) == 3 + new_geom = transform(geom, lambda x: x + 1, include_z=True) + assert shapely.get_coordinate_dimension(new_geom) == 3 + + +@pytest.mark.parametrize("geom", [ + pytest.param(empty_point_z, marks=pytest.mark.skipif(shapely.geos_version < (3, 9, 0), reason="Empty points don't have a dimensionality before GEOS 3.9")), + empty_line_string_z, +]) +def test_transform_remove_z(geom): + assert shapely.get_coordinate_dimension(geom) == 3 + new_geom = transform(geom, lambda x: x + 1, include_z=False) + assert shapely.get_coordinate_dimension(new_geom) == 2 diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/test_creation.py b/vllm/lib/python3.10/site-packages/shapely/tests/test_creation.py new file mode 100644 index 0000000000000000000000000000000000000000..3866890fa6a4b7731579651da7e50878eefc6b91 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/test_creation.py @@ -0,0 +1,594 @@ +import numpy as np +import pytest + +import shapely + +# Note: Point is not imported because it is overridden for testing +from shapely import ( + GeometryCollection, + GeometryType, + LinearRing, + LineString, + MultiLineString, + MultiPoint, + MultiPolygon, + Polygon, +) +from shapely.testing import assert_geometries_equal +from shapely.tests.common import ( + empty_polygon, + geometry_collection, + line_string, + linear_ring, + multi_line_string, + multi_point, + multi_polygon, + point, + polygon, +) + + +def box_tpl(x1, y1, x2, y2): + return (x2, y1), (x2, y2), (x1, y2), (x1, y1), (x2, y1) + + +def test_points_from_coords(): + actual = shapely.points([[0, 0], [2, 2]]) + assert_geometries_equal(actual, [shapely.Point(0, 0), shapely.Point(2, 2)]) + + +def test_points_from_xy(): + actual = shapely.points(2, [0, 1]) + assert_geometries_equal(actual, [shapely.Point(2, 0), shapely.Point(2, 1)]) + + +def test_points_from_xyz(): + actual = shapely.points(1, 1, [0, 1]) + assert_geometries_equal(actual, [shapely.Point(1, 1, 0), shapely.Point(1, 1, 1)]) + + +def test_points_invalid_ndim(): + with pytest.raises(ValueError, match="dimension should be 2 or 3, got 4"): + shapely.points([0, 1, 2, 3]) + + with pytest.raises(ValueError, match="dimension should be 2 or 3, got 1"): + shapely.points([0]) + + +@pytest.mark.skipif( + shapely.geos_version[:2] not in ((3, 10), (3, 11), (3, 12)), + reason="GEOS not in 3.10, 3.11, 3.12", +) +def test_points_nan_all_nan_becomes_empty(): + actual = shapely.points(np.nan, np.nan) + assert actual.wkt == "POINT EMPTY" + + +@pytest.mark.skipif( + shapely.geos_version[:2] not in ((3, 10), (3, 11)), + reason="GEOS not in 3.10, 3.11", +) +def test_points_nan_3D_all_nan_becomes_empty_2D(): + actual = shapely.points(np.nan, np.nan, np.nan) + assert actual.wkt == "POINT EMPTY" + + +@pytest.mark.skipif(shapely.geos_version[:2] != (3, 12), reason="GEOS != 3.12") +def test_points_nan_3D_all_nan_becomes_empty(): + actual = shapely.points(np.nan, np.nan, np.nan) + assert actual.wkt == "POINT Z EMPTY" + + +@pytest.mark.skipif(shapely.geos_version < (3, 12, 0), reason="GEOS < 3.12") +@pytest.mark.parametrize( + "coords,expected_wkt", + [ + pytest.param( + [np.nan, np.nan], + "POINT (NaN NaN)", + marks=pytest.mark.skipif( + shapely.geos_version < (3, 13, 0), reason="GEOS < 3.13" + ), + ), + pytest.param( + [np.nan, np.nan, np.nan], + "POINT Z (NaN NaN NaN)", + marks=pytest.mark.skipif( + shapely.geos_version < (3, 13, 0), reason="GEOS < 3.13" + ), + ), + ([1, np.nan], "POINT (1 NaN)"), + ([np.nan, 1], "POINT (NaN 1)"), + ([np.nan, 1, np.nan], "POINT Z (NaN 1 NaN)"), + ([np.nan, np.nan, 1], "POINT Z (NaN NaN 1)"), + ], +) +def test_points_handle_nan_allow(coords, expected_wkt): + actual = shapely.points(coords) + assert actual.wkt == expected_wkt + + +def test_linestrings_from_coords(): + actual = shapely.linestrings([[[0, 0], [1, 1]], [[0, 0], [2, 2]]]) + assert_geometries_equal( + actual, + [ + LineString([(0, 0), (1, 1)]), + LineString([(0, 0), (2, 2)]), + ], + ) + + +def test_linestrings_from_xy(): + actual = shapely.linestrings([0, 1], [2, 3]) + assert_geometries_equal(actual, LineString([(0, 2), (1, 3)])) + + +def test_linestrings_from_xy_broadcast(): + x = [0, 1] # the same X coordinates for both linestrings + y = [2, 3], [4, 5] # each linestring has a different set of Y coordinates + actual = shapely.linestrings(x, y) + assert_geometries_equal( + actual, + [ + LineString([(0, 2), (1, 3)]), + LineString([(0, 4), (1, 5)]), + ], + ) + + +def test_linestrings_from_xyz(): + actual = shapely.linestrings([0, 1], [2, 3], 0) + assert_geometries_equal(actual, LineString([(0, 2, 0), (1, 3, 0)])) + + +@pytest.mark.parametrize("dim", [2, 3]) +def test_linestrings_buffer(dim): + coords = np.random.randn(10, 3, dim) + coords1 = np.asarray(coords, order="C") + result1 = shapely.linestrings(coords1) + + coords2 = np.asarray(coords1, order="F") + result2 = shapely.linestrings(coords2) + assert_geometries_equal(result1, result2) + + # creating (.., 8, 8*3) strided array so it uses copyFromArrays + coords3 = np.asarray(np.swapaxes(np.swapaxes(coords, 0, 2), 1, 0), order="F") + coords3 = np.swapaxes(np.swapaxes(coords3, 0, 2), 1, 2) + result3 = shapely.linestrings(coords3) + assert_geometries_equal(result1, result3) + + +def test_linestrings_invalid_shape_scalar(): + with pytest.raises(ValueError): + shapely.linestrings((1, 1)) + + +@pytest.mark.parametrize( + "shape", + [ + (2, 1, 2), # 2 linestrings of 1 2D point + (1, 1, 2), # 1 linestring of 1 2D point + (1, 2), # 1 linestring of 1 2D point (scalar) + ], +) +def test_linestrings_invalid_shape(shape): + with pytest.raises(shapely.GEOSException): + shapely.linestrings(np.ones(shape)) + + +def test_linestrings_invalid_ndim(): + msg = r"The ordinate \(last\) dimension should be 2 or 3, got {}" + + coords = np.ones((10, 2, 4), order="C") + with pytest.raises(ValueError, match=msg.format(4)): + shapely.linestrings(coords) + + coords = np.ones((10, 2, 4), order="F") + with pytest.raises(ValueError, match=msg.format(4)): + shapely.linestrings(coords) + + coords = np.swapaxes(np.swapaxes(np.ones((10, 2, 4)), 0, 2), 1, 0) + coords = np.swapaxes(np.swapaxes(np.asarray(coords, order="F"), 0, 2), 1, 2) + with pytest.raises(ValueError, match=msg.format(4)): + shapely.linestrings(coords) + + # too few ordinates + coords = np.ones((10, 2, 1)) + with pytest.raises(ValueError, match=msg.format(1)): + shapely.linestrings(coords) + + +def test_linearrings(): + actual = shapely.linearrings(box_tpl(0, 0, 1, 1)) + assert_geometries_equal( + actual, LinearRing([(1, 0), (1, 1), (0, 1), (0, 0), (1, 0)]) + ) + + +def test_linearrings_from_xy(): + actual = shapely.linearrings([0, 1, 2, 0], [3, 4, 5, 3]) + assert_geometries_equal(actual, LinearRing([(0, 3), (1, 4), (2, 5), (0, 3)])) + + +def test_linearrings_unclosed(): + actual = shapely.linearrings(box_tpl(0, 0, 1, 1)[:-1]) + assert_geometries_equal( + actual, LinearRing([(1, 0), (1, 1), (0, 1), (0, 0), (1, 0)]) + ) + + +def test_linearrings_unclosed_all_coords_equal(): + actual = shapely.linearrings([(0, 0), (0, 0), (0, 0)]) + assert_geometries_equal(actual, LinearRing([(0, 0), (0, 0), (0, 0), (0, 0)])) + + +def test_linearrings_invalid_shape_scalar(): + with pytest.raises(ValueError): + shapely.linearrings((1, 1)) + + +@pytest.mark.parametrize( + "shape", + [ + (2, 1, 2), # 2 linearrings of 1 2D point + (1, 1, 2), # 1 linearring of 1 2D point + (1, 2), # 1 linearring of 1 2D point (scalar) + (2, 2, 2), # 2 linearrings of 2 2D points + (1, 2, 2), # 1 linearring of 2 2D points + (2, 2), # 1 linearring of 2 2D points (scalar) + ], +) +def test_linearrings_invalid_shape(shape): + coords = np.ones(shape) + with pytest.raises(ValueError): + shapely.linearrings(coords) + + # make sure the first coordinate != second coordinate + coords[..., 1] += 1 + with pytest.raises(ValueError): + shapely.linearrings(coords) + + +def test_linearrings_invalid_ndim(): + msg = r"The ordinate \(last\) dimension should be 2 or 3, got {}" + + coords1 = np.random.randn(10, 3, 4) + with pytest.raises(ValueError, match=msg.format(4)): + shapely.linearrings(coords1) + + coords2 = np.hstack((coords1, coords1[:, [0], :])) + with pytest.raises(ValueError, match=msg.format(4)): + shapely.linearrings(coords2) + + # too few ordinates + coords3 = np.random.randn(10, 3, 1) + with pytest.raises(ValueError, match=msg.format(1)): + shapely.linestrings(coords3) + + +def test_linearrings_all_nan(): + coords = np.full((4, 2), np.nan) + with pytest.raises(shapely.GEOSException): + shapely.linearrings(coords) + + +@pytest.mark.parametrize("dim", [2, 3]) +@pytest.mark.parametrize("order", ["C", "F"]) +def test_linearrings_buffer(dim, order): + coords1 = np.random.randn(10, 4, dim) + coords1 = np.asarray(coords1, order=order) + result1 = shapely.linearrings(coords1) + + # with manual closure -> can directly copy from buffer if C order + coords2 = np.hstack((coords1, coords1[:, [0], :])) + coords2 = np.asarray(coords2, order=order) + result2 = shapely.linearrings(coords2) + assert_geometries_equal(result1, result2) + + # create scalar -> can also directly copy from buffer if F order + coords3 = np.asarray(coords2[0], order=order) + result3 = shapely.linearrings(coords3) + assert_geometries_equal(result3, result1[0]) + + +def test_polygon_from_linearring(): + actual = shapely.polygons(shapely.linearrings(box_tpl(0, 0, 1, 1))) + assert_geometries_equal(actual, Polygon([(1, 0), (1, 1), (0, 1), (0, 0), (1, 0)])) + + +def test_polygons_none(): + assert_geometries_equal(shapely.polygons(None), empty_polygon) + assert_geometries_equal(shapely.polygons(None, holes=[linear_ring]), empty_polygon) + + +def test_polygons(): + actual = shapely.polygons(box_tpl(0, 0, 1, 1)) + assert_geometries_equal(actual, Polygon([(1, 0), (1, 1), (0, 1), (0, 0), (1, 0)])) + + +def test_polygon_no_hole_list_raises(): + with pytest.raises(ValueError): + shapely.polygons(box_tpl(0, 0, 10, 10), box_tpl(1, 1, 2, 2)) + + +def test_polygon_no_hole_wrong_type(): + with pytest.raises((TypeError, shapely.GEOSException)): + shapely.polygons(point) + + +def test_polygon_with_hole_wrong_type(): + with pytest.raises((TypeError, shapely.GEOSException)): + shapely.polygons(point, [linear_ring]) + + +def test_polygon_wrong_hole_type(): + with pytest.raises((TypeError, shapely.GEOSException)): + shapely.polygons(linear_ring, [point]) + + +def test_polygon_with_1_hole(): + actual = shapely.polygons(box_tpl(0, 0, 10, 10), [box_tpl(1, 1, 2, 2)]) + assert shapely.area(actual) == 99.0 + + +def test_polygon_with_2_holes(): + actual = shapely.polygons( + box_tpl(0, 0, 10, 10), [box_tpl(1, 1, 2, 2), box_tpl(3, 3, 4, 4)] + ) + assert shapely.area(actual) == 98.0 + + +def test_polygon_with_none_hole(): + actual = shapely.polygons( + shapely.linearrings(box_tpl(0, 0, 10, 10)), + [ + shapely.linearrings(box_tpl(1, 1, 2, 2)), + None, + shapely.linearrings(box_tpl(3, 3, 4, 4)), + ], + ) + assert shapely.area(actual) == 98.0 + + +def test_2_polygons_with_same_hole(): + actual = shapely.polygons( + [box_tpl(0, 0, 10, 10), box_tpl(0, 0, 5, 5)], [box_tpl(1, 1, 2, 2)] + ) + assert shapely.area(actual).tolist() == [99.0, 24.0] + + +def test_2_polygons_with_2_same_holes(): + actual = shapely.polygons( + [box_tpl(0, 0, 10, 10), box_tpl(0, 0, 5, 5)], + [box_tpl(1, 1, 2, 2), box_tpl(3, 3, 4, 4)], + ) + assert shapely.area(actual).tolist() == [98.0, 23.0] + + +def test_2_polygons_with_different_holes(): + actual = shapely.polygons( + [box_tpl(0, 0, 10, 10), box_tpl(0, 0, 5, 5)], + [[box_tpl(1, 1, 3, 3)], [box_tpl(1, 1, 2, 2)]], + ) + assert shapely.area(actual).tolist() == [96.0, 24.0] + + +def test_polygons_not_enough_points_in_shell_scalar(): + with pytest.raises(ValueError): + shapely.polygons((1, 1)) + + +@pytest.mark.parametrize( + "shape", + [ + (2, 1, 2), # 2 linearrings of 1 2D point + (1, 1, 2), # 1 linearring of 1 2D point + (1, 2), # 1 linearring of 1 2D point (scalar) + (2, 2, 2), # 2 linearrings of 2 2D points + (1, 2, 2), # 1 linearring of 2 2D points + (2, 2), # 1 linearring of 2 2D points (scalar) + ], +) +def test_polygons_not_enough_points_in_shell(shape): + coords = np.ones(shape) + with pytest.raises(ValueError): + shapely.polygons(coords) + + # make sure the first coordinate != second coordinate + coords[..., 1] += 1 + with pytest.raises(ValueError): + shapely.polygons(coords) + + +def test_polygons_not_enough_points_in_holes_scalar(): + with pytest.raises(ValueError): + shapely.polygons(np.ones((1, 4, 2)), (1, 1)) + + +@pytest.mark.parametrize( + "shape", + [ + (2, 1, 2), # 2 linearrings of 1 2D point + (1, 1, 2), # 1 linearring of 1 2D point + (1, 2), # 1 linearring of 1 2D point (scalar) + (2, 2, 2), # 2 linearrings of 2 2D points + (1, 2, 2), # 1 linearring of 2 2D points + (2, 2), # 1 linearring of 2 2D points (scalar) + ], +) +def test_polygons_not_enough_points_in_holes(shape): + coords = np.ones(shape) + with pytest.raises(ValueError): + shapely.polygons(np.ones((1, 4, 2)), coords) + + # make sure the first coordinate != second coordinate + coords[..., 1] += 1 + with pytest.raises(ValueError): + shapely.polygons(np.ones((1, 4, 2)), coords) + + +@pytest.mark.parametrize( + "func,expected", + [ + (shapely.multipoints, MultiPoint()), + (shapely.multilinestrings, MultiLineString()), + (shapely.multipolygons, MultiPolygon()), + (shapely.geometrycollections, GeometryCollection()), + ], +) +def test_create_collection_only_none(func, expected): + actual = func(np.array([None], dtype=object)) + assert_geometries_equal(actual, expected) + + +@pytest.mark.parametrize( + "func,sub_geom", + [ + (shapely.multipoints, point), + (shapely.multilinestrings, line_string), + (shapely.multilinestrings, linear_ring), + (shapely.multipolygons, polygon), + (shapely.geometrycollections, point), + (shapely.geometrycollections, line_string), + (shapely.geometrycollections, linear_ring), + (shapely.geometrycollections, polygon), + (shapely.geometrycollections, multi_point), + (shapely.geometrycollections, multi_line_string), + (shapely.geometrycollections, multi_polygon), + (shapely.geometrycollections, geometry_collection), + ], +) +def test_create_collection(func, sub_geom): + actual = func([sub_geom, sub_geom]) + assert shapely.get_num_geometries(actual) == 2 + + +@pytest.mark.parametrize( + "func,sub_geom", + [ + (shapely.multipoints, point), + (shapely.multilinestrings, line_string), + (shapely.multipolygons, polygon), + (shapely.geometrycollections, polygon), + ], +) +def test_create_collection_skips_none(func, sub_geom): + actual = func([sub_geom, None, None, sub_geom]) + assert shapely.get_num_geometries(actual) == 2 + + +@pytest.mark.parametrize( + "func,sub_geom", + [ + (shapely.multipoints, line_string), + (shapely.multipoints, geometry_collection), + (shapely.multipoints, multi_point), + (shapely.multilinestrings, point), + (shapely.multilinestrings, polygon), + (shapely.multilinestrings, multi_line_string), + (shapely.multipolygons, linear_ring), + (shapely.multipolygons, multi_point), + (shapely.multipolygons, multi_polygon), + ], +) +def test_create_collection_wrong_geom_type(func, sub_geom): + with pytest.raises(TypeError): + func([sub_geom]) + + +@pytest.mark.parametrize( + "coords,ccw,expected", + [ + ((0, 0, 1, 1), True, Polygon([(1, 0), (1, 1), (0, 1), (0, 0), (1, 0)])), + ( + (0, 0, 1, 1), + False, + Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]), + ), + ], +) +def test_box(coords, ccw, expected): + actual = shapely.box(*coords, ccw=ccw) + assert_geometries_equal(actual, expected) + + +@pytest.mark.parametrize( + "coords,ccw,expected", + [ + ( + (0, 0, [1, 2], [1, 2]), + True, + [ + Polygon([(1, 0), (1, 1), (0, 1), (0, 0), (1, 0)]), + Polygon([(2, 0), (2, 2), (0, 2), (0, 0), (2, 0)]), + ], + ), + ( + (0, 0, [1, 2], [1, 2]), + [True, False], + [ + Polygon([(1, 0), (1, 1), (0, 1), (0, 0), (1, 0)]), + Polygon([(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)]), + ], + ), + ], +) +def test_box_array(coords, ccw, expected): + actual = shapely.box(*coords, ccw=ccw) + assert_geometries_equal(actual, expected) + + +@pytest.mark.parametrize( + "coords", + [ + [np.nan, np.nan, np.nan, np.nan], + [np.nan, 0, 1, 1], + [0, np.nan, 1, 1], + [0, 0, np.nan, 1], + [0, 0, 1, np.nan], + ], +) +def test_box_nan(coords): + assert shapely.box(*coords) is None + + +def test_prepare(): + arr = np.array([shapely.points(1, 1), None, shapely.box(0, 0, 1, 1)]) + assert arr[0]._geom_prepared == 0 + assert arr[2]._geom_prepared == 0 + shapely.prepare(arr) + assert arr[0]._geom_prepared != 0 + assert arr[1] is None + assert arr[2]._geom_prepared != 0 + + # preparing again actually does nothing + original = arr[0]._geom_prepared + shapely.prepare(arr) + assert arr[0]._geom_prepared == original + + +def test_destroy_prepared(): + arr = np.array([shapely.points(1, 1), None, shapely.box(0, 0, 1, 1)]) + shapely.prepare(arr) + assert arr[0]._geom_prepared != 0 + assert arr[2]._geom_prepared != 0 + shapely.destroy_prepared(arr) + assert arr[0]._geom_prepared == 0 + assert arr[1] is None + assert arr[2]._geom_prepared == 0 + shapely.destroy_prepared(arr) # does not error + + +@pytest.mark.parametrize("geom_type", [None, GeometryType.MISSING, -1]) +def test_empty_missing(geom_type): + actual = shapely.empty((2,), geom_type=geom_type) + assert shapely.is_missing(actual).all() + + +@pytest.mark.parametrize("geom_type", range(8)) +def test_empty(geom_type): + actual = shapely.empty((2,), geom_type=geom_type) + assert (~shapely.is_missing(actual)).all() + assert shapely.is_empty(actual).all() + assert (shapely.get_type_id(actual) == geom_type).all() diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/test_creation_indices.py b/vllm/lib/python3.10/site-packages/shapely/tests/test_creation_indices.py new file mode 100644 index 0000000000000000000000000000000000000000..7d938926ed5e10a37acd387e153b1679347fdc23 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/test_creation_indices.py @@ -0,0 +1,418 @@ +import numpy as np +import pytest + +import shapely +from shapely import LinearRing, Polygon +from shapely.testing import assert_geometries_equal +from shapely.tests.common import empty_point, line_string, linear_ring, point, polygon + +pnts = shapely.points +lstrs = shapely.linestrings +geom_coll = shapely.geometrycollections + + +@pytest.mark.parametrize( + "func", [shapely.points, shapely.linestrings, shapely.linearrings] +) +@pytest.mark.parametrize( + "coordinates", + [ + np.empty((2,)), # not enough dimensions + np.empty((2, 4, 1)), # too many dimensions + np.empty((2, 4)), # wrong inner dimension size + None, + np.full((2, 2), "foo", dtype=object), # wrong type + ], +) +def test_invalid_coordinates(func, coordinates): + with pytest.raises((TypeError, ValueError)): + func(coordinates, indices=[0, 1]) + + +@pytest.mark.parametrize( + "func", + [ + shapely.multipoints, + shapely.multilinestrings, + shapely.multipolygons, + shapely.geometrycollections, + ], +) +@pytest.mark.parametrize( + "geometries", [np.array([1, 2], dtype=np.intp), None, np.array([[point]]), "hello"] +) +def test_invalid_geometries(func, geometries): + with pytest.raises((TypeError, ValueError)): + func(geometries, indices=[0, 1]) + + +@pytest.mark.parametrize( + "func", [shapely.points, shapely.linestrings, shapely.linearrings] +) +@pytest.mark.parametrize("indices", [[point], " hello", [0, 1], [-1]]) +def test_invalid_indices_simple(func, indices): + with pytest.raises((TypeError, ValueError)): + func([[0.2, 0.3]], indices=indices) + + +non_writeable = np.empty(3, dtype=object) +non_writeable.flags.writeable = False + + +@pytest.mark.parametrize( + "func", [shapely.points, shapely.linestrings, shapely.geometrycollections] +) +@pytest.mark.parametrize( + "out", + [ + [None, None, None], # not an ndarray + np.empty(3), # wrong dtype + non_writeable, # not writeable + np.empty((3, 2), dtype=object), # too many dimensions + np.empty((), dtype=object), # too few dimensions + np.empty((2,), dtype=object), # too small + ], +) +def test_invalid_out(func, out): + if func is shapely.points: + x = [[0.2, 0.3], [0.4, 0.5]] + indices = [0, 2] + elif func is shapely.linestrings: + x = [[1, 1], [2, 1], [2, 2], [3, 3], [3, 4], [4, 4]] + indices = [0, 0, 0, 2, 2, 2] + else: + x = [point, line_string] + indices = [0, 2] + with pytest.raises((TypeError, ValueError)): + func(x, indices=indices, out=out) + + +def test_points_invalid(): + # attempt to construct a point with 2 coordinates + with pytest.raises(shapely.GEOSException): + shapely.points([[1, 1], [2, 2]], indices=[0, 0]) + + +def test_points(): + actual = shapely.points( + np.array([[2, 3], [2, 3]], dtype=float), + indices=np.array([0, 1], dtype=np.intp), + ) + assert_geometries_equal(actual, [point, point]) + + +def test_points_no_index_raises(): + with pytest.raises(ValueError): + shapely.points( + np.array([[2, 3], [2, 3]], dtype=float), + indices=np.array([0, 2], dtype=np.intp), + ) + + +@pytest.mark.parametrize( + "indices,expected", + [ + ([0, 1], [point, point, empty_point, None]), + ([0, 3], [point, None, empty_point, point]), + ([2, 3], [None, None, point, point]), + ], +) +def test_points_out(indices, expected): + out = np.empty(4, dtype=object) + out[2] = empty_point + actual = shapely.points( + [[2, 3], [2, 3]], + indices=indices, + out=out, + ) + assert_geometries_equal(out, expected) + assert actual is out + + +@pytest.mark.parametrize( + "coordinates,indices,expected", + [ + ([[1, 1], [2, 2]], [0, 0], [lstrs([[1, 1], [2, 2]])]), + ([[1, 1, 1], [2, 2, 2]], [0, 0], [lstrs([[1, 1, 1], [2, 2, 2]])]), + ( + [[1, 1], [2, 2], [2, 2], [3, 3]], + [0, 0, 1, 1], + [lstrs([[1, 1], [2, 2]]), lstrs([[2, 2], [3, 3]])], + ), + ], +) +def test_linestrings(coordinates, indices, expected): + actual = shapely.linestrings( + np.array(coordinates, dtype=float), indices=np.array(indices, dtype=np.intp) + ) + assert_geometries_equal(actual, expected) + + +def test_linestrings_invalid(): + # attempt to construct linestrings with 1 coordinate + with pytest.raises(shapely.GEOSException): + shapely.linestrings([[1, 1], [2, 2]], indices=[0, 1]) + + +@pytest.mark.parametrize( + "indices,expected", + [ + ([0, 0, 0, 1, 1, 1], [line_string, line_string, empty_point, None]), + ([0, 0, 0, 3, 3, 3], [line_string, None, empty_point, line_string]), + ([2, 2, 2, 3, 3, 3], [None, None, line_string, line_string]), + ], +) +def test_linestrings_out(indices, expected): + out = np.empty(4, dtype=object) + out[2] = empty_point + actual = shapely.linestrings( + [(0, 0), (1, 0), (1, 1), (0, 0), (1, 0), (1, 1)], + indices=indices, + out=out, + ) + assert_geometries_equal(out, expected) + assert actual is out + + +@pytest.mark.parametrize( + "coordinates", [([[1, 1], [2, 1], [2, 2], [1, 1]]), ([[1, 1], [2, 1], [2, 2]])] +) +def test_linearrings(coordinates): + actual = shapely.linearrings( + np.array(coordinates, dtype=np.float64), + indices=np.zeros(len(coordinates), dtype=np.intp), + ) + assert_geometries_equal(actual, shapely.linearrings(coordinates)) + + +@pytest.mark.parametrize( + "coordinates", + [ + ([[1, np.nan], [2, 1], [2, 2], [1, 1]]), # starting with nan + ], +) +def test_linearrings_invalid(coordinates): + # attempt to construct linestrings with 1 coordinate + with pytest.raises((shapely.GEOSException, ValueError)): + shapely.linearrings(coordinates, indices=np.zeros(len(coordinates))) + + +def test_linearrings_unclosed_all_coords_equal(): + actual = shapely.linearrings([(0, 0), (0, 0), (0, 0)], indices=np.zeros(3)) + assert_geometries_equal(actual, LinearRing([(0, 0), (0, 0), (0, 0), (0, 0)])) + + +@pytest.mark.parametrize( + "indices,expected", + [ + ([0, 0, 0, 0, 0], [linear_ring, None, None, empty_point]), + ([1, 1, 1, 1, 1], [None, linear_ring, None, empty_point]), + ([3, 3, 3, 3, 3], [None, None, None, linear_ring]), + ], +) +def test_linearrings_out(indices, expected): + out = np.empty(4, dtype=object) + out[3] = empty_point + actual = shapely.linearrings( + [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)], + indices=indices, + out=out, + ) + assert_geometries_equal(out, expected) + assert actual is out + + +@pytest.mark.parametrize("dim", [2, 3]) +@pytest.mark.parametrize("order", ["C", "F"]) +def test_linearrings_buffer(dim, order): + coords = np.random.randn(10, 4, dim) + coords1 = np.asarray(coords.reshape(10 * 4, dim), order=order) + indices1 = np.repeat(range(10), 4) + result1 = shapely.linearrings(coords1, indices=indices1) + + # with manual closure -> can directly copy from buffer if C order + coords2 = np.hstack((coords, coords[:, [0], :])) + coords2 = np.asarray(coords2.reshape(10 * 5, dim), order=order) + indices2 = np.repeat(range(10), 5) + result2 = shapely.linearrings(coords2, indices=indices2) + assert_geometries_equal(result1, result2) + + +hole_1 = shapely.linearrings([(0.2, 0.2), (0.2, 0.4), (0.4, 0.4)]) +hole_2 = shapely.linearrings([(0.6, 0.6), (0.6, 0.8), (0.8, 0.8)]) +poly = shapely.polygons(linear_ring) +poly_empty = Polygon() +poly_hole_1 = shapely.polygons(linear_ring, holes=[hole_1]) +poly_hole_2 = shapely.polygons(linear_ring, holes=[hole_2]) +poly_hole_1_2 = shapely.polygons(linear_ring, holes=[hole_1, hole_2]) + + +@pytest.mark.parametrize( + "rings,indices,expected", + [ + ([linear_ring, linear_ring], [0, 1], [poly, poly]), + ([None, linear_ring], [0, 1], [poly_empty, poly]), + ([None, linear_ring, None, None], [0, 0, 1, 1], [poly, poly_empty]), + ([linear_ring, hole_1, linear_ring], [0, 0, 1], [poly_hole_1, poly]), + ([linear_ring, linear_ring, hole_1], [0, 1, 1], [poly, poly_hole_1]), + ([None, linear_ring, linear_ring, hole_1], [0, 0, 1, 1], [poly, poly_hole_1]), + ([linear_ring, None, linear_ring, hole_1], [0, 0, 1, 1], [poly, poly_hole_1]), + ([linear_ring, None, linear_ring, hole_1], [0, 1, 1, 1], [poly, poly_hole_1]), + ([linear_ring, linear_ring, None, hole_1], [0, 1, 1, 1], [poly, poly_hole_1]), + ([linear_ring, linear_ring, hole_1, None], [0, 1, 1, 1], [poly, poly_hole_1]), + ( + [linear_ring, hole_1, hole_2, linear_ring], + [0, 0, 0, 1], + [poly_hole_1_2, poly], + ), + ( + [linear_ring, hole_1, linear_ring, hole_2], + [0, 0, 1, 1], + [poly_hole_1, poly_hole_2], + ), + ( + [linear_ring, linear_ring, hole_1, hole_2], + [0, 1, 1, 1], + [poly, poly_hole_1_2], + ), + ( + [linear_ring, hole_1, None, hole_2, linear_ring], + [0, 0, 0, 0, 1], + [poly_hole_1_2, poly], + ), + ( + [linear_ring, hole_1, None, linear_ring, hole_2], + [0, 0, 0, 1, 1], + [poly_hole_1, poly_hole_2], + ), + ( + [linear_ring, hole_1, linear_ring, None, hole_2], + [0, 0, 1, 1, 1], + [poly_hole_1, poly_hole_2], + ), + ], +) +def test_polygons(rings, indices, expected): + actual = shapely.polygons( + np.array(rings, dtype=object), indices=np.array(indices, dtype=np.intp) + ) + assert_geometries_equal(actual, expected) + + +@pytest.mark.parametrize( + "indices,expected", + [ + ([0, 1], [poly, poly, empty_point, None]), + ([0, 3], [poly, None, empty_point, poly]), + ([2, 3], [None, None, poly, poly]), + ], +) +def test_polygons_out(indices, expected): + out = np.empty(4, dtype=object) + out[2] = empty_point + actual = shapely.polygons([linear_ring, linear_ring], indices=indices, out=out) + assert_geometries_equal(out, expected) + assert actual is out + + +@pytest.mark.parametrize( + "func", + [ + shapely.polygons, + shapely.multipoints, + shapely.multilinestrings, + shapely.multipolygons, + shapely.geometrycollections, + ], +) +@pytest.mark.parametrize("indices", [np.array([point]), " hello", [0, 1], [-1]]) +def test_invalid_indices_collections(func, indices): + with pytest.raises((TypeError, ValueError)): + func([point], indices=indices) + + +@pytest.mark.parametrize( + "geometries,indices,expected", + [ + ([point, line_string], [0, 0], [geom_coll([point, line_string])]), + ([point, line_string], [0, 1], [geom_coll([point]), geom_coll([line_string])]), + ([point, None], [0, 0], [geom_coll([point])]), + ([point, None], [0, 1], [geom_coll([point]), geom_coll([])]), + ([None, point, None, None], [0, 0, 1, 1], [geom_coll([point]), geom_coll([])]), + ([point, None, line_string], [0, 0, 0], [geom_coll([point, line_string])]), + ], +) +def test_geometrycollections(geometries, indices, expected): + actual = shapely.geometrycollections( + np.array(geometries, dtype=object), indices=indices + ) + assert_geometries_equal(actual, expected) + + +def test_geometrycollections_no_index_raises(): + with pytest.raises(ValueError): + shapely.geometrycollections( + np.array([point, line_string], dtype=object), indices=[0, 2] + ) + + +@pytest.mark.parametrize( + "indices,expected", + [ + ([0, 0], [geom_coll([point, line_string]), None, None, empty_point]), + ([3, 3], [None, None, None, geom_coll([point, line_string])]), + ], +) +def test_geometrycollections_out(indices, expected): + out = np.empty(4, dtype=object) + out[3] = empty_point + actual = shapely.geometrycollections([point, line_string], indices=indices, out=out) + assert_geometries_equal(out, expected) + assert actual is out + + +def test_multipoints(): + actual = shapely.multipoints( + np.array([point], dtype=object), indices=np.zeros(1, dtype=np.intp) + ) + assert_geometries_equal(actual, shapely.multipoints([point])) + + +def test_multilinestrings(): + actual = shapely.multilinestrings( + np.array([line_string], dtype=object), indices=np.zeros(1, dtype=np.intp) + ) + assert_geometries_equal(actual, shapely.multilinestrings([line_string])) + + +def test_multilinearrings(): + actual = shapely.multilinestrings( + np.array([linear_ring], dtype=object), indices=np.zeros(1, dtype=np.intp) + ) + assert_geometries_equal(actual, shapely.multilinestrings([linear_ring])) + + +def test_multipolygons(): + actual = shapely.multipolygons( + np.array([polygon], dtype=object), indices=np.zeros(1, dtype=np.intp) + ) + assert_geometries_equal(actual, shapely.multipolygons([polygon])) + + +@pytest.mark.parametrize( + "geometries,func", + [ + ([point], shapely.polygons), + ([line_string], shapely.polygons), + ([polygon], shapely.polygons), + ([line_string], shapely.multipoints), + ([polygon], shapely.multipoints), + ([point], shapely.multilinestrings), + ([polygon], shapely.multilinestrings), + ([point], shapely.multipolygons), + ([line_string], shapely.multipolygons), + ], +) +def test_incompatible_types(geometries, func): + with pytest.raises(TypeError): + func(geometries, indices=[0]) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/test_linear.py b/vllm/lib/python3.10/site-packages/shapely/tests/test_linear.py new file mode 100644 index 0000000000000000000000000000000000000000..dbdea59142e7e6aa8b6858479d997ef290402d76 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/test_linear.py @@ -0,0 +1,212 @@ +import numpy as np +import pytest + +import shapely +from shapely import GeometryCollection, LinearRing, LineString, MultiLineString, Point +from shapely.errors import UnsupportedGEOSVersionError +from shapely.testing import assert_geometries_equal +from shapely.tests.common import ( + empty_line_string, + empty_point, + line_string, + linear_ring, + multi_line_string, + multi_point, + multi_polygon, + point, + polygon, +) + + +def test_line_interpolate_point_geom_array(): + actual = shapely.line_interpolate_point( + [line_string, linear_ring, multi_line_string], -1 + ) + assert_geometries_equal(actual[0], Point(1, 0)) + assert_geometries_equal(actual[1], Point(0, 1)) + assert_geometries_equal(actual[2], Point(0.5528, 1.1056), tolerance=0.001) + + +def test_line_interpolate_point_geom_array_normalized(): + actual = shapely.line_interpolate_point( + [line_string, linear_ring, multi_line_string], 1, normalized=True + ) + assert_geometries_equal(actual[0], Point(1, 1)) + assert_geometries_equal(actual[1], Point(0, 0)) + assert_geometries_equal(actual[2], Point(1, 2)) + + +def test_line_interpolate_point_float_array(): + actual = shapely.line_interpolate_point(line_string, [0.2, 1.5, -0.2]) + assert_geometries_equal(actual[0], Point(0.2, 0)) + assert_geometries_equal(actual[1], Point(1, 0.5)) + assert_geometries_equal(actual[2], Point(1, 0.8)) + + +@pytest.mark.parametrize("normalized", [False, True]) +@pytest.mark.parametrize( + "geom", + [ + LineString(), + LinearRing(), + MultiLineString(), + shapely.from_wkt("MULTILINESTRING (EMPTY, (0 0, 1 1))"), + GeometryCollection(), + GeometryCollection([LineString(), Point(1, 1)]), + ], +) +def test_line_interpolate_point_empty(geom, normalized): + # These geometries segfault in some versions of GEOS (in 3.8.0, still + # some of them segfault). Instead, we patched this to return POINT EMPTY. + # This matches GEOS 3.8.0 behavior on simple empty geometries. + assert_geometries_equal( + shapely.line_interpolate_point(geom, 0.2, normalized=normalized), empty_point + ) + + +@pytest.mark.parametrize("normalized", [False, True]) +@pytest.mark.parametrize( + "geom", + [ + empty_point, + point, + polygon, + multi_point, + multi_polygon, + shapely.geometrycollections([point]), + shapely.geometrycollections([polygon]), + shapely.geometrycollections([multi_line_string]), + shapely.geometrycollections([multi_point]), + shapely.geometrycollections([multi_polygon]), + ], +) +def test_line_interpolate_point_invalid_type(geom, normalized): + with pytest.raises(TypeError): + assert shapely.line_interpolate_point(geom, 0.2, normalized=normalized) + + +def test_line_interpolate_point_none(): + assert shapely.line_interpolate_point(None, 0.2) is None + + +def test_line_interpolate_point_nan(): + assert shapely.line_interpolate_point(line_string, np.nan) is None + + +def test_line_locate_point_geom_array(): + point = shapely.points(0, 1) + actual = shapely.line_locate_point([line_string, linear_ring], point) + np.testing.assert_allclose(actual, [0.0, 3.0]) + + +def test_line_locate_point_geom_array2(): + points = shapely.points([[0, 0], [1, 0]]) + actual = shapely.line_locate_point(line_string, points) + np.testing.assert_allclose(actual, [0.0, 1.0]) + + +@pytest.mark.parametrize("normalized", [False, True]) +def test_line_locate_point_none(normalized): + assert np.isnan(shapely.line_locate_point(line_string, None, normalized=normalized)) + assert np.isnan(shapely.line_locate_point(None, point, normalized=normalized)) + + +@pytest.mark.parametrize("normalized", [False, True]) +def test_line_locate_point_empty(normalized): + assert np.isnan( + shapely.line_locate_point(line_string, empty_point, normalized=normalized) + ) + assert np.isnan( + shapely.line_locate_point(empty_line_string, point, normalized=normalized) + ) + + +@pytest.mark.parametrize("normalized", [False, True]) +def test_line_locate_point_invalid_geometry(normalized): + with pytest.raises(shapely.GEOSException): + shapely.line_locate_point(line_string, line_string, normalized=normalized) + + with pytest.raises(shapely.GEOSException): + shapely.line_locate_point(polygon, point, normalized=normalized) + + +def test_line_merge_geom_array(): + actual = shapely.line_merge([line_string, multi_line_string]) + assert_geometries_equal(actual[0], line_string) + assert_geometries_equal(actual[1], LineString([(0, 0), (1, 2)])) + + +@pytest.mark.skipif(shapely.geos_version < (3, 11, 0), reason="GEOS < 3.11.0") +def test_line_merge_directed(): + lines = MultiLineString([[(0, 0), (1, 0)], [(0, 0), (3, 0)]]) + # Merge lines without directed, this requires changing the vertex ordering + result = shapely.line_merge(lines) + assert_geometries_equal(result, LineString([(1, 0), (0, 0), (3, 0)])) + # Since the lines can't be merged when directed is specified + # the original geometry is returned + result = shapely.line_merge(lines, directed=True) + assert_geometries_equal(result, lines) + + +@pytest.mark.skipif(shapely.geos_version >= (3, 11, 0), reason="GEOS >= 3.11.0") +def test_line_merge_error(): + lines = MultiLineString([[(0, 0), (1, 0)], [(0, 0), (3, 0)]]) + with pytest.raises(UnsupportedGEOSVersionError): + shapely.line_merge(lines, directed=True) + + +def test_shared_paths_linestring(): + g1 = shapely.linestrings([(0, 0), (1, 0), (1, 1)]) + g2 = shapely.linestrings([(0, 0), (1, 0)]) + actual1 = shapely.shared_paths(g1, g2) + assert_geometries_equal( + shapely.get_geometry(actual1, 0), shapely.multilinestrings([g2]) + ) + + +def test_shared_paths_none(): + assert shapely.shared_paths(line_string, None) is None + assert shapely.shared_paths(None, line_string) is None + assert shapely.shared_paths(None, None) is None + + +def test_shared_paths_non_linestring(): + g1 = shapely.linestrings([(0, 0), (1, 0), (1, 1)]) + g2 = shapely.points(0, 1) + with pytest.raises(shapely.GEOSException): + shapely.shared_paths(g1, g2) + + +def _prepare_input(geometry, prepare): + """Prepare without modifying in-place""" + if prepare: + geometry = shapely.transform(geometry, lambda x: x) # makes a copy + shapely.prepare(geometry) + return geometry + else: + return geometry + + +@pytest.mark.parametrize("prepare", [True, False]) +def test_shortest_line(prepare): + g1 = shapely.linestrings([(0, 0), (1, 0), (1, 1)]) + g2 = shapely.linestrings([(0, 3), (3, 0)]) + actual = shapely.shortest_line(_prepare_input(g1, prepare), g2) + expected = shapely.linestrings([(1, 1), (1.5, 1.5)]) + assert shapely.equals(actual, expected) + + +@pytest.mark.parametrize("prepare", [True, False]) +def test_shortest_line_none(prepare): + assert shapely.shortest_line(_prepare_input(line_string, prepare), None) is None + assert shapely.shortest_line(None, line_string) is None + assert shapely.shortest_line(None, None) is None + + +@pytest.mark.parametrize("prepare", [True, False]) +def test_shortest_line_empty(prepare): + g1 = _prepare_input(line_string, prepare) + assert shapely.shortest_line(g1, empty_line_string) is None + g1_empty = _prepare_input(empty_line_string, prepare) + assert shapely.shortest_line(g1_empty, line_string) is None + assert shapely.shortest_line(g1_empty, empty_line_string) is None diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/test_measurement.py b/vllm/lib/python3.10/site-packages/shapely/tests/test_measurement.py new file mode 100644 index 0000000000000000000000000000000000000000..45a4a6f337410155cfbfe8809793f0b5ceff09c8 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/test_measurement.py @@ -0,0 +1,355 @@ +import numpy as np +import pytest +from numpy.testing import assert_allclose, assert_array_equal + +import shapely +from shapely import GeometryCollection, LineString, MultiPoint, Point, Polygon +from shapely.tests.common import ( + empty, + geometry_collection, + ignore_invalid, + line_string, + linear_ring, + multi_line_string, + multi_point, + multi_polygon, + point, + point_polygon_testdata, + polygon, + polygon_with_hole, +) + + +@pytest.mark.parametrize( + "geom", + [ + point, + line_string, + linear_ring, + multi_point, + multi_line_string, + geometry_collection, + ], +) +def test_area_non_polygon(geom): + assert shapely.area(geom) == 0.0 + + +def test_area(): + actual = shapely.area([polygon, polygon_with_hole, multi_polygon]) + assert actual.tolist() == [4.0, 96.0, 1.01] + + +def test_distance(): + actual = shapely.distance(*point_polygon_testdata) + expected = [2 * 2**0.5, 2**0.5, 0, 0, 0, 2**0.5] + np.testing.assert_allclose(actual, expected) + + +def test_distance_missing(): + actual = shapely.distance(point, None) + assert np.isnan(actual) + + +def test_distance_duplicated(): + a = Point(1, 2) + b = LineString([(0, 0), (0, 0), (1, 1)]) + with ignore_invalid(shapely.geos_version < (3, 12, 0)): + # https://github.com/shapely/shapely/issues/1552 + # GEOS < 3.12 raises "invalid" floating point errors + actual = shapely.distance(a, b) + assert actual == 1.0 + + +@pytest.mark.parametrize( + "geom,expected", + [ + (point, [2, 3, 2, 3]), + ([point, multi_point], [[2, 3, 2, 3], [0, 0, 1, 2]]), + (shapely.linestrings([[0, 0], [0, 1]]), [0, 0, 0, 1]), + (shapely.linestrings([[0, 0], [1, 0]]), [0, 0, 1, 0]), + (multi_point, [0, 0, 1, 2]), + (multi_polygon, [0, 0, 2.2, 2.2]), + (geometry_collection, [49, -1, 52, 2]), + (empty, [np.nan, np.nan, np.nan, np.nan]), + (None, [np.nan, np.nan, np.nan, np.nan]), + ], +) +def test_bounds(geom, expected): + assert_array_equal(shapely.bounds(geom), expected) + + +@pytest.mark.parametrize( + "geom,shape", + [ + (point, (4,)), + (None, (4,)), + ([point, multi_point], (2, 4)), + ([[point, multi_point], [polygon, point]], (2, 2, 4)), + ([[[point, multi_point]], [[polygon, point]]], (2, 1, 2, 4)), + ], +) +def test_bounds_dimensions(geom, shape): + assert shapely.bounds(geom).shape == shape + + +@pytest.mark.parametrize( + "geom,expected", + [ + (point, [2, 3, 2, 3]), + (shapely.linestrings([[0, 0], [0, 1]]), [0, 0, 0, 1]), + (shapely.linestrings([[0, 0], [1, 0]]), [0, 0, 1, 0]), + (multi_point, [0, 0, 1, 2]), + (multi_polygon, [0, 0, 2.2, 2.2]), + (geometry_collection, [49, -1, 52, 2]), + (empty, [np.nan, np.nan, np.nan, np.nan]), + (None, [np.nan, np.nan, np.nan, np.nan]), + ([empty, empty, None], [np.nan, np.nan, np.nan, np.nan]), + # mixed missing and non-missing coordinates + ([point, None], [2, 3, 2, 3]), + ([point, empty], [2, 3, 2, 3]), + ([point, empty, None], [2, 3, 2, 3]), + ([point, empty, None, multi_point], [0, 0, 2, 3]), + ], +) +def test_total_bounds(geom, expected): + assert_array_equal(shapely.total_bounds(geom), expected) + + +@pytest.mark.parametrize( + "geom", + [ + point, + None, + [point, multi_point], + [[point, multi_point], [polygon, point]], + [[[point, multi_point]], [[polygon, point]]], + ], +) +def test_total_bounds_dimensions(geom): + assert shapely.total_bounds(geom).shape == (4,) + + +def test_length(): + actual = shapely.length( + [ + point, + line_string, + linear_ring, + polygon, + polygon_with_hole, + multi_point, + multi_polygon, + ] + ) + assert actual.tolist() == [0.0, 2.0, 4.0, 8.0, 48.0, 0.0, 4.4] + + +def test_length_missing(): + actual = shapely.length(None) + assert np.isnan(actual) + + +def test_hausdorff_distance(): + # example from GEOS docs + a = shapely.linestrings([[0, 0], [100, 0], [10, 100], [10, 100]]) + b = shapely.linestrings([[0, 100], [0, 10], [80, 10]]) + with ignore_invalid(shapely.geos_version < (3, 12, 0)): + # Hausdorff distance emits "invalid value encountered" + # (see https://github.com/libgeos/geos/issues/515) + actual = shapely.hausdorff_distance(a, b) + assert actual == pytest.approx(22.360679775, abs=1e-7) + + +def test_hausdorff_distance_densify(): + # example from GEOS docs + a = shapely.linestrings([[0, 0], [100, 0], [10, 100], [10, 100]]) + b = shapely.linestrings([[0, 100], [0, 10], [80, 10]]) + with ignore_invalid(shapely.geos_version < (3, 12, 0)): + # Hausdorff distance emits "invalid value encountered" + # (see https://github.com/libgeos/geos/issues/515) + actual = shapely.hausdorff_distance(a, b, densify=0.001) + assert actual == pytest.approx(47.8, abs=0.1) + + +def test_hausdorff_distance_missing(): + actual = shapely.hausdorff_distance(point, None) + assert np.isnan(actual) + actual = shapely.hausdorff_distance(point, None, densify=0.001) + assert np.isnan(actual) + + +def test_hausdorff_densify_nan(): + actual = shapely.hausdorff_distance(point, point, densify=np.nan) + assert np.isnan(actual) + + +def test_distance_empty(): + actual = shapely.distance(point, empty) + assert np.isnan(actual) + + +def test_hausdorff_distance_empty(): + actual = shapely.hausdorff_distance(point, empty) + assert np.isnan(actual) + + +def test_hausdorff_distance_densify_empty(): + actual = shapely.hausdorff_distance(point, empty, densify=0.2) + assert np.isnan(actual) + + +@pytest.mark.skipif(shapely.geos_version < (3, 7, 0), reason="GEOS < 3.7") +@pytest.mark.parametrize( + "geom1, geom2, expected", + [ + # identical geometries should have 0 distance + ( + shapely.linestrings([[0, 0], [100, 0]]), + shapely.linestrings([[0, 0], [100, 0]]), + 0, + ), + # example from GEOS docs + ( + shapely.linestrings([[0, 0], [50, 200], [100, 0], [150, 200], [200, 0]]), + shapely.linestrings([[0, 200], [200, 150], [0, 100], [200, 50], [0, 0]]), + 200, + ), + # same geometries but different curve direction results in maximum + # distance between vertices on the lines. + ( + shapely.linestrings([[0, 0], [50, 200], [100, 0], [150, 200], [200, 0]]), + shapely.linestrings([[200, 0], [150, 200], [100, 0], [50, 200], [0, 0]]), + 200, + ), + # another example from GEOS docs + ( + shapely.linestrings([[0, 0], [50, 200], [100, 0], [150, 200], [200, 0]]), + shapely.linestrings([[0, 0], [200, 50], [0, 100], [200, 150], [0, 200]]), + 282.842712474619, + ), + # example from GEOS tests + ( + shapely.linestrings([[0, 0], [100, 0]]), + shapely.linestrings([[0, 0], [50, 50], [100, 0]]), + 70.7106781186548, + ), + ], +) +def test_frechet_distance(geom1, geom2, expected): + actual = shapely.frechet_distance(geom1, geom2) + assert actual == pytest.approx(expected, abs=1e-12) + + +@pytest.mark.skipif(shapely.geos_version < (3, 7, 0), reason="GEOS < 3.7") +@pytest.mark.parametrize( + "geom1, geom2, densify, expected", + [ + # example from GEOS tests + ( + shapely.linestrings([[0, 0], [100, 0]]), + shapely.linestrings([[0, 0], [50, 50], [100, 0]]), + 0.001, + 50, + ) + ], +) +def test_frechet_distance_densify(geom1, geom2, densify, expected): + actual = shapely.frechet_distance(geom1, geom2, densify=densify) + assert actual == pytest.approx(expected, abs=1e-12) + + +@pytest.mark.skipif(shapely.geos_version < (3, 7, 0), reason="GEOS < 3.7") +@pytest.mark.parametrize( + "geom1, geom2", + [ + (line_string, None), + (None, line_string), + (None, None), + (line_string, empty), + (empty, line_string), + (empty, empty), + ], +) +def test_frechet_distance_nan_for_invalid_geometry_inputs(geom1, geom2): + actual = shapely.frechet_distance(geom1, geom2) + assert np.isnan(actual) + + +@pytest.mark.skipif(shapely.geos_version < (3, 7, 0), reason="GEOS < 3.7") +def test_frechet_densify_ndarray(): + actual = shapely.frechet_distance( + shapely.linestrings([[0, 0], [100, 0]]), + shapely.linestrings([[0, 0], [50, 50], [100, 0]]), + densify=[0.1, 0.2, 1], + ) + expected = np.array([50, 50.99019514, 70.7106781186548]) + np.testing.assert_array_almost_equal(actual, expected) + + +@pytest.mark.skipif(shapely.geos_version < (3, 7, 0), reason="GEOS < 3.7") +def test_frechet_densify_nan(): + actual = shapely.frechet_distance(line_string, line_string, densify=np.nan) + assert np.isnan(actual) + + +@pytest.mark.skipif(shapely.geos_version < (3, 7, 0), reason="GEOS < 3.7") +@pytest.mark.parametrize("densify", [0, -1, 2]) +def test_frechet_densify_invalid_values(densify): + with pytest.raises(shapely.GEOSException, match="Fraction is not in range"): + shapely.frechet_distance(line_string, line_string, densify=densify) + + +@pytest.mark.skipif(shapely.geos_version < (3, 7, 0), reason="GEOS < 3.7") +def test_frechet_distance_densify_empty(): + actual = shapely.frechet_distance(line_string, empty, densify=0.2) + assert np.isnan(actual) + + +@pytest.mark.skipif(shapely.geos_version < (3, 6, 0), reason="GEOS < 3.6") +def test_minimum_clearance(): + actual = shapely.minimum_clearance([polygon, polygon_with_hole, multi_polygon]) + assert_allclose(actual, [2.0, 2.0, 0.1]) + + +@pytest.mark.skipif(shapely.geos_version < (3, 6, 0), reason="GEOS < 3.6") +def test_minimum_clearance_nonexistent(): + actual = shapely.minimum_clearance([point, empty]) + assert np.isinf(actual).all() + + +@pytest.mark.skipif(shapely.geos_version < (3, 6, 0), reason="GEOS < 3.6") +def test_minimum_clearance_missing(): + actual = shapely.minimum_clearance(None) + assert np.isnan(actual) + + +@pytest.mark.skipif(shapely.geos_version < (3, 8, 0), reason="GEOS < 3.8") +@pytest.mark.parametrize( + "geometry, expected", + [ + ( + Polygon([(0, 5), (5, 10), (10, 5), (5, 0), (0, 5)]), + 5, + ), + ( + LineString([(1, 0), (1, 10)]), + 5, + ), + ( + MultiPoint([(2, 2), (4, 2)]), + 1, + ), + ( + Point(2, 2), + 0, + ), + ( + GeometryCollection(), + 0, + ), + ], +) +def test_minimum_bounding_radius(geometry, expected): + actual = shapely.minimum_bounding_radius(geometry) + assert actual == pytest.approx(expected, abs=1e-12) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/test_plotting.py b/vllm/lib/python3.10/site-packages/shapely/tests/test_plotting.py new file mode 100644 index 0000000000000000000000000000000000000000..f06bec2281bd2c01141e7a9446c29037aef1e88a --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/test_plotting.py @@ -0,0 +1,103 @@ +import pytest +from numpy.testing import assert_allclose + +from shapely import box, get_coordinates, LineString, MultiLineString, Point +from shapely.plotting import patch_from_polygon, plot_line, plot_points, plot_polygon + +pytest.importorskip("matplotlib") + + +def test_patch_from_polygon(): + poly = box(0, 0, 1, 1) + artist = patch_from_polygon(poly, facecolor="red", edgecolor="blue", linewidth=3) + assert equal_color(artist.get_facecolor(), "red") + assert equal_color(artist.get_edgecolor(), "blue") + assert artist.get_linewidth() == 3 + + +def test_patch_from_polygon_with_interior(): + poly = box(0, 0, 1, 1).difference(box(0.2, 0.2, 0.5, 0.5)) + artist = patch_from_polygon(poly, facecolor="red", edgecolor="blue", linewidth=3) + assert equal_color(artist.get_facecolor(), "red") + assert equal_color(artist.get_edgecolor(), "blue") + assert artist.get_linewidth() == 3 + + +def test_patch_from_multipolygon(): + poly = box(0, 0, 1, 1).union(box(2, 2, 3, 3)) + artist = patch_from_polygon(poly, facecolor="red", edgecolor="blue", linewidth=3) + assert equal_color(artist.get_facecolor(), "red") + assert equal_color(artist.get_edgecolor(), "blue") + assert artist.get_linewidth() == 3 + + +def test_plot_polygon(): + poly = box(0, 0, 1, 1) + artist, _ = plot_polygon(poly) + plot_coords = artist.get_path().vertices + assert_allclose(plot_coords, get_coordinates(poly)) + + # overriding default styling + artist = plot_polygon(poly, add_points=False, color="red", linewidth=3) + assert equal_color(artist.get_facecolor(), "red", alpha=0.3) + assert equal_color(artist.get_edgecolor(), "red", alpha=1.0) + assert artist.get_linewidth() == 3 + + +def test_plot_polygon_with_interior(): + poly = box(0, 0, 1, 1).difference(box(0.2, 0.2, 0.5, 0.5)) + artist, _ = plot_polygon(poly) + plot_coords = artist.get_path().vertices + assert_allclose(plot_coords, get_coordinates(poly)) + + +def test_plot_multipolygon(): + poly = box(0, 0, 1, 1).union(box(2, 2, 3, 3)) + artist, _ = plot_polygon(poly) + plot_coords = artist.get_path().vertices + assert_allclose(plot_coords, get_coordinates(poly)) + + +def test_plot_line(): + line = LineString([(0, 0), (1, 0), (1, 1)]) + artist, _ = plot_line(line) + plot_coords = artist.get_path().vertices + assert_allclose(plot_coords, get_coordinates(line)) + + # overriding default styling + artist = plot_line(line, add_points=False, color="red", linewidth=3) + assert equal_color(artist.get_edgecolor(), "red") + assert equal_color(artist.get_facecolor(), "none") + assert artist.get_linewidth() == 3 + + +def test_plot_multilinestring(): + line = MultiLineString( + [LineString([(0, 0), (1, 0), (1, 1)]), LineString([(2, 2), (3, 3)])] + ) + artist, _ = plot_line(line) + plot_coords = artist.get_path().vertices + assert_allclose(plot_coords, get_coordinates(line)) + + +def test_plot_points(): + for geom in [Point(0, 0), LineString([(0, 0), (1, 0), (1, 1)]), box(0, 0, 1, 1)]: + artist = plot_points(geom) + plot_coords = artist.get_path().vertices + assert_allclose(plot_coords, get_coordinates(geom)) + assert artist.get_linestyle() == "None" + + # overriding default styling + geom = Point(0, 0) + artist = plot_points(geom, color="red", marker="+", fillstyle="top") + assert artist.get_color() == "red" + assert artist.get_marker() == "+" + assert artist.get_fillstyle() == "top" + + +def equal_color(actual, expected, alpha=None): + import matplotlib.colors as colors + + conv = colors.colorConverter + + return actual == conv.to_rgba(expected, alpha=alpha) diff --git a/vllm/lib/python3.10/site-packages/shapely/tests/test_testing.py b/vllm/lib/python3.10/site-packages/shapely/tests/test_testing.py new file mode 100644 index 0000000000000000000000000000000000000000..73322a6ddf0609fee8b094698764393f8e31fd21 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/shapely/tests/test_testing.py @@ -0,0 +1,103 @@ +import numpy as np +import pytest + +import shapely +from shapely.testing import assert_geometries_equal +from shapely.tests.common import ( + all_types, + empty, + empty_line_string, + empty_line_string_z, + empty_point, + empty_point_z, + empty_polygon, + line_string, + line_string_nan, + line_string_z, + point, +) + +EMPTY_GEOMS = ( + empty_point, + empty_point_z, + empty_line_string, + empty_line_string_z, + empty_polygon, + empty, +) + +line_string_reversed = shapely.linestrings([(0, 0), (1, 0), (1, 1)][::-1]) + + +PRE_GEOS_390 = pytest.mark.skipif( + shapely.geos_version < (3, 9, 0), + reason="2D and 3D empty geometries did not have dimensionality before GEOS 3.9", +) + + +def make_array(left, right, use_array): + if use_array in ("left", "both"): + left = np.array([left] * 3, dtype=object) + if use_array in ("right", "both"): + right = np.array([right] * 3, dtype=object) + return left, right + + +@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"]) +@pytest.mark.parametrize("geom", all_types + EMPTY_GEOMS) +def test_assert_geometries_equal(geom, use_array): + assert_geometries_equal(*make_array(geom, geom, use_array)) + + +@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"]) +@pytest.mark.parametrize( + "geom1,geom2", + [ + (point, line_string), + (line_string, line_string_z), + (empty_point, empty_polygon), + pytest.param(empty_point, empty_point_z, marks=PRE_GEOS_390), + pytest.param(empty_line_string, empty_line_string_z, marks=PRE_GEOS_390), + ], +) +def test_assert_geometries_not_equal(geom1, geom2, use_array): + with pytest.raises(AssertionError): + assert_geometries_equal(*make_array(geom1, geom2, use_array)) + + +@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"]) +def test_assert_none_equal(use_array): + assert_geometries_equal(*make_array(None, None, use_array)) + + +@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"]) +def test_assert_none_not_equal(use_array): + with pytest.raises(AssertionError): + assert_geometries_equal(*make_array(None, None, use_array), equal_none=False) + + +@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"]) +def test_assert_nan_equal(use_array): + assert_geometries_equal(*make_array(line_string_nan, line_string_nan, use_array)) + + +@pytest.mark.parametrize("use_array", ["none", "left", "right", "both"]) +def test_assert_nan_not_equal(use_array): + with pytest.raises(AssertionError): + assert_geometries_equal( + *make_array(line_string_nan, line_string_nan, use_array), equal_nan=False + ) + + +def test_normalize_true(): + assert_geometries_equal(line_string_reversed, line_string, normalize=True) + + +def test_normalize_default(): + with pytest.raises(AssertionError): + assert_geometries_equal(line_string_reversed, line_string) + + +def test_normalize_false(): + with pytest.raises(AssertionError): + assert_geometries_equal(line_string_reversed, line_string, normalize=False)