Class: Applitools::Region

Inherits:
Object
  • Object
show all
Defined in:
lib/eyes_selenium/eyes/region.rb

Constant Summary collapse

EMPTY =
Applitools::Region.new(0, 0, 0, 0)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, top, width, height) ⇒ Region

Returns a new instance of Region.



4
5
6
7
8
9
# File 'lib/eyes_selenium/eyes/region.rb', line 4

def initialize(left, top, width, height)
  @left = left.round
  @top = top.round
  @width = width.round
  @height = height.round
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



2
3
4
# File 'lib/eyes_selenium/eyes/region.rb', line 2

def height
  @height
end

#leftObject

Returns the value of attribute left.



2
3
4
# File 'lib/eyes_selenium/eyes/region.rb', line 2

def left
  @left
end

#topObject

Returns the value of attribute top.



2
3
4
# File 'lib/eyes_selenium/eyes/region.rb', line 2

def top
  @top
end

#widthObject

Returns the value of attribute width.



2
3
4
# File 'lib/eyes_selenium/eyes/region.rb', line 2

def width
  @width
end

Instance Method Details

#bottomObject



28
29
30
# File 'lib/eyes_selenium/eyes/region.rb', line 28

def bottom
  top + height
end

#contains?(other_left, other_top) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/eyes_selenium/eyes/region.rb', line 52

def contains?(other_left, other_top)
  other_left >= left && other_left <= right && \
  other_top >= top && other_top <= bottom
end

#empty?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/eyes_selenium/eyes/region.rb', line 20

def empty?
   self.left == EMPTY.left && self.top == EMPTY.top && self.width == EMPTY.width && self.height == EMPTY.height
end

#intersect(other) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/eyes_selenium/eyes/region.rb', line 37

def intersect(other)
  if !intersecting?(other)
    make_empty and return
  end
  i_left = (left >= other.left) ? left : other.left
  i_right = (right <= other.right) ? right : other.right
  i_top = (top >= other.top) ? top : other.top
  i_bottom = (bottom <= other.bottom) ? bottom : other.bottom

  self.left = i_left
  self.top = i_top
  self.width = i_right - i_left
  self.height = i_bottom - i_top
end

#intersecting?(other) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/eyes_selenium/eyes/region.rb', line 32

def intersecting?(other)
  ((left <= other.left && other.left <= right) || (other.left <= left && left <= other.right)) \
  && ((top <= other.top && other.top <= bottom) || (other.top <= top && top <=other.bottom))
end

#make_emptyObject



13
14
15
16
17
18
# File 'lib/eyes_selenium/eyes/region.rb', line 13

def make_empty
  @left = EMPTY.left
  @top = EMPTY.top
  @width = EMPTY.width
  @height = EMPTY.height
end

#middle_offsetObject



57
58
59
60
61
# File 'lib/eyes_selenium/eyes/region.rb', line 57

def middle_offset
  mid_x = width / 2
  mid_y = height / 2
  Selenium::WebDriver::Point.new(mid_x.round, mid_y.round)
end

#rightObject



24
25
26
# File 'lib/eyes_selenium/eyes/region.rb', line 24

def right
  left + width
end

#to_hashObject



63
64
65
66
67
# File 'lib/eyes_selenium/eyes/region.rb', line 63

def to_hash
  {
    left: left, top: top, height: height, width: width
  }
end

#to_sObject



69
70
71
# File 'lib/eyes_selenium/eyes/region.rb', line 69

def to_s
  "(#{left}, #{top}), #{width} x #{height}"
end