Ignore:
Timestamp:
Sep 28, 2005, 10:29:52 AM (19 years ago)
Author:
ole
Message:

Added functionality for excluding polygons in populate_polygon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/test_util.py

    r1835 r1854  
    11121112
    11131113
     1114    def test_populate_polygon_with_exclude(self):
     1115       
     1116
     1117        polygon = [[0,0], [1,0], [1,1], [0,1]]
     1118        ex_poly = [[0,0], [0.5,0], [0.5, 0.5], [0,0.5]] #SW quarter
     1119        points = populate_polygon(polygon, 5, exclude = [ex_poly])
     1120
     1121        assert len(points) == 5
     1122        for point in points:
     1123            assert inside_polygon(point, polygon)
     1124            assert not inside_polygon(point, ex_poly)           
     1125
     1126
     1127        #overlap
     1128        polygon = [[0,0], [1,0], [1,1], [0,1]]
     1129        ex_poly = [[-1,-1], [0.5,0], [0.5, 0.5], [-1,0.5]]
     1130        points = populate_polygon(polygon, 5, exclude = [ex_poly])
     1131
     1132        assert len(points) == 5
     1133        for point in points:
     1134            assert inside_polygon(point, polygon)
     1135            assert not inside_polygon(point, ex_poly)                       
     1136       
     1137        #Multiple
     1138        polygon = [[0,0], [1,0], [1,1], [0,1]]
     1139        ex_poly1 = [[0,0], [0.5,0], [0.5, 0.5], [0,0.5]] #SW quarter
     1140        ex_poly2 = [[0.5,0.5], [0.5,1], [1, 1], [1,0.5]] #NE quarter       
     1141       
     1142        points = populate_polygon(polygon, 20, exclude = [ex_poly1, ex_poly2])
     1143
     1144        assert len(points) == 20
     1145        for point in points:
     1146            assert inside_polygon(point, polygon)
     1147            assert not inside_polygon(point, ex_poly1)
     1148            assert not inside_polygon(point, ex_poly2)                               
     1149       
     1150
     1151        #Very convoluted polygon
     1152        polygon = [[0,0], [10,10], [15,5], [20, 10], [25,0], [30,10], [40,-10]]
     1153        ex_poly = [[-1,-1], [5,0], [5, 5], [-1,5]]
     1154        points = populate_polygon(polygon, 20, exclude = [ex_poly])
     1155       
     1156        assert len(points) == 20
     1157        for point in points:
     1158            assert inside_polygon(point, polygon)
     1159            assert not inside_polygon(point, ex_poly), '%s' %str(point)                       
     1160
     1161
    11141162
    11151163#-------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.