|
1 | 1 | #!/usr/bin/env python |
2 | | -import numpy as np |
3 | 2 | from pylineclip import cohensutherland |
4 | | - |
| 3 | +from pytest import approx |
5 | 4 | """ |
6 | 5 | make box with corners LL/UR (1,3) (4,5) |
7 | 6 | and line segment with ends (0,0) (4,6) |
|
10 | 9 |
|
11 | 10 | def main(): |
12 | 11 | # %% LOWER to UPPER test |
13 | | - x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, |
14 | | - 0, 0, 4, 6) |
| 12 | + x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, 0, 0, 4, 6) |
15 | 13 |
|
16 | | - np.testing.assert_array_almost_equal([x1, y1, x2, y2], [2, 3, 3.3333333333333, 5]) |
| 14 | + assert [x1, y1, x2, y2] == approx([2, 3, 3.3333333333333, 5]) |
17 | 15 | # %% no intersection test |
18 | | - x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, |
19 | | - 0, 0.1, 0, 0.1) |
| 16 | + x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, 0, 0.1, 0, 0.1) |
20 | 17 |
|
21 | 18 | assert x1 is None and y1 is None and x2 is None and y2 is None |
22 | 19 | # %% left to right test |
23 | | - x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, |
24 | | - 0, 4, 5, 4) |
25 | | - np.testing.assert_array_almost_equal([x1, y1, x2, y2], [1, 4, 4, 4]) |
| 20 | + x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, 0, 4, 5, 4) |
| 21 | + assert [x1, y1, x2, y2] == [1, 4, 4, 4] |
26 | 22 |
|
27 | 23 |
|
28 | 24 | if __name__ == '__main__': |
|
0 commit comments