-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDemoLineclip.py
More file actions
executable file
·25 lines (19 loc) · 681 Bytes
/
DemoLineclip.py
File metadata and controls
executable file
·25 lines (19 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python
from pylineclip import cohensutherland
from pytest import approx
"""
make box with corners LL/UR (1,3) (4,5)
and line segment with ends (0,0) (4,6)
"""
def main():
# %% LOWER to UPPER test
x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, 0, 0, 4, 6)
assert [x1, y1, x2, y2] == approx([2, 3, 3.3333333333333, 5])
# %% no intersection test
x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, 0, 0.1, 0, 0.1)
assert x1 is None and y1 is None and x2 is None and y2 is None
# %% left to right test
x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, 0, 4, 5, 4)
assert [x1, y1, x2, y2] == [1, 4, 4, 4]
if __name__ == '__main__':
main()