Class: Geometry::SlopeInterceptLine
- Inherits:
-
Line
- Object
- Line
- Geometry::SlopeInterceptLine
show all
- Defined in:
- lib/geometry/line.rb
Instance Method Summary
collapse
Methods inherited from Line
[], horizontal, new, vertical
included
Constructor Details
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
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
|
#slope ⇒ Object
121
122
123
|
# File 'lib/geometry/line.rb', line 121
def slope
@slope
end
|
#to_s ⇒ Object
125
126
127
|
# File 'lib/geometry/line.rb', line 125
def to_s
'Line(' + @slope.to_s + ',' + @intercept.to_s + ')'
end
|
#vertical? ⇒ Boolean
109
110
111
|
# File 'lib/geometry/line.rb', line 109
def vertical?
(1/0.0) == @slope
end
|