# Changeset 7687

Ignore:
Timestamp:
Apr 19, 2010, 1:53:18 PM (13 years ago)
Message:

Added naive check for complex polygons, and unit tests to test it.

Location:
anuga_core/source/anuga/utilities
Files:
2 edited

Unmodified
Removed
• ## anuga_core/source/anuga/utilities/polygon.py

 r7686 return False def is_complex(polygon): def is_complex(polygon, verbose=False): """Check if a polygon is complex (self-intersecting) """ if (abs(i-j) > 1 and type == 1) or (type == 2 and list(point[0]) != list(point[1])) or (type == 3) and type != 4: #                    print 'self-intersecting polygon, type ', type, ' point', point, 'vertex indices ', i, j if verbose: print 'Self-intersecting polygon found, type ', type, ' point', point, 'vertex indices ', i, j return True # check this is a valid polygon # JAMES: don't do this check yet, it's too slow, and there is already pathological data in the unit tests. # if is_complex(polygon): # msg = 'Self-intersecting polygon detected in file' + filename +'. ' # msg = 'ERROR: Self-intersecting polygon detected in file' + filename +'. ' # msg += 'Please fix.' # raise Exception, msg # log.critical(msg) # #            raise Exception, msg return polygon
• ## anuga_core/source/anuga/utilities/test_polygon.py

 r7686 assert res is False def test_is_polygon_complex(self): concave_poly = [[0, 0], [10, 0], [5, 5], [10, 10], [0, 10]] complex_poly = [[0, 0], [10, 0], [5, 5], [5, 15], [5, 7], [10, 10], [0, 10]] assert not is_complex(concave_poly) assert is_complex(complex_poly) complex_poly = [[0, 0], [10, 0], [5, 5], [4, 15], [5, 7], [10, 10], [0, 10]] not_complex = is_complex(concave_poly) complex = is_complex(complex_poly) assert not not_complex assert complex def test_is_polygon_complex2(self): concave_poly = [[0, 0], [10, 0], [11,0], [5, 5], [7,6], [10, 10], [1,5], [0, 10]] complex_poly = [[0, 0], [12,12], [10, 0], [5, 5], [3,18], [4, 15], [5, 7], [10, 10], [0, 10], [16, 12]] not_complex = is_complex(concave_poly) complex = is_complex(complex_poly) assert not not_complex assert complex ################################################################################
Note: See TracChangeset for help on using the changeset viewer.