Class: Uzi::Rect
- Inherits:
-
Object
- Object
- Uzi::Rect
- Defined in:
- lib/uzi-rect.rb,
lib/uzi-rect/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #bottom ⇒ Object
- #bottom=(y) ⇒ Object
- #bottomleft ⇒ Object
- #bottomleft=(loc) ⇒ Object
- #bottomright ⇒ Object
- #bottomright=(loc) ⇒ Object
-
#center ⇒ Object
Center point.
- #center=(loc) ⇒ Object
- #center_x ⇒ Object
- #center_x=(x) ⇒ Object
- #center_y ⇒ Object
- #center_y=(y) ⇒ Object
- #contains?(loc) ⇒ Boolean
-
#initialize(*args) ⇒ Rect
constructor
A new instance of Rect.
-
#left ⇒ Object
Left, right, top and bottom edges.
- #left=(x) ⇒ Object
- #right ⇒ Object
- #right=(x) ⇒ Object
- #to_a ⇒ Object
- #top ⇒ Object
- #top=(y) ⇒ Object
-
#topleft ⇒ Object
Corner points.
- #topleft=(loc) ⇒ Object
- #topright ⇒ Object
- #topright=(loc) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Rect
Returns a new instance of Rect.
5 6 7 8 9 10 11 |
# File 'lib/uzi-rect.rb', line 5 def initialize(*args) if args.empty? @x, @y, @width, @height = 0, 0, 0, 0 else @x, @y, @width, @height = *args end end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/uzi-rect.rb', line 3 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
3 4 5 |
# File 'lib/uzi-rect.rb', line 3 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/uzi-rect.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/uzi-rect.rb', line 3 def y @y end |
Instance Method Details
#bottom ⇒ Object
28 |
# File 'lib/uzi-rect.rb', line 28 def bottom; @y + @height; end |
#bottom=(y) ⇒ Object
29 |
# File 'lib/uzi-rect.rb', line 29 def bottom=(y); @y = y - @height; end |
#bottomleft ⇒ Object
49 50 51 52 53 54 |
# File 'lib/uzi-rect.rb', line 49 def bottomleft [ left, bottom ] end |
#bottomleft=(loc) ⇒ Object
56 57 58 59 |
# File 'lib/uzi-rect.rb', line 56 def bottomleft=(loc) self.left = loc[0] self.bottom = loc[1] end |
#bottomright ⇒ Object
62 63 64 65 66 67 |
# File 'lib/uzi-rect.rb', line 62 def bottomright [ right, bottom ] end |
#bottomright=(loc) ⇒ Object
69 70 71 72 |
# File 'lib/uzi-rect.rb', line 69 def bottomright=(loc) self.right = loc[0] self.bottom = loc[1] end |
#center ⇒ Object
Center point
75 76 77 78 79 80 |
# File 'lib/uzi-rect.rb', line 75 def center [ @x + (@width / 2.0), @y + (@height / 2.0) ] end |
#center=(loc) ⇒ Object
82 83 84 85 |
# File 'lib/uzi-rect.rb', line 82 def center=(loc) @x = loc[0] - (@width / 2.0) @y = loc[1] - (@height / 2.0) end |
#center_x ⇒ Object
88 |
# File 'lib/uzi-rect.rb', line 88 def center_x; center[0]; end |
#center_x=(x) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/uzi-rect.rb', line 91 def center_x=(x) c = center c[0] = x self.center = c end |
#center_y ⇒ Object
89 |
# File 'lib/uzi-rect.rb', line 89 def center_y; center[1]; end |
#center_y=(y) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/uzi-rect.rb', line 98 def center_y=(y) c = center c[1] = y self.center = c end |
#contains?(loc) ⇒ Boolean
105 106 107 108 |
# File 'lib/uzi-rect.rb', line 105 def contains?(loc) x, y = *loc x >= left && x <= right && y <= bottom && y >= top end |
#left ⇒ Object
Left, right, top and bottom edges
19 |
# File 'lib/uzi-rect.rb', line 19 def left; @x; end |
#left=(x) ⇒ Object
20 |
# File 'lib/uzi-rect.rb', line 20 def left=(x); @x = x; end |
#right ⇒ Object
22 |
# File 'lib/uzi-rect.rb', line 22 def right; @x + @width; end |
#right=(x) ⇒ Object
23 |
# File 'lib/uzi-rect.rb', line 23 def right=(x); @x = x - @width; end |
#to_a ⇒ Object
13 14 15 |
# File 'lib/uzi-rect.rb', line 13 def to_a [ @x, @y, @width, @height ] end |
#top ⇒ Object
25 |
# File 'lib/uzi-rect.rb', line 25 def top; @y; end |
#top=(y) ⇒ Object
26 |
# File 'lib/uzi-rect.rb', line 26 def top=(y); @y = y; end |
#topleft ⇒ Object
Corner points
33 |
# File 'lib/uzi-rect.rb', line 33 def topleft; [ @x, @y ]; end |
#topleft=(loc) ⇒ Object
34 |
# File 'lib/uzi-rect.rb', line 34 def topleft=(loc); @x, @y = loc[0], loc[1]; end |
#topright ⇒ Object
36 37 38 39 40 41 |
# File 'lib/uzi-rect.rb', line 36 def topright [ right, top ] end |
#topright=(loc) ⇒ Object
43 44 45 46 |
# File 'lib/uzi-rect.rb', line 43 def topright=(loc) self.right = loc[0] self.top = loc[1] end |