Skip to content

Commit

Permalink
Merge e6a70d1 into 7c63580
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews committed Sep 1, 2022
2 parents 7c63580 + e6a70d1 commit 995331d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions shapely/geometry/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ def buffer(self, distance, resolution=16, quadsegs=None,
if mitre_limit == 0.0:
raise ValueError(
'Cannot compute offset from zero-length line segment')
elif not math.isfinite(distance):
raise ValueError("buffer distance must be finite")

if 'buffer_with_params' in self.impl:
params = self._lgeos.GEOSBufferParams_create()
Expand Down
3 changes: 3 additions & 0 deletions shapely/geometry/linestring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""

from ctypes import c_double
import math
import warnings

from shapely.coords import CoordinateSequence
Expand Down Expand Up @@ -171,6 +172,8 @@ def parallel_offset(
if mitre_limit == 0.0:
raise ValueError(
'Cannot compute offset from zero-length line segment')
elif not math.isfinite(distance):
raise ValueError("parallel_offset distance must be finite")
try:
return geom_factory(self.impl['parallel_offset'](
self, distance, resolution, join_style, mitre_limit, side))
Expand Down
9 changes: 9 additions & 0 deletions tests/test_buffer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import pytest

from . import unittest
from shapely import geometry


@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 BufferSingleSidedCase(unittest.TestCase):
""" Test Buffer Point/Line/Polygon with and without single_sided params """

Expand Down
11 changes: 10 additions & 1 deletion tests/test_parallel_offset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import pytest

from . import unittest
from shapely.geometry import LineString, LinearRing
from shapely.wkt import loads


@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):

Expand Down

0 comments on commit 995331d

Please sign in to comment.