forked from vikingeducation/prep_ruby_challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrectangle.rb
More file actions
23 lines (17 loc) · 775 Bytes
/
rectangle.rb
File metadata and controls
23 lines (17 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def overlap(rect_1, rect_2)
rect_1_left_x = rect_1[0][0]
rect_1_right_x = rect_1[1][0]
rect_1_bot_y = rect_1[0][1]
rect_1_top_y = rect_1[1][1]
rect_2_left_x = rect_2[0][0]
rect_2_right_x = rect_2[1][0]
rect_2_bot_y = rect_2[0][1]
rect_2_top_y = rect_2[1][1]
if (rect_1_left_x < rect_2_left_x && rect_1_right_x > rect_2_left_x) || (rect_1_left_x > rect_2_left_x && rect_1_right_x < Bxrect_2_right_x) || (rect_1_left_x < rect_2_right_x && rect_1_right_x > rect_2_right_x)
if (rect_1_bot_y < rect_2_bot_y && rect_1_top_y > rect_2_bot_y) || (rect_1_bot_y > rect_2_bot_y && rect_1_top_y < rect_2_top_y) || (rect_1_bot_y < rect_2_top_y && rect_1_top_y > rect_2_top_y)
return true
end
return false
end
end
puts overlap( [ [1,10], [4,4] ], [ [2,8], [5,10] ] )