Class: Geometry::PointSlopeLine
Instance Attribute Summary collapse
-
#point ⇒ Object
Returns the value of attribute point.
-
#slope ⇒ Number
readonly
The slope of the Line.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two PointSlopeLines are equal if both have equal slope and origin.
-
#eql?(other) ⇒ Boolean
Two PointSlopeLines are equal if both have equal slopes and origins @note eql? does not check for equivalence between cluster subclases.
-
#initialize(point, slope) ⇒ PointSlopeLine
constructor
A new instance of PointSlopeLine.
- #to_s ⇒ Object
Methods inherited from Line
[], horizontal, new, vertical
Methods included from ClusterFactory
Constructor Details
#initialize(point, slope) ⇒ PointSlopeLine
99 100 101 102 |
# File 'lib/geometry/line.rb', line 99 def initialize(point, slope) @point = Point[point] @slope = slope end |
Instance Attribute Details
#point ⇒ Object
Returns the value of attribute point.
92 93 94 |
# File 'lib/geometry/line.rb', line 92 def point @point end |
#slope ⇒ Number (readonly)
95 96 97 |
# File 'lib/geometry/line.rb', line 95 def slope @slope end |
Instance Method Details
#==(other) ⇒ Object
Two Geometry::PointSlopeLines are equal if both have equal slope and origin
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/geometry/line.rb', line 105 def ==(other) case other when SlopeInterceptLine # Check that the slopes are equal and that the starting point will solve the slope-intercept equation (slope == other.slope) && (point.y == other.slope * point.x + other.intercept) when TwoPointLine # Plug both of other's endpoints into the line equation and check that they solve it first_diff = other.first - point last_diff = other.last - point (first_diff.y == slope*first_diff.x) && (last_diff.y == slope*last_diff.x) else self.eql? other end end |
#eql?(other) ⇒ Boolean
Two Geometry::PointSlopeLines are equal if both have equal slopes and origins
@note eql? does not check for equivalence between cluster subclases
122 123 124 |
# File 'lib/geometry/line.rb', line 122 def eql?(other) (point == other.point) && (slope == other.slope) end |
#to_s ⇒ Object
126 127 128 |
# File 'lib/geometry/line.rb', line 126 def to_s 'Line(' + @slope.to_s + ',' + @point.to_s + ')' end |