Class: ImageCompare::Rectangle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#botObject

Returns the value of attribute bot.



5
6
7
# File 'lib/image_compare/rectangle.rb', line 5

def bot
  @bot
end

#leftObject

Returns the value of attribute left.



5
6
7
# File 'lib/image_compare/rectangle.rb', line 5

def left
  @left
end

#rightObject

Returns the value of attribute right.



5
6
7
# File 'lib/image_compare/rectangle.rb', line 5

def right
  @right
end

#topObject

Returns the value of attribute top.



5
6
7
# File 'lib/image_compare/rectangle.rb', line 5

def top
  @top
end

Instance Method Details

#areaObject



14
15
16
# File 'lib/image_compare/rectangle.rb', line 14

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

#boundsObject



25
26
27
# File 'lib/image_compare/rectangle.rb', line 25

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

#contains?(rect) ⇒ Boolean

Returns:

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

Returns:

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