Class: Compix::SubimageMatch
- Inherits:
-
Object
- Object
- Compix::SubimageMatch
- Defined in:
- lib/compix/match.rb
Instance Attribute Summary collapse
-
#coordinate_x ⇒ Object
readonly
Returns the value of attribute coordinate_x.
-
#coordinate_y ⇒ Object
readonly
Returns the value of attribute coordinate_y.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#pixels_compared ⇒ Object
readonly
Returns the value of attribute pixels_compared.
-
#pixels_matched ⇒ Object
readonly
Returns the value of attribute pixels_matched.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #coordinate_middle ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(coord_x, coord_y, pixels_compared, pixels_matched, width, height, limit_for_match = DEFAULT_PERCENT) ⇒ SubimageMatch
constructor
A new instance of SubimageMatch.
- #match? ⇒ Boolean
- #match_percentage ⇒ Object
- #overlaped_by?(other) ⇒ Boolean
- #state ⇒ Object
Constructor Details
#initialize(coord_x, coord_y, pixels_compared, pixels_matched, width, height, limit_for_match = DEFAULT_PERCENT) ⇒ SubimageMatch
Returns a new instance of SubimageMatch.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/compix/match.rb', line 8 def initialize(coord_x, coord_y, pixels_compared, pixels_matched, width, height, limit_for_match=DEFAULT_PERCENT) raise ArgumentError.new("Matched more pixels ('#{pixels_matched}') than compared ('#{pixels_compared}')") if pixels_compared < pixels_matched @coordinate_x = coord_x @coordinate_y = coord_y @pixels_compared = pixels_compared @pixels_matched = pixels_matched @width = width @height = height @match = limit_for_match <= self.match_percentage end |
Instance Attribute Details
#coordinate_x ⇒ Object (readonly)
Returns the value of attribute coordinate_x.
6 7 8 |
# File 'lib/compix/match.rb', line 6 def coordinate_x @coordinate_x end |
#coordinate_y ⇒ Object (readonly)
Returns the value of attribute coordinate_y.
6 7 8 |
# File 'lib/compix/match.rb', line 6 def coordinate_y @coordinate_y end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
6 7 8 |
# File 'lib/compix/match.rb', line 6 def height @height end |
#pixels_compared ⇒ Object (readonly)
Returns the value of attribute pixels_compared.
6 7 8 |
# File 'lib/compix/match.rb', line 6 def pixels_compared @pixels_compared end |
#pixels_matched ⇒ Object (readonly)
Returns the value of attribute pixels_matched.
6 7 8 |
# File 'lib/compix/match.rb', line 6 def pixels_matched @pixels_matched end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
6 7 8 |
# File 'lib/compix/match.rb', line 6 def width @width end |
Instance Method Details
#coordinate_middle ⇒ Object
44 45 46 47 48 |
# File 'lib/compix/match.rb', line 44 def coordinate_middle x = @coordinate_x + @width / 2 y = @coordinate_y + @height / 2 return [x, y] end |
#eql?(other) ⇒ Boolean
28 29 30 |
# File 'lib/compix/match.rb', line 28 def eql?(other) other.class.eql?(self.class) && other.state.eql?(self.state) end |
#match? ⇒ Boolean
24 25 26 |
# File 'lib/compix/match.rb', line 24 def match? @match end |
#match_percentage ⇒ Object
19 20 21 22 |
# File 'lib/compix/match.rb', line 19 def match_percentage return 0 if pixels_compared == 0 pixels_matched.to_f / pixels_compared end |
#overlaped_by?(other) ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/compix/match.rb', line 32 def overlaped_by?(other) return false if other.coordinate_x + other.width <= @coordinate_x return false if other.coordinate_x >= @coordinate_x + @width return false if other.coordinate_y + other.height <= @coordinate_y return false if other.coordinate_y >= @coordinate_y + @height true end |
#state ⇒ Object
40 41 42 |
# File 'lib/compix/match.rb', line 40 def state [@coordinate_x, @coordinate_y, @pixels_compared, @pixels_matched] end |