class UnderOs::Point

Generic Point/Size unit

Attributes

x[RW]
y[RW]

Public Class Methods

new(x, y=nil) click to toggle source
# File lib/under_os/point.rb, line 7
def initialize(x, y=nil)
  if x.is_a?(UnderOs::Point)
    y = x.y if x.y
    x = x.x
  elsif x.is_a?(Hash)
    y = x[:y] || x['y'] || nil
    x = x[:x] || x['x'] || nil
  end

  @x = x
  @y = y
end

Public Instance Methods

*(multiplier) click to toggle source
# File lib/under_os/point.rb, line 25
def *(multiplier)
  UnderOs::Point.new(x: x * multiplier, y: y * multiplier)
end
+(point) click to toggle source
# File lib/under_os/point.rb, line 38
def +(point)
  point = point.is_a?(Numeric) ? UnderOs::Point.new(x: point, y: point) : UnderOs::Point.new(point)
  UnderOs::Point.new(x: x + point.x, y: y + point.y)
end
-(point) click to toggle source
# File lib/under_os/point.rb, line 33
def -(point)
  point = point.is_a?(Numeric) ? UnderOs::Point.new(x: point, y: point) : UnderOs::Point.new(point)
  UnderOs::Point.new(x: x - point.x, y: y - point.y)
end
/(divider) click to toggle source
# File lib/under_os/point.rb, line 29
def /(divider)
  UnderOs::Point.new(x: x / divider.to_f, y: y / divider.to_f)
end
==(*args) click to toggle source
# File lib/under_os/point.rb, line 20
def ==(*args)
  point = UnderOs::Point.new(*args) # normalizing
  x == point.x && y == point.y
end
inspect() click to toggle source
# File lib/under_os/point.rb, line 47
def inspect
  "#<#{self.class.name}:0x#{__id__.to_s(16)} #{to_s}>"
end
to_s() click to toggle source
# File lib/under_os/point.rb, line 43
def to_s
  "x=#{x} y=#{y}"
end