test_delaunay.py 838 B

1234567891011121314151617181920212223242526272829303132
  1. import unittest
  2. from shapely.geometry import LineString, Point, Polygon
  3. from shapely.ops import triangulate
  4. class DelaunayTriangulation(unittest.TestCase):
  5. """
  6. Only testing the number of triangles and their type here.
  7. This doesn't actually test the points in the resulting geometries.
  8. """
  9. def setUp(self):
  10. self.p = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
  11. def test_polys(self):
  12. polys = triangulate(self.p)
  13. assert len(polys) == 2
  14. for p in polys:
  15. assert isinstance(p, Polygon)
  16. def test_lines(self):
  17. polys = triangulate(self.p, edges=True)
  18. assert len(polys) == 5
  19. for p in polys:
  20. assert isinstance(p, LineString)
  21. def test_point(self):
  22. p = Point(1, 1)
  23. polys = triangulate(p)
  24. assert len(polys) == 0