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, width, height, limit_for_match = DEFAULT_PERCENT) ⇒ SubimageMatch

Returns a new instance of SubimageMatch.

Raises:

  • (ArgumentError)


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_xObject (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_yObject (readonly)

Returns the value of attribute coordinate_y.



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

def coordinate_y
  @coordinate_y
end

#heightObject (readonly)

Returns the value of attribute height.



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

def height
  @height
end

#pixels_comparedObject (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_matchedObject (readonly)

Returns the value of attribute pixels_matched.



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

def pixels_matched
  @pixels_matched
end

#widthObject (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_middleObject



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

Returns:

  • (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

Returns:

  • (Boolean)


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

def match?
  @match
end

#match_percentageObject



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

Returns:

  • (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

#stateObject



40
41
42
# File 'lib/compix/match.rb', line 40

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