class Qrio::Neighbor

track angle and distance between two Finder Patterns

Constants

ANGLE
NINETY
ONEEIGHTY
ZERO

Attributes

angle[R]
destination[R]
distance[R]
source[R]

Public Class Methods

new(source, destination) click to toggle source
# 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

Public Instance Methods

right_angle?() click to toggle source
# File lib/qrio/neighbor.rb, line 33
def right_angle?
  ZERO.include?(angle.abs)      ||
  NINETY.include?(angle.abs)    ||
  ONEEIGHTY.include?(angle.abs)
end
to_coordinates() click to toggle source
# File lib/qrio/neighbor.rb, line 25
def to_coordinates
  [source.center, destination.center].flatten
end
to_s() click to toggle source
# File lib/qrio/neighbor.rb, line 29
def to_s
  "N[#{ to_coordinates * ',' }]"
end