lib/capybara/screenshot/diff/image_compare.rb in capybara-screenshot-diff-0.6.0 vs lib/capybara/screenshot/diff/image_compare.rb in capybara-screenshot-diff-0.7.0

- old
+ new

@@ -27,11 +27,11 @@ @annotated_new_file_name = "#{new_file_name.chomp('.png')}_1.png~" reset end def reset - @max_color_distance = 0 if @color_distance_limit + @max_color_distance = @color_distance_limit ? 0 : nil @left = @top = @right = @bottom = nil end # Compare the two image files and return `true` or `false` as quickly as possible. # Return falsish if the old file does not exist or the image dimensions do not match. @@ -227,16 +227,15 @@ end private def same_color?(old_img, new_img, x, y) org_color = old_img[x, y] new_color = new_img[x, y] - if @color_distance_limit && @color_distance_limit > 0 - distance = ChunkyPNG::Color.euclidean_distance_rgba(org_color, new_color) - @max_color_distance = distance if distance > @max_color_distance - distance <= @color_distance_limit - else - org_color == new_color - end + return true if org_color == new_color + + distance = ChunkyPNG::Color.euclidean_distance_rgba(org_color, new_color) + @max_color_distance = distance if !@max_color_distance || distance > @max_color_distance + + @color_distance_limit && @color_distance_limit > 0 && distance <= @color_distance_limit end end end end end