Module: Contrek::Concurrent::Partitionable
- Included in:
- Polyline
- Defined in:
- lib/contrek/finder/concurrent/partitionable.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #add_part(new_part) ⇒ Object
- #initialize(*args, **kwargs, &block) ⇒ Object
- #inspect_parts ⇒ Object
- #partition! ⇒ Object
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
4 5 6 |
# File 'lib/contrek/finder/concurrent/partitionable.rb', line 4 def parts @parts end |
Instance Method Details
#add_part(new_part) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/contrek/finder/concurrent/partitionable.rb', line 11 def add_part(new_part) last = @parts.last @parts << new_part last.next = last.circular_next = new_part if last new_part.circular_next = @parts.first new_part.prev = last new_part.orient! if new_part.is?(Part::SEAM) end |
#initialize(*args, **kwargs, &block) ⇒ Object
6 7 8 9 |
# File 'lib/contrek/finder/concurrent/partitionable.rb', line 6 def initialize(*args, **kwargs, &block) super @parts = [] end |
#inspect_parts ⇒ Object
21 22 23 |
# File 'lib/contrek/finder/concurrent/partitionable.rb', line 21 def inspect_parts [" "] + ["#{self.class} parts=#{@parts.size}"] + @parts.map { |p| p.inspect } + [" "] end |
#partition! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/contrek/finder/concurrent/partitionable.rb', line 25 def partition! current_part = nil @parts = [] @raw.each_with_index do |position, n| if @tile.tg_border?(position) if current_part.nil? current_part = Part.new(Part::SEAM, self) elsif !current_part.is?(Part::SEAM) add_part(current_part) current_part = Part.new(Part::SEAM, self) end elsif current_part.nil? current_part = Part.new(Part::EXCLUSIVE, self) elsif !current_part.is?(Part::EXCLUSIVE) add_part(current_part) current_part = Part.new(Part::EXCLUSIVE, self) end if n > 0 && @raw[n - 1] == position current_part.inverts = true end current_part.add_position(position) end add_part(current_part) trasmute_parts! end |