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.
-
#dead_end ⇒ Object
Returns the value of attribute dead_end.
-
#delayed ⇒ Object
Returns the value of attribute delayed.
-
#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.
-
#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.
-
#versus ⇒ Object
Returns the value of attribute versus.
Attributes included from Queueable
Class Method Summary collapse
Instance Method Summary collapse
- #add_position(position) ⇒ 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
- #orient! ⇒ Object
- #set_polyline(polyline) ⇒ Object
- #to_endpoints ⇒ Object
- #touch! ⇒ Object
Methods included from Queueable
#add, #append, #each, #forward!, #iterator, #map, #move_from, #next_of!, #pop!, #rem, #remove_adjacent_pairs!, #replace!, #reset!, #reverse_each, #rewind!, #singleton!, #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 23 24 |
# File 'lib/contrek/finder/concurrent/part.rb', line 12 def initialize(type, polyline) @type = type @polyline = polyline @next = nil @circular_next = nil @prev = nil @dead_end = false @touched = false @inverts = false @trasmuted = false @delayed = false @versus = 0 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 |
#dead_end ⇒ Object
Returns the value of attribute dead_end.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def dead_end @dead_end end |
#delayed ⇒ Object
Returns the value of attribute delayed.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def delayed @delayed 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 |
#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 |
#versus ⇒ Object
Returns the value of attribute versus.
11 12 13 |
# File 'lib/contrek/finder/concurrent/part.rb', line 11 def versus @versus end |
Class Method Details
.remove_adjacent_pairs(array = nil) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/contrek/finder/concurrent/part.rb', line 96 def self.remove_adjacent_pairs(array = nil) n = array.size (0...(n - 1)).each do |i| if array[i] == array[i + 1] # Remove the pair and call recursively new_array = array[0...i] + array[(i + 2)..] return remove_adjacent_pairs(new_array) end end array end |
Instance Method Details
#add_position(position) ⇒ Object
34 35 36 37 |
# File 'lib/contrek/finder/concurrent/part.rb', line 34 def add_position(position) hub = is?(EXCLUSIVE) ? nil : polyline.tile.cluster.hub add(Position.new(position: position, hub: hub)) end |
#innerable? ⇒ Boolean
67 68 69 |
# File 'lib/contrek/finder/concurrent/part.rb', line 67 def innerable? (@touched == false) && is?(EXCLUSIVE) end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/contrek/finder/concurrent/part.rb', line 63 def inspect "part #{polyline.parts.index(self)} (versus=#{@versus} inv=#{@inverts} trm=#{@trasmuted} touched=#{@touched} dead_end =#{@dead_end}, #{size}x) of #{polyline.info} (#{name}) (#{to_a.map { |e| "[#{e[:x]},#{e[:y]}]" }.join})" end |
#intersect_part?(other_part) ⇒ Boolean
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/contrek/finder/concurrent/part.rb', line 71 def intersect_part?(other_part) intersect = false other_part.each do |position| if position.end_point.queues.include?(self) intersect = true false else true end end intersect end |
#is?(type) ⇒ Boolean
26 27 28 |
# File 'lib/contrek/finder/concurrent/part.rb', line 26 def is?(type) @type == type end |
#name ⇒ Object
57 58 59 60 61 |
# File 'lib/contrek/finder/concurrent/part.rb', line 57 def name {Part::EXCLUSIVE => "EXCLUSIVE", Part::SEAM => "SEAM", Part::ADDED => "ADDED"}[type] end |
#next_position(force_position = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/contrek/finder/concurrent/part.rb', line 39 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
88 89 90 91 92 93 94 |
# File 'lib/contrek/finder/concurrent/part.rb', line 88 def orient! @versus = if size <= 1 || (size == 2 && @inverts) 0 else (tail.payload[:y] - head.payload[:y]).positive? ? 1 : -1 end end |
#set_polyline(polyline) ⇒ Object
30 31 32 |
# File 'lib/contrek/finder/concurrent/part.rb', line 30 def set_polyline(polyline) @polyline = polyline end |
#to_endpoints ⇒ Object
84 85 86 |
# File 'lib/contrek/finder/concurrent/part.rb', line 84 def to_endpoints map(&:end_point) end |
#touch! ⇒ Object
53 54 55 |
# File 'lib/contrek/finder/concurrent/part.rb', line 53 def touch! @touched = true end |