Skip to content

Instantly share code, notes, and snippets.

@OfTheDelmer
Created December 6, 2013 02:44
Show Gist options
  • Save OfTheDelmer/7817769 to your computer and use it in GitHub Desktop.
Save OfTheDelmer/7817769 to your computer and use it in GitHub Desktop.
bound_box.rb
#takes two squares
def check_square(square)
if(square[0][0] > square[1][0])
puts square
square[0][0], square[1][0] = square[1][0], square[0][0]
end
if(square[0][1] > square[1][1])
puts square
square[0][1], square[1][1] = square[1][1], square[0][1]
end
square
end
def bound_box(squares)
square_1 = check_square [squares[0],squares[1]]
square_2 = check_square [squares[2],squares[3]]
[ [ [square_1[0][0], square_2[0][0]].max,
[square_1[0][1], square_2[0][1]].max
],
[ [square_1[1][0], square_2[1][0]].min,
[square_1[1][1], square_2[1][1]].min ]]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment