Class: Geometry::SlopeInterceptLine

Inherits:
Line
  • Object
show all
Defined in:
lib/geometry/line.rb

Instance Method Summary collapse

Methods inherited from Line

[], horizontal, new, vertical

Methods included from ClusterFactory

included

Constructor Details

#initialize(slope, intercept) ⇒ SlopeInterceptLine

Returns a new instance of SlopeInterceptLine.



101
102
103
104
# File 'lib/geometry/line.rb', line 101

def initialize(slope, intercept)
    @slope = slope
    @intercept = intercept
end

Instance Method Details

#horizontal?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/geometry/line.rb', line 106

def horizontal?
    0 == @slope
end

#intercept(axis = :y) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/geometry/line.rb', line 113

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

#slopeObject



121
122
123
# File 'lib/geometry/line.rb', line 121

def slope
    @slope
end

#to_sObject



125
126
127
# File 'lib/geometry/line.rb', line 125

def to_s
    'Line(' + @slope.to_s + ',' + @intercept.to_s + ')'
end

#vertical?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/geometry/line.rb', line 109

def vertical?
    (1/0.0) == @slope
end