Class: Geometry::SlopeInterceptLine
Overview
/# SlopeInterceptLine #/#
Instance Attribute Summary collapse
-
#slope ⇒ Number
readonly
The slope of the Line.
Attributes inherited from Line
Instance Method Summary collapse
- #horizontal? ⇒ Boolean
-
#initialize(slope, intercept) ⇒ SlopeInterceptLine
constructor
A new instance of SlopeInterceptLine.
- #intercept(axis = :y) ⇒ Object
- #to_s ⇒ Object
- #vertical? ⇒ Boolean
Methods inherited from Line
[], horizontal, new, vertical
Methods included from ClusterFactory
Constructor Details
#initialize(slope, intercept) ⇒ SlopeInterceptLine
Returns a new instance of SlopeInterceptLine.
121 122 123 124 |
# File 'lib/geometry/line.rb', line 121 def initialize(slope, intercept) @slope = slope @intercept = intercept end |
Instance Attribute Details
#slope ⇒ Number (readonly)
Returns the slope of the Line.
119 120 121 |
# File 'lib/geometry/line.rb', line 119 def slope @slope end |
Instance Method Details
#horizontal? ⇒ Boolean
126 127 128 |
# File 'lib/geometry/line.rb', line 126 def horizontal? 0 == @slope end |
#intercept(axis = :y) ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/geometry/line.rb', line 134 def intercept(axis=:y) case axis when :x vertical? ? @intercept : (horizontal? ? nil : (-@intercept/@slope)) when :y vertical? ? nil : @intercept end end |
#to_s ⇒ Object
143 144 145 |
# File 'lib/geometry/line.rb', line 143 def to_s 'Line(' + @slope.to_s + ',' + @intercept.to_s + ')' end |
#vertical? ⇒ Boolean
130 131 132 |
# File 'lib/geometry/line.rb', line 130 def vertical? (1/0.0) == @slope end |