Class: Geometry::SlopeInterceptLine
- Includes:
- SlopedLine
- Defined in:
- lib/geometry/line.rb
Instance Attribute Summary
Attributes included from SlopedLine
#horizontal?, #slope, #vertical?
Attributes inherited from Line
#horizontal?, #slope, #vertical?
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two SlopeInterceptLines are equal if both have equal slope and intercept.
-
#eql?(other) ⇒ Boolean
Two SlopeInterceptLines are equal if both have equal slopes and intercepts @note eql? does not check for equivalence between cluster subclases.
-
#initialize(slope, intercept) ⇒ SlopeInterceptLine
constructor
A new instance of SlopeInterceptLine.
-
#intercept(axis = :y) ⇒ Number
Find the requested axis intercept.
- #to_s ⇒ Object
Methods inherited from Line
[], horizontal, new, vertical
Methods included from ClusterFactory
Constructor Details
#initialize(slope, intercept) ⇒ SlopeInterceptLine
Returns a new instance of SlopeInterceptLine.
177 178 179 180 |
# File 'lib/geometry/line.rb', line 177 def initialize(slope, intercept) @slope = slope @intercept = intercept end |
Instance Method Details
#==(other) ⇒ Object
Two Geometry::SlopeInterceptLines are equal if both have equal slope and intercept
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/geometry/line.rb', line 183 def ==(other) case other when PointSlopeLine # Check that the slopes are equal and that the starting point will solve the slope-intercept equation (slope == other.slope) && (other.point.y == slope * other.point.x + intercept) when TwoPointLine # Check that both endpoints solve the line equation ((other.first.y == slope * other.first.x + intercept)) && (other.last.y == (slope * other.last.x + intercept)) else self.eql? other end end |
#eql?(other) ⇒ Boolean
Two Geometry::SlopeInterceptLines are equal if both have equal slopes and intercepts
@note eql? does not check for equivalence between cluster subclases
198 199 200 |
# File 'lib/geometry/line.rb', line 198 def eql?(other) (intercept == other.intercept) && (slope == other.slope) end |
#intercept(axis = :y) ⇒ Number
Find the requested axis intercept
205 206 207 208 209 210 211 212 |
# File 'lib/geometry/line.rb', line 205 def intercept(axis=:y) case axis when :x vertical? ? @intercept : (horizontal? ? nil : (-@intercept/@slope)) when :y vertical? ? nil : @intercept end end |
#to_s ⇒ Object
214 215 216 |
# File 'lib/geometry/line.rb', line 214 def to_s 'Line(' + @slope.to_s + ',' + @intercept.to_s + ')' end |