Class: Contrek::Concurrent::Part
- Inherits:
-
Object
- Object
- Contrek::Concurrent::Part
- Includes:
- Queueable
- Defined in:
- lib/contrek/finder/concurrent/part.rb
Constant Summary collapse
- SEAM =
1- EXCLUSIVE =
0
Instance Attribute Summary collapse
-
#circular_next ⇒ Object
Returns the value of attribute circular_next.
-
#next ⇒ Object
Returns the value of attribute next.
-
#polyline ⇒ Object
readonly
Returns the value of attribute polyline.
-
#touched ⇒ Object
readonly
Returns the value of attribute touched.
-
#type ⇒ Object
Returns the value of attribute type.
-
#versus ⇒ Object
Returns the value of attribute versus.
Attributes included from Queueable
Instance Method Summary collapse
- #add_position(position) ⇒ Object
-
#initialize(type, polyline) ⇒ Part
constructor
A new instance of Part.
- #innerable? ⇒ Boolean
- #inspect ⇒ Object
- #is?(type) ⇒ Boolean
- #name ⇒ Object
- #next_position(force_position = nil) ⇒ Object
- #orient! ⇒ Object
- #touch! ⇒ Object
Methods included from Queueable
#add, #append, #each, #forward!, #iterator, #map, #next_of!, #pop!, #rem, #reset!, #reverse_each, #rewind!, #to_a
Constructor Details
#initialize(type, polyline) ⇒ Part
Returns a new instance of Part.
13 14 15 16 17 18 19 20 |
# File 'lib/contrek/finder/concurrent/part.rb', line 13 def initialize(type, polyline) @type = type @polyline = polyline @next = nil @circular_next = nil @touched = false @versus = 0 end |
Instance Attribute Details
#circular_next ⇒ Object
Returns the value of attribute circular_next.
12 13 14 |
# File 'lib/contrek/finder/concurrent/part.rb', line 12 def circular_next @circular_next end |
#next ⇒ Object
Returns the value of attribute next.
12 13 14 |
# File 'lib/contrek/finder/concurrent/part.rb', line 12 def next @next end |
#polyline ⇒ Object (readonly)
Returns the value of attribute polyline.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def polyline @polyline end |
#touched ⇒ Object (readonly)
Returns the value of attribute touched.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def touched @touched end |
#type ⇒ Object
Returns the value of attribute type.
12 13 14 |
# File 'lib/contrek/finder/concurrent/part.rb', line 12 def type @type end |
#versus ⇒ Object
Returns the value of attribute versus.
12 13 14 |
# File 'lib/contrek/finder/concurrent/part.rb', line 12 def versus @versus end |
Instance Method Details
#add_position(position) ⇒ Object
26 27 28 29 |
# File 'lib/contrek/finder/concurrent/part.rb', line 26 def add_position(position) hub = is?(EXCLUSIVE) ? nil : polyline.tile.cluster.hub add(Position.new(position: position, hub: hub)) end |
#innerable? ⇒ Boolean
58 59 60 |
# File 'lib/contrek/finder/concurrent/part.rb', line 58 def innerable? (@touched == false) && is?(EXCLUSIVE) end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/contrek/finder/concurrent/part.rb', line 54 def inspect "part #{polyline.parts.index(self)} (versus=#{@versus} touched=#{@touched}, #{size}x) of #{polyline.named} (#{name}) (#{to_a.map { |e| "[#{e[:x]},#{e[:y]}]" }.join})" end |
#is?(type) ⇒ Boolean
22 23 24 |
# File 'lib/contrek/finder/concurrent/part.rb', line 22 def is?(type) @type == type end |
#name ⇒ Object
49 50 51 52 |
# File 'lib/contrek/finder/concurrent/part.rb', line 49 def name {Part::EXCLUSIVE => "EXCLUSIVE", Part::SEAM => "SEAM"}[type] end |
#next_position(force_position = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/contrek/finder/concurrent/part.rb', line 31 def next_position(force_position = nil) if force_position move_to_this = reverse_each { |pos| break pos if pos.payload == force_position.payload } next_of!(move_to_this) force_position else return nil if iterator.nil? position = iterator @touched = true forward! position end end |
#orient! ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/contrek/finder/concurrent/part.rb', line 62 def orient! @versus = if size <= 1 0 else diff = tail.payload[:y] - head.payload[:y] if diff == 0 0 else diff.positive? ? 1 : -1 end end end |
#touch! ⇒ Object
45 46 47 |
# File 'lib/contrek/finder/concurrent/part.rb', line 45 def touch! @touched = true end |