Class: UnderOs::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/under_os/point.rb

Overview

Generic Point/Size unit

Direct Known Subclasses

UI::Position, UI::Size

Instance Method Summary collapse

Constructor Details

#initialize(x, y = nil) ⇒ Point

Returns a new instance of Point.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/under_os/point.rb', line 6

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

Instance Method Details

#*(multiplier) ⇒ Object



32
33
34
# File 'lib/under_os/point.rb', line 32

def *(multiplier)
  self.class.new(x: @x * multiplier, y: @y * multiplier)
end

#/(divider) ⇒ Object



36
37
38
# File 'lib/under_os/point.rb', line 36

def /(divider)
  self.class.new(x: @x / divider.to_f, y: @y / divider.to_f)
end

#==(*args) ⇒ Object



27
28
29
30
# File 'lib/under_os/point.rb', line 27

def ==(*args)
  point = UnderOs::Point.new(*args) # normalizing
  x == point.x && y == point.y
end

#inspectObject



44
45
46
# File 'lib/under_os/point.rb', line 44

def inspect
  "#<#{self.class.name}:0x#{__id__.to_s(16)} #{to_s}>"
end

#to_sObject



40
41
42
# File 'lib/under_os/point.rb', line 40

def to_s
  "x=#{x} y=#{y}"
end

#xObject



19
20
21
# File 'lib/under_os/point.rb', line 19

def x
  @x
end

#yObject



23
24
25
# File 'lib/under_os/point.rb', line 23

def y
  @y
end