Method: Ruby2D::Line#contains?
- Defined in:
- lib/ruby2d/line.rb
#contains?(x, y) ⇒ Boolean
Line contains a point if the point is closer than the length of line from both ends and if the distance from point to line is smaller than half of the width. Check en.wikipedia.org/wiki/Distance_from_a_point_to_a_line for reference
34 35 36 37 38 |
# File 'lib/ruby2d/line.rb', line 34 def contains?(x, y) points_distance(x1, y1, x, y) < length and points_distance(x2, y2, x, y) < length and (((@y2 - @y1) * x - (@x2 - @x1) * y + @x2 * @y1 - @y2 * @x1).abs / length) < 0.5 * @width end |