Class: Geometry::SlopeInterceptLine
- Inherits:
-
Line
- Object
- Line
- Geometry::SlopeInterceptLine
show all
- Defined in:
- lib/aurora-geometry/line.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Line
[], horizontal, new, vertical
included
Constructor Details
Returns a new instance of SlopeInterceptLine.
107
108
109
110
|
# File 'lib/aurora-geometry/line.rb', line 107
def initialize(slope, intercept)
@slope = slope
@intercept = intercept
end
|
Instance Attribute Details
#slope ⇒ Number
Returns the slope of the Line.
105
106
107
|
# File 'lib/aurora-geometry/line.rb', line 105
def slope
@slope
end
|
Instance Method Details
#horizontal? ⇒ Boolean
112
113
114
|
# File 'lib/aurora-geometry/line.rb', line 112
def horizontal?
0 == @slope
end
|
#intercept(axis = :y) ⇒ Object
119
120
121
122
123
124
125
126
|
# File 'lib/aurora-geometry/line.rb', line 119
def intercept(axis=:y)
case axis
when :x
vertical? ? @intercept : (horizontal? ? nil : (-@intercept/@slope))
when :y
vertical? ? nil : @intercept
end
end
|
#to_s ⇒ Object
128
129
130
|
# File 'lib/aurora-geometry/line.rb', line 128
def to_s
'Line(' + @slope.to_s + ',' + @intercept.to_s + ')'
end
|
#vertical? ⇒ Boolean
115
116
117
|
# File 'lib/aurora-geometry/line.rb', line 115
def vertical?
(1/0.0) == @slope
end
|