File: test_equality.py

package info (click to toggle)
python-shapely 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,528 kB
  • sloc: python: 18,648; ansic: 6,615; makefile: 88; sh: 62
file content (24 lines) | stat: -rw-r--r-- 747 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from shapely import Point, Polygon


def test_equals_exact():
    p1 = Point(1.0, 1.0)
    p2 = Point(2.0, 2.0)
    p3 = Point(1.0, 1.0 + 1e-7)
    assert not p1.equals(p2)
    assert not p1.equals_exact(p2, 0.001)
    assert not p1.equals_exact(p3)
    assert p1.equals_exact(p3, 1e-6)

    # test polygons
    shell = [(10, 10), (10, -10), (-10, -10), (-10, 10)]
    holes = [[(1, 1), (1, -1), (-1, -1), (-1, 1)]]
    p1 = Polygon(shell, holes)
    p2 = Polygon(shell, holes=[holes[0][::-1]])
    assert p1.equals(p2)
    assert not p1.equals_exact(p2, 1e-5)
    assert p1.equals_exact(p2, 1e-5, normalize=True)

    hole2 = [(1, 1), (1, -1), (-1, -1), (-1, 1.01)]
    p3 = Polygon(shell, holes=[hole2])
    assert not p1.equals_exact(p3, 1e-5)