Class: Qrio::Neighbor

Inherits:
Object
  • Object
show all
Defined in:
lib/qrio/neighbor.rb

Overview

track angle and distance between two Finder Patterns

Constant Summary collapse

ANGLE =
Math::PI / 8
ZERO =
0..ANGLE
NINETY =
(ANGLE * 3)..(ANGLE * 5)
ONEEIGHTY =
(ANGLE * 7)..(ANGLE * 8)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, destination) ⇒ Neighbor

Returns a new instance of Neighbor.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/qrio/neighbor.rb', line 11

def initialize(source, destination)
  @source      = source
  @destination = destination

  source.neighbors << self

  dx = destination.center.first - source.center.first
  # images are top down, geometry is bottom up.  invert.
  dy = source.center.last - destination.center.last

  @angle    = Math.atan2(dy, dx)
  @distance = Math.sqrt(dx ** 2 + dy ** 2)
end

Instance Attribute Details

#angleObject (readonly)

Returns the value of attribute angle.



4
5
6
# File 'lib/qrio/neighbor.rb', line 4

def angle
  @angle
end

#destinationObject (readonly)

Returns the value of attribute destination.



4
5
6
# File 'lib/qrio/neighbor.rb', line 4

def destination
  @destination
end

#distanceObject (readonly)

Returns the value of attribute distance.



4
5
6
# File 'lib/qrio/neighbor.rb', line 4

def distance
  @distance
end

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/qrio/neighbor.rb', line 4

def source
  @source
end

Instance Method Details

#right_angle?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/qrio/neighbor.rb', line 33

def right_angle?
  ZERO.include?(angle.abs)      ||
  NINETY.include?(angle.abs)    ||
  ONEEIGHTY.include?(angle.abs)
end

#to_coordinatesObject



25
26
27
# File 'lib/qrio/neighbor.rb', line 25

def to_coordinates
  [source.center, destination.center].flatten
end

#to_sObject



29
30
31
# File 'lib/qrio/neighbor.rb', line 29

def to_s
  "N[#{ to_coordinates * ',' }]"
end