Class: Geometry::SlopeInterceptLine

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

Instance Attribute Summary collapse

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.



107
108
109
110
# File 'lib/geometry/line.rb', line 107

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



105
106
107
# File 'lib/geometry/line.rb', line 105

def slope
  @slope
end

Instance Method Details

#horizontal?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/geometry/line.rb', line 112

def horizontal?
    0 == @slope
end

#intercept(axis = :y) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/geometry/line.rb', line 119

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

#to_sObject



128
129
130
# File 'lib/geometry/line.rb', line 128

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

#vertical?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/geometry/line.rb', line 115

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