Class: Region
- Inherits:
-
Object
- Object
- Region
- Defined in:
- lib/capybara/screenshot/diff/region.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
- .from_edge_coordinates(left, top, right, bottom) ⇒ Object
- .from_top_left_corner_coordinates(x, y, width, height) ⇒ Object
Instance Method Summary collapse
- #bottom ⇒ Object
- #cover?(x, y) ⇒ Boolean
- #find_intersect_with(region) ⇒ Object
- #find_relative_intersect(region) ⇒ Object
-
#initialize(x, y, width, height) ⇒ Region
constructor
A new instance of Region.
- #intersect?(region) ⇒ Boolean
- #left ⇒ Object
- #move_by(right_by, down_by) ⇒ Object
- #right ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
- #to_edge_coordinates ⇒ Object
- #to_top_left_corner_coordinates ⇒ Object
- #top ⇒ Object
Constructor Details
#initialize(x, y, width, height) ⇒ Region
Returns a new instance of Region.
6 7 8 |
# File 'lib/capybara/screenshot/diff/region.rb', line 6 def initialize(x, y, width, height) @x, @y, @width, @height = x, y, width, height end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
4 5 6 |
# File 'lib/capybara/screenshot/diff/region.rb', line 4 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
4 5 6 |
# File 'lib/capybara/screenshot/diff/region.rb', line 4 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
4 5 6 |
# File 'lib/capybara/screenshot/diff/region.rb', line 4 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
4 5 6 |
# File 'lib/capybara/screenshot/diff/region.rb', line 4 def y @y end |
Class Method Details
.from_edge_coordinates(left, top, right, bottom) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/capybara/screenshot/diff/region.rb', line 17 def self.from_edge_coordinates(left, top, right, bottom) return nil unless left && top && right && bottom return nil if right < left || bottom < top Region.new(left, top, right - left, bottom - top) end |
.from_top_left_corner_coordinates(x, y, width, height) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/capybara/screenshot/diff/region.rb', line 10 def self.from_top_left_corner_coordinates(x, y, width, height) return nil unless x && y && width && height return nil if width < 0 || height < 0 Region.new(x, y, width, height) end |
Instance Method Details
#bottom ⇒ Object
36 37 38 |
# File 'lib/capybara/screenshot/diff/region.rb', line 36 def bottom y + height end |
#cover?(x, y) ⇒ Boolean
83 84 85 |
# File 'lib/capybara/screenshot/diff/region.rb', line 83 def cover?(x, y) left <= x && x <= right && top <= y && y <= bottom end |
#find_intersect_with(region) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/capybara/screenshot/diff/region.rb', line 59 def find_intersect_with(region) return nil unless intersect?(region) new_left = [x, region.x].max new_top = [y, region.y].max Region.new(new_left, new_top, [right, region.right].min - new_left, [bottom, region.bottom].min - new_top) end |
#find_relative_intersect(region) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/capybara/screenshot/diff/region.rb', line 76 def find_relative_intersect(region) intersect = find_intersect_with(region) return nil unless intersect intersect.move_by(-x, -y) end |
#intersect?(region) ⇒ Boolean
68 69 70 |
# File 'lib/capybara/screenshot/diff/region.rb', line 68 def intersect?(region) left <= region.right && right >= region.left && top <= region.bottom && bottom >= region.top end |
#left ⇒ Object
40 41 42 |
# File 'lib/capybara/screenshot/diff/region.rb', line 40 def left x end |
#move_by(right_by, down_by) ⇒ Object
72 73 74 |
# File 'lib/capybara/screenshot/diff/region.rb', line 72 def move_by(right_by, down_by) Region.new(x + right_by, y + down_by, width, height) end |
#right ⇒ Object
44 45 46 |
# File 'lib/capybara/screenshot/diff/region.rb', line 44 def right x + width end |
#size ⇒ Object
48 49 50 51 52 53 |
# File 'lib/capybara/screenshot/diff/region.rb', line 48 def size return 0 if width < 0 || height < 0 result = width * height result.zero? ? 1 : result end |
#to_a ⇒ Object
55 56 57 |
# File 'lib/capybara/screenshot/diff/region.rb', line 55 def to_a [@x, @y, @width, @height] end |
#to_edge_coordinates ⇒ Object
24 25 26 |
# File 'lib/capybara/screenshot/diff/region.rb', line 24 def to_edge_coordinates [left, top, right, bottom] end |
#to_top_left_corner_coordinates ⇒ Object
28 29 30 |
# File 'lib/capybara/screenshot/diff/region.rb', line 28 def to_top_left_corner_coordinates [x, y, width, height] end |
#top ⇒ Object
32 33 34 |
# File 'lib/capybara/screenshot/diff/region.rb', line 32 def top y end |