Class: Geometry::SlopeInterceptLine

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

Overview

/# SlopeInterceptLine #/#

Instance Attribute Summary collapse

Attributes inherited from Line

#options

Instance Method Summary collapse

Methods inherited from Line

[], horizontal, new, vertical

Methods included from ClusterFactory

included

Constructor Details

#initialize(slope, intercept) ⇒ SlopeInterceptLine

Returns a new instance of SlopeInterceptLine.



121
122
123
124
# File 'lib/geometry/line.rb', line 121

def initialize(slope, intercept)
  @slope = slope
  @intercept = intercept
end

Instance Attribute Details

#slopeNumber (readonly)

Returns the slope of the Line.

Returns:

  • (Number)

    the slope of the Line



119
120
121
# File 'lib/geometry/line.rb', line 119

def slope
  @slope
end

Instance Method Details

#horizontal?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/geometry/line.rb', line 126

def horizontal?
  0 == @slope
end

#intercept(axis = :y) ⇒ Object



134
135
136
137
138
139
140
141
# File 'lib/geometry/line.rb', line 134

def intercept(axis=:y)
  case axis
    when :x
      vertical? ? @intercept : (horizontal? ? nil : (-@intercept/@slope))
    when :y
      vertical? ? nil : @intercept
  end
end

#to_sObject



143
144
145
# File 'lib/geometry/line.rb', line 143

def to_s
  'Line(' + @slope.to_s + ',' + @intercept.to_s + ')'
end

#vertical?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/geometry/line.rb', line 130

def vertical?
  (1/0.0) == @slope
end