class Geospatial::Line
Attributes
a[R]
b[R]
Public Class Methods
new(a, b)
click to toggle source
# File lib/geospatial/line.rb, line 25 def initialize(a, b) @a = a @b = b end
Public Instance Methods
intersect?(other)
click to toggle source
# File lib/geospatial/line.rb, line 37 def intersect?(other) t = self.offset o = other.offset d = (o[1] * t[0]) - (o[0] * t[1]) return false if d.zero? na = o[0] * (self.a[1] - other.a[1]) - o[1] * (self.a[0] - other.a[0]) left_time = na.fdiv(d); if left_time < 0.0 or left_time > 1.0 return false end nb = t[0] * (self.a[1] - other.a[1]) - t[1] * (self.a[0] - other.a[0]) right_time = nb.fdiv(d) if right_time < 0.0 or right_time > 1.0 return false end return left_time end
offset()
click to toggle source
# File lib/geospatial/line.rb, line 33 def offset @b - @a end