Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.62 KB | None | 0 0
  1. def on_segment(point_1, point_2, point_3)
  2.   min_x(point_1, point_2) <= point_3[0] &&
  3.   point_3[0] <= max_x(point_1, point_2) &&
  4.   min_y(point_1, point_2) <= point_3[1] &&
  5.   point_3[1] <= max_y(point_1, point_2)
  6. end
  7.  
  8. def min_x(point_1, point_2)
  9.   [point_1[0], point_2[0]].min
  10. end
  11.  
  12. def max_x(point_1, point_2)
  13.   [point_1[0], point_2[0]].max
  14. end
  15.  
  16.  
  17. # Łukasz
  18. def on_segment(point_1, point_2, point_3)
  19.   point_3[0].between?(x_cords) &&
  20.   point_3[1].between?(y_cords)
  21. end
  22.  
  23. def x_cords
  24.   (min_x(point_1, point_2), max_x(point_1, point_2))
  25. end
  26.  
  27. def y_range
  28.   (min_y(point_1, point_2), max_y(point_1, point_2))
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement