Ignore:
Timestamp:
Oct 30, 2010, 5:51:31 PM (9 years ago)
Author:
steve
Message:

Added a 'closed' argument to read_polygon so that the code correctly tests for a self intersecting polygon (both open and closed)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/geometry/polygon.py

    r8053 r8057  
    350350    return bool(_is_inside_triangle(point, triangle, int(closed), rtol, atol))
    351351   
    352 def is_complex(polygon, verbose=False):
     352def is_complex(polygon, closed=True, verbose=False):
    353353    """Check if a polygon is complex (self-intersecting).
    354354       Uses a sweep algorithm that is O(n^2) in the worst case, but
     
    378378    for i in range(0, len(polygon)-1):
    379379        unsorted_segs.append([list(polygon[i]), list(polygon[i+1])])
    380     unsorted_segs.append([list(polygon[0]), list(polygon[-1])])
     380
     381    if closed:
     382        unsorted_segs.append([list(polygon[0]), list(polygon[-1])])
    381383   
    382384    # all segments must point in same direction
     
    855857################################################################################
    856858
    857 def read_polygon(filename, delimiter=','):
    858     """ Read points assumed to form a polygon.
    859 
    860         Also checks to make sure polygon is not complex (self-intersecting).
     859def read_polygon(filename, delimiter=',', closed='True'):
     860    """ Read points assumed to form a (closed) polygon.
     861        Can also be used toread  in a polyline (closed = 'False')
     862
     863        Also checks to make sure polygon (polyline)
     864        is not complex (self-intersecting).
    861865
    862866        filename Path to file containing polygon data.
     
    876880        polygon.append([float(fields[0]), float(fields[1])])
    877881   
    878     # check this is a valid polygon.
    879     if is_complex(polygon, verbose=True):   
     882    # check this is a valid polygon (polyline).
     883    if is_complex(polygon, closed, verbose=True):
    880884        msg = 'ERROR: Self-intersecting polygon detected in file '
    881885        msg += filename +'. A complex polygon will not '
Note: See TracChangeset for help on using the changeset viewer.