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- ADDED =
2
Instance Attribute Summary collapse
-
#circular_next ⇒ Object
Returns the value of attribute circular_next.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#inverts ⇒ Object
Returns the value of attribute inverts.
-
#next ⇒ Object
Returns the value of attribute next.
-
#passes ⇒ Object
Returns the value of attribute passes.
-
#polyline ⇒ Object
readonly
Returns the value of attribute polyline.
-
#prev ⇒ Object
Returns the value of attribute prev.
-
#touched ⇒ Object
readonly
Returns the value of attribute touched.
-
#trasmuted ⇒ Object
Returns the value of attribute trasmuted.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes included from Queueable
Instance Method Summary collapse
- #add_position(position, n) ⇒ Object
-
#initialize(type, polyline) ⇒ Part
constructor
A new instance of Part.
- #innerable? ⇒ Boolean
- #inspect ⇒ Object
- #intersect_part?(other_part) ⇒ Boolean
- #is?(type) ⇒ Boolean
- #name ⇒ Object
- #next_position(force_position = nil) ⇒ Object
- #touch! ⇒ Object
Methods included from Queueable
#add, #append, #each, #forward!, #intersect_with?, #intersection_with, #intersection_with_array?, #iterator, #map, #move_from, #next_of!, #pop!, #rem, #remove_adjacent_pairs, #remove_adjacent_pairs!, #replace!, #reset!, #reverse_each, #rewind!, #to_a
Constructor Details
#initialize(type, polyline) ⇒ Part
Returns a new instance of Part.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/contrek/finder/concurrent/part.rb', line 12 def initialize(type, polyline) @type = type @polyline = polyline @next = nil @circular_next = nil @prev = nil @passes = 0 @touched = false @inverts = false @trasmuted = false end |
Instance Attribute Details
#circular_next ⇒ Object
Returns the value of attribute circular_next.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def circular_next @circular_next end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
10 11 12 |
# File 'lib/contrek/finder/concurrent/part.rb', line 10 def index @index end |
#inverts ⇒ Object
Returns the value of attribute inverts.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def inverts @inverts end |
#next ⇒ Object
Returns the value of attribute next.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def next @next end |
#passes ⇒ Object
Returns the value of attribute passes.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def passes @passes end |
#polyline ⇒ Object (readonly)
Returns the value of attribute polyline.
10 11 12 |
# File 'lib/contrek/finder/concurrent/part.rb', line 10 def polyline @polyline end |
#prev ⇒ Object
Returns the value of attribute prev.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def prev @prev end |
#touched ⇒ Object (readonly)
Returns the value of attribute touched.
10 11 12 |
# File 'lib/contrek/finder/concurrent/part.rb', line 10 def touched @touched end |
#trasmuted ⇒ Object
Returns the value of attribute trasmuted.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def trasmuted @trasmuted end |
#type ⇒ Object
Returns the value of attribute type.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def type @type end |
Instance Method Details
#add_position(position, n) ⇒ Object
28 29 30 |
# File 'lib/contrek/finder/concurrent/part.rb', line 28 def add_position(position, n) add(Position.new(position: position, hub: polyline.tile.cluster.hub)) end |
#innerable? ⇒ Boolean
60 61 62 |
# File 'lib/contrek/finder/concurrent/part.rb', line 60 def innerable? (@touched == false) && is?(EXCLUSIVE) end |
#inspect ⇒ Object
56 57 58 |
# File 'lib/contrek/finder/concurrent/part.rb', line 56 def inspect "part #{polyline.parts.index(self)} (inv=#{@inverts} trm=#{@trasmuted} touched=#{@touched} passes=#{@passes}, #{size}x) of #{polyline.info} (#{name}) (#{to_a.map { |e| "[#{e[:x]},#{e[:y]}]" }.join})" end |
#intersect_part?(other_part) ⇒ Boolean
64 65 66 67 68 69 |
# File 'lib/contrek/finder/concurrent/part.rb', line 64 def intersect_part?(other_part) other_part.each do |position| return true if position.end_point.queues.include?(self) end false end |
#is?(type) ⇒ Boolean
24 25 26 |
# File 'lib/contrek/finder/concurrent/part.rb', line 24 def is?(type) @type == type end |
#name ⇒ Object
50 51 52 53 54 |
# File 'lib/contrek/finder/concurrent/part.rb', line 50 def name {Part::EXCLUSIVE => "EXCLUSIVE", Part::SEAM => "SEAM", Part::ADDED => "ADDED"}[type] end |
#next_position(force_position = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/contrek/finder/concurrent/part.rb', line 32 def next_position(force_position = nil) if force_position move_to_this = reverse_each { |pos| break pos if pos.payload == force_position } next_of!(move_to_this) force_position else return nil if iterator.nil? position = iterator @touched = true forward! position end end |
#touch! ⇒ Object
46 47 48 |
# File 'lib/contrek/finder/concurrent/part.rb', line 46 def touch! @touched = true end |