Class: Geometry::TwoPointLine

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

Instance Attribute Summary collapse

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.



137
138
139
# File 'lib/geometry/line.rb', line 137

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

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



135
136
137
# File 'lib/geometry/line.rb', line 135

def first
  @first
end

#lastObject (readonly)

Returns the value of attribute last.



135
136
137
# File 'lib/geometry/line.rb', line 135

def last
  @last
end

Instance Method Details

#inspectObject Also known as: to_s



140
141
142
# File 'lib/geometry/line.rb', line 140

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

#slopeObject

!@attribute [r[ slope

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


148
149
150
# File 'lib/geometry/line.rb', line 148

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