Class: Imatcher::Rectangle
- Inherits:
-
Object
- Object
- Imatcher::Rectangle
- Defined in:
- lib/imatcher/rectangle.rb
Instance Attribute Summary collapse
-
#bot ⇒ Object
Returns the value of attribute bot.
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
-
#top ⇒ Object
Returns the value of attribute top.
Instance Method Summary collapse
- #area ⇒ Object
- #bounds ⇒ Object
- #contains?(rect) ⇒ Boolean
- #contains_point?(x, y) ⇒ Boolean
-
#initialize(l, t, r, b) ⇒ Rectangle
constructor
A new instance of Rectangle.
Constructor Details
#initialize(l, t, r, b) ⇒ Rectangle
Returns a new instance of Rectangle.
5 6 7 8 9 10 |
# File 'lib/imatcher/rectangle.rb', line 5 def initialize(l, t, r, b) @left = l @top = t @right = r @bot = b end |
Instance Attribute Details
#bot ⇒ Object
Returns the value of attribute bot.
3 4 5 |
# File 'lib/imatcher/rectangle.rb', line 3 def bot @bot end |
#left ⇒ Object
Returns the value of attribute left.
3 4 5 |
# File 'lib/imatcher/rectangle.rb', line 3 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
3 4 5 |
# File 'lib/imatcher/rectangle.rb', line 3 def right @right end |
#top ⇒ Object
Returns the value of attribute top.
3 4 5 |
# File 'lib/imatcher/rectangle.rb', line 3 def top @top end |
Instance Method Details
#area ⇒ Object
12 13 14 |
# File 'lib/imatcher/rectangle.rb', line 12 def area (right - left + 1) * (bot - top + 1) end |
#bounds ⇒ Object
23 24 25 |
# File 'lib/imatcher/rectangle.rb', line 23 def bounds [left, top, right, bot] end |
#contains?(rect) ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/imatcher/rectangle.rb', line 16 def contains?(rect) (left <= rect.left) && (right >= rect.right) && (top <= rect.top) && (bot >= rect.bot) end |
#contains_point?(x, y) ⇒ Boolean
27 28 29 |
# File 'lib/imatcher/rectangle.rb', line 27 def contains_point?(x, y) x.between?(left, right) && y.between?(top, bot) end |