Class: Applitools::Region
- Inherits:
-
Object
- Object
- Applitools::Region
- Defined in:
- lib/eyes_selenium/eyes/region.rb
Constant Summary collapse
- EMPTY =
Applitools::Region.new(0, 0, 0, 0)
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#left ⇒ Object
Returns the value of attribute left.
-
#top ⇒ Object
Returns the value of attribute top.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #bottom ⇒ Object
- #contains?(other_left, other_top) ⇒ Boolean
- #empty? ⇒ Boolean
-
#initialize(left, top, width, height) ⇒ Region
constructor
A new instance of Region.
- #intersect(other) ⇒ Object
- #intersecting?(other) ⇒ Boolean
- #make_empty ⇒ Object
- #middle_offset ⇒ Object
- #right ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
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
#height ⇒ Object
Returns the value of attribute height.
2 3 4 |
# File 'lib/eyes_selenium/eyes/region.rb', line 2 def height @height end |
#left ⇒ Object
Returns the value of attribute left.
2 3 4 |
# File 'lib/eyes_selenium/eyes/region.rb', line 2 def left @left end |
#top ⇒ Object
Returns the value of attribute top.
2 3 4 |
# File 'lib/eyes_selenium/eyes/region.rb', line 2 def top @top end |
#width ⇒ Object
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
#bottom ⇒ Object
28 29 30 |
# File 'lib/eyes_selenium/eyes/region.rb', line 28 def bottom top + height end |
#contains?(other_left, other_top) ⇒ 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
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
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_empty ⇒ Object
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_offset ⇒ Object
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 |
#right ⇒ Object
24 25 26 |
# File 'lib/eyes_selenium/eyes/region.rb', line 24 def right left + width end |
#to_hash ⇒ Object
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_s ⇒ Object
69 70 71 |
# File 'lib/eyes_selenium/eyes/region.rb', line 69 def to_s "(#{left}, #{top}), #{width} x #{height}" end |