Class: Rect
- Inherits:
-
Object
- Object
- Rect
- Defined in:
- lib/rect.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#position ⇒ Object
Returns the value of attribute position.
-
#size ⇒ Object
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
- #bottom ⇒ Object
- #bottom=(value) ⇒ Object
- #clone ⇒ Object
- #height ⇒ Object
- #height=(value) ⇒ Object
-
#initialize(pos, size) ⇒ Rect
constructor
A new instance of Rect.
- #left ⇒ Object
- #left=(value) ⇒ Object
- #right ⇒ Object
- #right=(value) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
- #top ⇒ Object
- #top=(value) ⇒ Object
- #width ⇒ Object
- #width=(value) ⇒ Object
- #x ⇒ Object
- #y ⇒ Object
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
#position ⇒ Object
Returns the value of attribute position.
4 5 6 |
# File 'lib/rect.rb', line 4 def position @position end |
#size ⇒ Object
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
#bottom ⇒ Object
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 |
#clone ⇒ Object
71 72 73 |
# File 'lib/rect.rb', line 71 def clone Rect.new([@position.x, @position.y], [@size.x, @size.y]) end |
#height ⇒ Object
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 |
#left ⇒ Object
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 |
#right ⇒ Object
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_a ⇒ Object
75 76 77 |
# File 'lib/rect.rb', line 75 def to_a [@position.x, @position.y, @size.x, @size.y] end |
#to_s ⇒ Object
67 68 69 |
# File 'lib/rect.rb', line 67 def to_s self.to_a.to_s end |
#top ⇒ Object
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 |
#width ⇒ Object
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 |
#x ⇒ Object
11 12 13 |
# File 'lib/rect.rb', line 11 def x @position.x end |
#y ⇒ Object
15 16 17 |
# File 'lib/rect.rb', line 15 def y @position.y end |