Class: Imatcher::Rectangle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#botObject

Returns the value of attribute bot.



3
4
5
# File 'lib/imatcher/rectangle.rb', line 3

def bot
  @bot
end

#leftObject

Returns the value of attribute left.



3
4
5
# File 'lib/imatcher/rectangle.rb', line 3

def left
  @left
end

#rightObject

Returns the value of attribute right.



3
4
5
# File 'lib/imatcher/rectangle.rb', line 3

def right
  @right
end

#topObject

Returns the value of attribute top.



3
4
5
# File 'lib/imatcher/rectangle.rb', line 3

def top
  @top
end

Instance Method Details

#areaObject



12
13
14
# File 'lib/imatcher/rectangle.rb', line 12

def area
  (right - left + 1) * (bot - top + 1)
end

#boundsObject



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

def bounds
  [left, top, right, bot]
end

#contains?(rect) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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