Class: Rect

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

Direct Known Subclasses

Bomp::QuadTree::QuadNode

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pos, size) ⇒ Rect

Returns a new instance of Rect.



6
7
8
9
# File 'lib/rect.rb', line 6

def initialize(pos, size)
  @position = Vector2[*pos]
  @size = Vector2[*size]
end

Instance Attribute Details

#positionObject

Returns the value of attribute position.



4
5
6
# File 'lib/rect.rb', line 4

def position
  @position
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'lib/rect.rb', line 4

def size
  @size
end

Class Method Details

.[](x, y, w, h) ⇒ Object



79
80
81
# File 'lib/rect.rb', line 79

def self.[](x, y, w, h)
  Rect.new([x, y], [w, h])
end

Instance Method Details

#bottomObject



43
44
45
# File 'lib/rect.rb', line 43

def bottom
  @position.y + height
end

#bottom=(value) ⇒ Object



47
48
49
# File 'lib/rect.rb', line 47

def bottom=(value)
  @position.y += value - self.bottom
end

#cloneObject



71
72
73
# File 'lib/rect.rb', line 71

def clone
  Rect.new([@position.x, @position.y], [@size.x, @size.y])
end

#heightObject



27
28
29
# File 'lib/rect.rb', line 27

def height
  @size.y
end

#height=(value) ⇒ Object



31
32
33
# File 'lib/rect.rb', line 31

def height=(value)
  @size.y = value
end

#leftObject



51
52
53
# File 'lib/rect.rb', line 51

def left
  @position.x
end

#left=(value) ⇒ Object



55
56
57
# File 'lib/rect.rb', line 55

def left=(value)
  @position.x = value
end

#rightObject



59
60
61
# File 'lib/rect.rb', line 59

def right
  @position.x + width
end

#right=(value) ⇒ Object



63
64
65
# File 'lib/rect.rb', line 63

def right=(value)
  @position.x += value - self.right
end

#to_aObject



75
76
77
# File 'lib/rect.rb', line 75

def to_a
  [@position.x, @position.y, @size.x, @size.y]
end

#to_sObject



67
68
69
# File 'lib/rect.rb', line 67

def to_s
  self.to_a.to_s
end

#topObject



35
36
37
# File 'lib/rect.rb', line 35

def top
  @position.y
end

#top=(value) ⇒ Object



39
40
41
# File 'lib/rect.rb', line 39

def top=(value)
  @position.y = value
end

#widthObject



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

def width
  @size.x
end

#width=(value) ⇒ Object



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

def width=(value)
  @size.x = value
end

#xObject



11
12
13
# File 'lib/rect.rb', line 11

def x
  @position.x
end

#yObject



15
16
17
# File 'lib/rect.rb', line 15

def y
  @position.y
end