Changeset 7686
- Timestamp:
- Apr 15, 2010, 8:45:36 PM (15 years ago)
- Location:
- anuga_core/source/anuga/utilities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/polygon.py
r7553 r7686 322 322 return False 323 323 324 def is_complex(polygon): 325 """Check if a polygon is complex (self-intersecting) 326 """ 327 328 polygon = ensure_numeric(polygon, num.float) 329 330 for i in range(0, len(polygon)-1): 331 for j in range(i+1, len(polygon)-1): 332 (type, point) = intersection([polygon[i], polygon[i+1]], [polygon[j], polygon[j+1]]) 333 334 if (abs(i-j) > 1 and type == 1) or (type == 2 and list(point[0]) != list(point[1])) or (type == 3) and type != 4: 335 # print 'self-intersecting polygon, type ', type, ' point', point, 'vertex indices ', i, j 336 return True 337 338 return False 339 324 340 def is_inside_polygon_quick(point, polygon, closed=True, verbose=False): 325 341 """Determine if one point is inside a polygon … … 978 994 fields = line.split(delimiter) 979 995 polygon.append([float(fields[0]), float(fields[1])]) 980 996 997 # check this is a valid polygon 998 # JAMES: don't do this check yet, it's too slow, and there is already pathological data in the unit tests. 999 # if is_complex(polygon): 1000 # msg = 'Self-intersecting polygon detected in file' + filename +'. ' 1001 # msg += 'Please fix.' 1002 # raise Exception, msg 1003 981 1004 return polygon 982 1005 -
anuga_core/source/anuga/utilities/test_polygon.py
r7308 r7686 1806 1806 assert res is False 1807 1807 1808 def test_is_polygon_complex(self): 1809 concave_poly = [[0, 0], [10, 0], [5, 5], [10, 10], [0, 10]] 1810 complex_poly = [[0, 0], [10, 0], [5, 5], [5, 15], [5, 7], [10, 10], [0, 10]] 1811 1812 assert not is_complex(concave_poly) 1813 assert is_complex(complex_poly) 1814 1815 1808 1816 ################################################################################ 1809 1817
Note: See TracChangeset
for help on using the changeset viewer.