Class: ImageCompare::Rectangle
- Inherits:
-
Object
- Object
- ImageCompare::Rectangle
- Defined in:
- lib/image_compare/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.
7 8 9 10 11 12 |
# File 'lib/image_compare/rectangle.rb', line 7 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.
5 6 7 |
# File 'lib/image_compare/rectangle.rb', line 5 def bot @bot end |
#left ⇒ Object
Returns the value of attribute left.
5 6 7 |
# File 'lib/image_compare/rectangle.rb', line 5 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
5 6 7 |
# File 'lib/image_compare/rectangle.rb', line 5 def right @right end |
#top ⇒ Object
Returns the value of attribute top.
5 6 7 |
# File 'lib/image_compare/rectangle.rb', line 5 def top @top end |
Instance Method Details
#area ⇒ Object
14 15 16 |
# File 'lib/image_compare/rectangle.rb', line 14 def area (right - left + 1) * (bot - top + 1) end |
#bounds ⇒ Object
25 26 27 |
# File 'lib/image_compare/rectangle.rb', line 25 def bounds [left, top, right, bot] end |
#contains?(rect) ⇒ Boolean
18 19 20 21 22 23 |
# File 'lib/image_compare/rectangle.rb', line 18 def contains?(rect) (left <= rect.left) && (right >= rect.right) && (top <= rect.top) && (bot >= rect.bot) end |
#contains_point?(x, y) ⇒ Boolean
29 30 31 32 33 |
# File 'lib/image_compare/rectangle.rb', line 29 def contains_point?(x, y) (x >= left && y >= top && x <= right && y <= bot) || (x <= right && y <= top && x >= left && y >= bot) || (x.between?(right, left) && y.between?(bot, top)) end |