Class: Qrio::Neighbor
- Inherits:
-
Object
- Object
- Qrio::Neighbor
- 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
-
#angle ⇒ Object
readonly
Returns the value of attribute angle.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(source, destination) ⇒ Neighbor
constructor
A new instance of Neighbor.
- #right_angle? ⇒ Boolean
- #to_coordinates ⇒ Object
- #to_s ⇒ Object
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
#angle ⇒ Object (readonly)
Returns the value of attribute angle.
4 5 6 |
# File 'lib/qrio/neighbor.rb', line 4 def angle @angle end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
4 5 6 |
# File 'lib/qrio/neighbor.rb', line 4 def destination @destination end |
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
4 5 6 |
# File 'lib/qrio/neighbor.rb', line 4 def distance @distance end |
#source ⇒ Object (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
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_coordinates ⇒ Object
25 26 27 |
# File 'lib/qrio/neighbor.rb', line 25 def to_coordinates [source.center, destination.center].flatten end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/qrio/neighbor.rb', line 29 def to_s "N[#{ to_coordinates * ',' }]" end |