Class: Compix::SubimageMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/compix/match.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(coord_x, coord_y, pixels_compared, pixels_matched) ⇒ SubimageMatch

Returns a new instance of SubimageMatch.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
# File 'lib/compix/match.rb', line 7

def initialize(coord_x, coord_y, pixels_compared, pixels_matched)
  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
end

Instance Attribute Details

#coordinate_xObject (readonly)

Returns the value of attribute coordinate_x.



5
6
7
# File 'lib/compix/match.rb', line 5

def coordinate_x
  @coordinate_x
end

#coordinate_yObject (readonly)

Returns the value of attribute coordinate_y.



5
6
7
# File 'lib/compix/match.rb', line 5

def coordinate_y
  @coordinate_y
end

#pixels_comparedObject (readonly)

Returns the value of attribute pixels_compared.



5
6
7
# File 'lib/compix/match.rb', line 5

def pixels_compared
  @pixels_compared
end

#pixels_matchedObject (readonly)

Returns the value of attribute pixels_matched.



5
6
7
# File 'lib/compix/match.rb', line 5

def pixels_matched
  @pixels_matched
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/compix/match.rb', line 20

def eql?(other)
  other.class.eql?(self.class) && other.state.eql?(self.state)
end

#match_percentageObject



15
16
17
18
# File 'lib/compix/match.rb', line 15

def match_percentage
  return 0 if pixels_compared == 0
  pixels_matched.to_f / pixels_compared
end

#stateObject



24
25
26
# File 'lib/compix/match.rb', line 24

def state
  [@coordinate_x, @coordinate_y, @pixels_compared, @pixels_matched]
end