module DrawCommon def get_item_coords( item ) coord = item.coords coord_array = [] x = coord.shift y = coord.shift while x != nil coord_array.push( [x.to_f, y.to_f] ) x = coord.shift y = coord.shift end coord_array end def set_coords( item, coord_array ) eval "item.coords( #{ coord_array.flatten.join(',')} )" end def min_max( coord_array, index ) temp = coord_array.collect{|c| c[index]} [ temp.min, temp.max ] end def center( coord_array ) x_min, x_max = min_max( coord_array, 0 ) y_min, y_max = min_max( coord_array, 1 ) x = ( x_min + x_max ) / 2.0 y = ( y_min + y_max ) / 2.0 [x, y] end def axis_shift( coord_array, cntr ) x0, y0 = cntr coord_array.collect{|c| [ c[0]-x0, c[1]-y0 ] } end def axis_shift_reverse( coord_array, cntr ) x0, y0 = cntr coord_array.collect{|c| [ c[0]+x0, c[1]+y0 ] } end def linear_map( coord_array, matrix ) cntr = center( coord_array ) temp = axis_shift( coord_array, cntr ) temp = temp.collect{|c| x = c[0]*matrix[0] + c[1]*matrix[1] y = c[0]*matrix[2] + c[1]*matrix[3] [x, y] } axis_shift_reverse( temp, cntr ) end def linear_map_with_center( coord_array, matrix, cntr ) temp = axis_shift( coord_array, cntr ) temp = temp.collect{|c| x = c[0]*matrix[0] + c[1]*matrix[1] y = c[0]*matrix[2] + c[1]*matrix[3] [x, y] } axis_shift_reverse( temp, cntr ) end end