#NEWLINE# def reduce_poly( points , tolerance = 0.5 ) : #NEWLINE# #INDENT# 'Remove close points to simplify a polyline\n    tolerance is the min distance between two points squared.\n    \n    :return: The reduced polygon as a list of (x,y)\n    ' #NEWLINE# assert ( len ( points ) > 0 ) , 'reduce_poly can not simplify an empty points list' #NEWLINE# curr_p = points [ 0 ] #NEWLINE# reduced_ps = [ points [ 0 ] ] #NEWLINE# for p in points [ 1 : ] : #NEWLINE# #INDENT# distance = ( ( ( curr_p [ X ] - p [ X ] ) ** 2 ) + ( ( curr_p [ Y ] - p [ Y ] ) ** 2 ) ) #NEWLINE# if ( distance > tolerance ) : #NEWLINE# #INDENT# curr_p = p #NEWLINE# reduced_ps . append ( p ) #NEWLINE# #UNINDENT# #UNINDENT# return reduced_ps