Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def on_segment(point_1, point_2, point_3)
- min_x(point_1, point_2) <= point_3[0] &&
- point_3[0] <= max_x(point_1, point_2) &&
- min_y(point_1, point_2) <= point_3[1] &&
- point_3[1] <= max_y(point_1, point_2)
- end
- def min_x(point_1, point_2)
- [point_1[0], point_2[0]].min
- end
- def max_x(point_1, point_2)
- [point_1[0], point_2[0]].max
- end
- # Łukasz
- def on_segment(point_1, point_2, point_3)
- point_3[0].between?(x_cords) &&
- point_3[1].between?(y_cords)
- end
- def x_cords
- (min_x(point_1, point_2), max_x(point_1, point_2))
- end
- def y_range
- (min_y(point_1, point_2), max_y(point_1, point_2))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement