Skip to content

Commit

Permalink
Merge pull request #4 from instantink/fix-error-exclude-area
Browse files Browse the repository at this point in the history
Fix the error when trying to add a rect exclude area that is partially outside the image bound
  • Loading branch information
cristianofmc authored Apr 6, 2023
2 parents 48aad4d + 1027fe7 commit b0d3f88
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- v1.0.3: Fix documentation ([@gsguma][])
- v1.0.4: Fix gem documentation images ([@gsguma][])
- v1.0.5: Fix gem documentation ([@gsguma][])
- v1.0.6: Fix the error when trying to add a rect exclude area that is partially outside the image bounds ([@gsguma][])

[@gsguma]: https://github.com/gsguma
[@cristianofmc]: https://github.com/cristianofmc
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# ImageCompare
[<img src="https://shields.io/github/license/instantink/image_compare?color=%2345a34c" />](LICENSE.txt)
[<img src="https://shields.io/gem/v/image_compare" />](https://rubygems.org/gems/image_compare)
<img alt="Gem total downloads" src="https://shields.io/gem/dt/image_compare" />

Compare PNG images in pure Ruby (uses [ChunkyPNG](https://github.com/wvanbergen/chunky_png)) using different algorithms.
This is an utility library for image regression testing.
Expand Down
2 changes: 1 addition & 1 deletion image_compare.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
spec.files = Dir.glob("lib/**/*") + Dir.glob("bin/**/*") + %w[README.md LICENSE.txt CHANGELOG.md]
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 3.2.0"
spec.add_dependency "chunky_png", "~> 1.4"
spec.add_dependency "chunky_png", "1.3.15"
spec.add_development_dependency "rake", "~> 13.0", ">= 13.0.6"
spec.add_development_dependency "rspec", "~> 3.12"
end
6 changes: 0 additions & 6 deletions lib/image_compare/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ def compare(a, b)

image_area = Rectangle.new(0, 0, a.width - 1, a.height - 1)

unless mode.exclude_rect.nil?
unless image_area.contains?(mode.exclude_rect)
raise ArgumentError, "Bounds must be in image"
end
end

unless mode.include_rect.nil?
unless image_area.contains?(mode.include_rect)
raise ArgumentError, "Bounds must be in image"
Expand Down
8 changes: 3 additions & 5 deletions lib/image_compare/modes/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ def initialize(**options)
def diff(bg, diff)
diff_image = bg.highlight_rectangle(exclude_rect, :blue)

if area_in_exclude_rect?
diff_image
else
diff_image.highlight_rectangle(bounds)
end
return diff_image if self.result.match?

diff_image.highlight_rectangle(bounds) unless area_in_exclude_rect?
end

def area_in_exclude_rect?
Expand Down
2 changes: 1 addition & 1 deletion lib/image_compare/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ImageCompare
VERSION = "1.0.5"
VERSION = "1.0.6"
end

0 comments on commit b0d3f88

Please sign in to comment.