Class: Geometry::TwoPointLine
Instance Attribute Summary collapse
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
Accessors collapse
-
#slope ⇒ Object
!@attribute [r[ slope @return [Number] the slope of the Line.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two TwoPointLines are equal if both have equal Points in the same order.
-
#eql?(other) ⇒ Boolean
Two TwoPointLines are equal if both have equal endpoints @note eql? does not check for equivalence between cluster subclases.
-
#initialize(point0, point1) ⇒ TwoPointLine
constructor
A new instance of TwoPointLine.
- #inspect ⇒ Object (also: #to_s)
Methods inherited from Line
[], horizontal, new, vertical
Methods included from ClusterFactory
Constructor Details
#initialize(point0, point1) ⇒ TwoPointLine
Returns a new instance of TwoPointLine.
188 189 190 |
# File 'lib/geometry/line.rb', line 188 def initialize(point0, point1) @first, @last = [Point[point0], Point[point1]] end |
Instance Attribute Details
#first ⇒ Object (readonly)
Returns the value of attribute first.
186 187 188 |
# File 'lib/geometry/line.rb', line 186 def first @first end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
186 187 188 |
# File 'lib/geometry/line.rb', line 186 def last @last end |
Instance Method Details
#==(other) ⇒ Object
Two Geometry::TwoPointLines are equal if both have equal Points in the same order
197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/geometry/line.rb', line 197 def ==(other) case other when PointSlopeLine # Plug both endpoints into the line equation and check that they solve it first_diff = first - other.point last_diff = last - other.point (first_diff.y == other.slope*first_diff.x) && (last_diff.y == other.slope*last_diff.x) when SlopeInterceptLine # Check that both endpoints solve the line equation ((first.y == other.slope * first.x + other.intercept)) && (last.y == (other.slope * last.x + other.intercept)) else self.eql?(other) || ((first == other.last) && (last == other.first)) end end |
#eql?(other) ⇒ Boolean
Two Geometry::TwoPointLines are equal if both have equal endpoints
@note eql? does not check for equivalence between cluster subclases
214 215 216 |
# File 'lib/geometry/line.rb', line 214 def eql?(other) (first == other.first) && (last == other.last) end |
#inspect ⇒ Object Also known as: to_s
191 192 193 |
# File 'lib/geometry/line.rb', line 191 def inspect 'Line(' + @first.inspect + ', ' + @last.inspect + ')' end |
#slope ⇒ Object
!@attribute [r[ slope
@return [Number] the slope of the {Line}
221 222 223 |
# File 'lib/geometry/line.rb', line 221 def slope (last.y - first.y)/(last.x - first.x) end |