class TheFox::TermKit::Point

A single point on a x-y-grid.

Attributes

x[RW]
y[RW]

Public Class Methods

from_s(s) click to toggle source
# File lib/termkit/misc/point.rb, line 100
def self.from_s(s)
    x, y =
        s
        .split(/[:,]/, 2)
        .map{ |pos|
            pos.nil? || pos == '' ? nil : pos.to_i
        }
    
    new(x, y)
end
new(x = nil, y = nil) click to toggle source
# File lib/termkit/misc/point.rb, line 12
def initialize(x = nil, y = nil)
    case x
    when Array
        y = x[1]
        x = x[0]
    when Hash
        y = if x['y']
                x['y']
            elsif x[:y]
                x[:y]
            end
        
        x = if x['x']
                x['x']
            elsif x[:x]
                x[:x]
            end
    end
    
    @x = x
    @y = y
end

Public Instance Methods

+(point) click to toggle source

def eql?(point) puts “Point eql? compare” false end

# File lib/termkit/misc/point.rb, line 51
def +(point)
    x = nil
    y = nil
    
    if !@x.nil? || !point.x.nil?
        x = @x.to_i + point.x.to_i
    end
    
    if !@y.nil? || !point.y.nil?
        y = @y.to_i + point.y.to_i
    end
    
    self.class.new(x, y)
end
-(point) click to toggle source
# File lib/termkit/misc/point.rb, line 66
def -(point)
    x = nil
    y = nil
    
    if !@x.nil? || !point.x.nil?
        x = @x.to_i - point.x.to_i
    end
    
    if !@y.nil? || !point.y.nil?
        y = @y.to_i - point.y.to_i
    end
    
    self.class.new(x, y)
end
==(point) click to toggle source
# File lib/termkit/misc/point.rb, line 35
def ==(point)
    # puts "Point == compare"
    @x == point.x && @y == point.y
end
inspect() click to toggle source
# File lib/termkit/misc/point.rb, line 89
def inspect
    x_s = x.nil? ? 'NIL' : x
    y_s = y.nil? ? 'NIL' : y
    
    "#<Point x=#{x_s} y=#{y_s}>"
end
missing_function() click to toggle source
# File lib/termkit/misc/point.rb, line 96
def missing_function
    
end
to_a() click to toggle source
# File lib/termkit/misc/point.rb, line 85
def to_a
    [@x, @y]
end
to_s() click to toggle source
# File lib/termkit/misc/point.rb, line 81
def to_s
    "#{@x}:#{@y}"
end