test_equality.py 747 B

123456789101112131415161718192021222324
  1. from shapely import Point, Polygon
  2. def test_equals_exact():
  3. p1 = Point(1.0, 1.0)
  4. p2 = Point(2.0, 2.0)
  5. p3 = Point(1.0, 1.0 + 1e-7)
  6. assert not p1.equals(p2)
  7. assert not p1.equals_exact(p2, 0.001)
  8. assert not p1.equals_exact(p3)
  9. assert p1.equals_exact(p3, 1e-6)
  10. # test polygons
  11. shell = [(10, 10), (10, -10), (-10, -10), (-10, 10)]
  12. holes = [[(1, 1), (1, -1), (-1, -1), (-1, 1)]]
  13. p1 = Polygon(shell, holes)
  14. p2 = Polygon(shell, holes=[holes[0][::-1]])
  15. assert p1.equals(p2)
  16. assert not p1.equals_exact(p2, 1e-5)
  17. assert p1.equals_exact(p2, 1e-5, normalize=True)
  18. hole2 = [(1, 1), (1, -1), (-1, -1), (-1, 1.01)]
  19. p3 = Polygon(shell, holes=[hole2])
  20. assert not p1.equals_exact(p3, 1e-5)