Class: Geometry::TwoPointLine

Inherits:
Line
  • Object
show all
Defined in:
lib/geometry/line.rb

Overview

/# TwoPointLine #/#

Instance Attribute Summary collapse

Attributes inherited from Line

#options

Accessors collapse

Instance Method Summary collapse

Methods inherited from Line

[], horizontal, new, vertical

Methods included from ClusterFactory

included

Constructor Details

#initialize(point0, point1) ⇒ TwoPointLine

Returns a new instance of TwoPointLine.



155
156
157
# File 'lib/geometry/line.rb', line 155

def initialize(point0, point1)
    @first, @last = [Point[point0], Point[point1]]
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



153
154
155
# File 'lib/geometry/line.rb', line 153

def first
  @first
end

#lastObject (readonly)

Returns the value of attribute last.



153
154
155
# File 'lib/geometry/line.rb', line 153

def last
  @last
end

Instance Method Details

#inspectObject Also known as: to_s



158
159
160
# File 'lib/geometry/line.rb', line 158

def inspect
    'Line(' + @first.inspect + ', ' + @last.inspect + ')'
end

#slopeObject

!@attribute [r[ slope

@return [Number]  the slope of the {Line}


166
167
168
# File 'lib/geometry/line.rb', line 166

def slope
  (last.y - first.y)/(last.x - first.x)
end