class Region
Attributes
height[RW]
width[RW]
x[RW]
y[RW]
Public Class Methods
from_edge_coordinates(left, top, right, bottom)
click to toggle 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
new(x, y, width, height)
click to toggle 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
==(other)
click to toggle source
need to add this method to make it work with assert_equal
# 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
blank?()
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 84 def blank? empty? end
bottom()
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 29 def bottom y + height end
cover?(x, y)
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 76 def cover?(x, y) left <= x && x <= right && top <= y && y <= bottom end
empty?()
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 80 def empty? width.zero? || height.zero? end
find_intersect_with(region)
click to toggle 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
find_relative_intersect(region)
click to toggle 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
inspect()
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 92 def inspect "Region(x: #{x}, y: #{y}, width: #{width}, height: #{height})" end
intersect?(region)
click to toggle 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
left()
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 33 def left x end
move_by(right_by, down_by)
click to toggle 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
present?()
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 88 def present? !empty? end
right()
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 37 def right x + width end
size()
click to toggle 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
to_a()
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 48 def to_a [@x, @y, @width, @height] end
to_edge_coordinates()
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 17 def to_edge_coordinates [left, top, right, bottom] end
to_top_left_corner_coordinates()
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 21 def to_top_left_corner_coordinates [x, y, width, height] end
top()
click to toggle source
# File lib/capybara/screenshot/diff/region.rb, line 25 def top y end