class Region
Attributes
Public Class Methods
Source
# File lib/capybara/screenshot/diff/region.rb, line 10 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
Source
# File lib/capybara/screenshot/diff/region.rb, line 6 def initialize(x, y, width, height) @x, @y, @width, @height = x, y, width, height end
Public Instance Methods
Source
# File lib/capybara/screenshot/diff/region.rb, line 97 def ==(other) case other when Region x == other.x && y == other.y && width == other.width && height == other.height when Array to_a == other else false end end
need to add this method to make it work with assert_equal
Source
# File lib/capybara/screenshot/diff/region.rb, line 76 def cover?(x, y) x.between?(left, right) && y.between?(top, bottom) end
Source
# File lib/capybara/screenshot/diff/region.rb, line 80 def empty? width.zero? || height.zero? end
Source
# File lib/capybara/screenshot/diff/region.rb, line 52 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
Source
# File lib/capybara/screenshot/diff/region.rb, line 69 def find_relative_intersect(region) intersect = find_intersect_with(region) return nil unless intersect intersect.move_by(-x, -y) end
Source
# File lib/capybara/screenshot/diff/region.rb, line 92 def inspect "Region(x: #{x}, y: #{y}, width: #{width}, height: #{height})" end
Source
# File lib/capybara/screenshot/diff/region.rb, line 61 def intersect?(region) left <= region.right && right >= region.left && top <= region.bottom && bottom >= region.top end
Source
# File lib/capybara/screenshot/diff/region.rb, line 65 def move_by(right_by, down_by) Region.new(x + right_by, y + down_by, width, height) end
Source
# File lib/capybara/screenshot/diff/region.rb, line 41 def size return 0 if width < 0 || height < 0 result = width * height result.zero? ? 1 : result end
Source
# File lib/capybara/screenshot/diff/region.rb, line 48 def to_a [@x, @y, @width, @height] end
Source
# File lib/capybara/screenshot/diff/region.rb, line 17 def to_edge_coordinates [left, top, right, bottom] end
Source
# File lib/capybara/screenshot/diff/region.rb, line 21 def to_top_left_corner_coordinates [x, y, width, height] end