1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from culvert_polygons import * |
---|
4 | |
---|
5 | import unittest |
---|
6 | import os.path |
---|
7 | |
---|
8 | from anuga.geometry.polygon import inside_polygon, polygon_area |
---|
9 | |
---|
10 | |
---|
11 | class Test_poly(unittest.TestCase): |
---|
12 | def setUp(self): |
---|
13 | pass |
---|
14 | |
---|
15 | def tearDown(self): |
---|
16 | pass |
---|
17 | |
---|
18 | |
---|
19 | def test_1(self): |
---|
20 | |
---|
21 | end_point0=[307138.813,6193474] |
---|
22 | end_point1=[307150.563,6193469] |
---|
23 | width=3 |
---|
24 | height=3 |
---|
25 | number_of_barrels=1 |
---|
26 | |
---|
27 | P = create_culvert_polygons(end_point0, |
---|
28 | end_point1, |
---|
29 | width=width, |
---|
30 | height=height, |
---|
31 | number_of_barrels=number_of_barrels) |
---|
32 | |
---|
33 | # Compute area and check that it is greater than 0 |
---|
34 | for key1 in ['exchange_polygon0', |
---|
35 | 'exchange_polygon1']: |
---|
36 | polygon = P[key1] |
---|
37 | area = polygon_area(polygon) |
---|
38 | |
---|
39 | msg = 'Polygon %s ' %(polygon) |
---|
40 | msg += ' has area = %f' % area |
---|
41 | assert area > 0.0, msg |
---|
42 | |
---|
43 | for key2 in ['enquiry_point0', 'enquiry_point1']: |
---|
44 | point = P[key2] |
---|
45 | assert not inside_polygon(point, polygon) |
---|
46 | |
---|
47 | |
---|
48 | def test_2(self): |
---|
49 | #end_point0=[307138.813,6193474] |
---|
50 | #end_point1=[307150.563,6193469] |
---|
51 | end_point0=[10., 5.] |
---|
52 | end_point1=[10., 10.] |
---|
53 | width = 1 |
---|
54 | height = 3.5 |
---|
55 | number_of_barrels=1 |
---|
56 | |
---|
57 | P = create_culvert_polygons(end_point0, |
---|
58 | end_point1, |
---|
59 | width=width, |
---|
60 | height=height, |
---|
61 | number_of_barrels=number_of_barrels) |
---|
62 | |
---|
63 | # Compute area and check that it is greater than 0 |
---|
64 | for key1 in ['exchange_polygon0', |
---|
65 | 'exchange_polygon1']: |
---|
66 | polygon = P[key1] |
---|
67 | area = polygon_area(polygon) |
---|
68 | |
---|
69 | msg = 'Polygon %s ' % (polygon) |
---|
70 | msg += ' has area = %f' % area |
---|
71 | assert area > 0.0, msg |
---|
72 | |
---|
73 | for key2 in ['enquiry_point0', 'enquiry_point1']: |
---|
74 | point = P[key2] |
---|
75 | assert not inside_polygon(point, polygon) |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | #------------------------------------------------------------- |
---|
80 | if __name__ == "__main__": |
---|
81 | suite = unittest.makeSuite(Test_poly, 'test') |
---|
82 | runner = unittest.TextTestRunner() |
---|
83 | runner.run(suite) |
---|
84 | |
---|