Changeset 7687


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

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

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

Legend:

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

    r7686 r7687  
    322322    return False
    323323
    324 def is_complex(polygon):
     324def is_complex(polygon, verbose=False):
    325325    """Check if a polygon is complex (self-intersecting)
    326326    """
     
    333333
    334334                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               
     335                    if verbose:
     336                        print 'Self-intersecting polygon found, type ', type, ' point', point, 'vertex indices ', i, j               
    336337                    return True
    337338       
     
    996997   
    997998    # 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.
    999999    # if is_complex(polygon):   
    1000             # msg = 'Self-intersecting polygon detected in file' + filename +'. '
     1000            # msg = 'ERROR: Self-intersecting polygon detected in file' + filename +'. '
    10011001            # msg += 'Please fix.'
    1002             # raise Exception, msg
     1002            # log.critical(msg)
     1003# #            raise Exception, msg
    10031004   
    10041005    return polygon
  • anuga_core/source/anuga/utilities/test_polygon.py

    r7686 r7687  
    18061806        assert res is False
    18071807
     1808       
    18081809    def test_is_polygon_complex(self):
    18091810        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        
     1811        complex_poly = [[0, 0], [10, 0], [5, 5], [4, 15], [5, 7], [10, 10], [0, 10]]
     1812
     1813        not_complex = is_complex(concave_poly)       
     1814        complex = is_complex(complex_poly)       
     1815
     1816        assert not not_complex
     1817        assert complex
     1818
     1819    def test_is_polygon_complex2(self):
     1820        concave_poly = [[0, 0], [10, 0], [11,0], [5, 5], [7,6], [10, 10], [1,5], [0, 10]]
     1821        complex_poly = [[0, 0], [12,12], [10, 0], [5, 5], [3,18], [4, 15], [5, 7], [10, 10], [0, 10], [16, 12]]
     1822
     1823        not_complex = is_complex(concave_poly)       
     1824        complex = is_complex(complex_poly)       
     1825
     1826        assert not not_complex
     1827        assert complex
    18151828       
    18161829################################################################################
Note: See TracChangeset for help on using the changeset viewer.