diff --git a/src/data_morph/shapes/bases/line_collection.py b/src/data_morph/shapes/bases/line_collection.py index f1001572..ac88fff5 100644 --- a/src/data_morph/shapes/bases/line_collection.py +++ b/src/data_morph/shapes/bases/line_collection.py @@ -23,6 +23,11 @@ class LineCollection(Shape): """ def __init__(self, *lines: Iterable[Iterable[Number]]) -> None: + # check that lines that have the same starting and ending points raise an error + for line in lines: + start, end = line + if np.allclose(start, end): + raise ValueError(f'Line {line} has the same start and end point') self.lines = lines """Iterable[Iterable[numbers.Number]]: An iterable of two (x, y) pairs representing the endpoints of a line.""" diff --git a/tests/shapes/bases/test_line_collection.py b/tests/shapes/bases/test_line_collection.py index 6b356552..0b1d39ae 100644 --- a/tests/shapes/bases/test_line_collection.py +++ b/tests/shapes/bases/test_line_collection.py @@ -35,10 +35,10 @@ def test_distance_nonzero(self, line_collection, point, expected_distance): assert pytest.approx(line_collection.distance(*point)) == expected_distance @pytest.mark.parametrize('line', [[(0, 0), (0, 0)], [(-1, -1), (-1, -1)]], ids=str) - def test_distance_to_small_line_magnitude(self, line_collection, line): - """Test _distance_point_to_line() for small line magnitudes.""" - distance = line_collection._distance_point_to_line((30, 50), line) - assert distance == 9999 + def test_line_as_point(self, line): + """Test LineCollection raises a ValueError for small line magnitudes.""" + with pytest.raises(ValueError): + LineCollection(line) def test_repr(self, line_collection): """Test that the __repr__() method is working."""