Method: Geometry::TwoPointLine#intercept

Defined in:
lib/geometry/line.rb

#intercept(axis = :y) ⇒ Number

Find the requested axis intercept

Parameters:

  • axis (Symbol) (defaults to: :y)

    the axis to intercept (either :x or :y)

Returns:

  • (Number)

    the location of the intercept



281
282
283
284
285
286
287
288
# File 'lib/geometry/line.rb', line 281

def intercept(axis=:y)
    case axis
  when :x
      vertical? ? first.x : (horizontal? ? nil : (first.x - first.y/slope))
  when :y
      vertical? ? nil : (horizontal? ? first.y : (first.y - slope * first.x))
    end
end