#NEWLINE# def get_pixels_on_line( self , x1 , y1 , x2 , y2 , getvalues = True ) : #NEWLINE# #INDENT# "Uses Bresenham's line algorithm to enumerate the pixels along\n        a line.\n        (see http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm)\n\n        If `getvalues`==False then it will return tuples of (x, y) coordinates\n        instead of pixel values.\n        " #NEWLINE# ( x1 , y1 , x2 , y2 ) = ( int ( x1 ) , int ( y1 ) , int ( x2 ) , int ( y2 ) ) #NEWLINE# dx = abs ( ( x2 - x2 ) ) #NEWLINE# dy = abs ( ( y2 - y1 ) ) #NEWLINE# if ( x1 < x2 ) : #NEWLINE# #INDENT# sx = 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sx = ( - 1 ) #NEWLINE# #UNINDENT# if ( y1 < y2 ) : #NEWLINE# #INDENT# sy = 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sy = ( - 1 ) #NEWLINE# #UNINDENT# err = ( dx - dy ) #NEWLINE# res = [ ] #NEWLINE# ( x , y ) = ( x1 , y1 ) #NEWLINE# while True : #NEWLINE# #INDENT# if getvalues : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# val = self . get_data_xy ( x , y ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# val = numpy . NaN #NEWLINE# #UNINDENT# res . append ( val ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# res . append ( ( x , y ) ) #NEWLINE# #UNINDENT# if ( ( x == x2 ) and ( y == y2 ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# e2 = ( 2 * err ) #NEWLINE# if ( e2 > ( - dy ) ) : #NEWLINE# #INDENT# err = ( err - dy ) #NEWLINE# x += sx #NEWLINE# #UNINDENT# if ( e2 < dx ) : #NEWLINE# #INDENT# err = ( err + dx ) #NEWLINE# y += sy #NEWLINE# #UNINDENT# #UNINDENT# return res