Module: Contrek::Concurrent::Partitionable

Included in:
Polyline
Defined in:
lib/contrek/finder/concurrent/partitionable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts.



6
7
8
# File 'lib/contrek/finder/concurrent/partitionable.rb', line 6

def parts
  @parts
end

Instance Method Details

#add_part(new_part) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/contrek/finder/concurrent/partitionable.rb', line 15

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
  if new_part.is?(Part::SEAM)
    @first_seam ||= new_part
    if !@last_seam.nil?
      @last_seam.next_seam = new_part
    end
    @last_seam = new_part
    new_part.orient!
  end
end

#initialize(*args, **kwargs, &block) ⇒ Object



8
9
10
11
12
13
# File 'lib/contrek/finder/concurrent/partitionable.rb', line 8

def initialize(*args, **kwargs, &block)
  super
  @parts = []
  @first_seam = nil
  @last_seam = nil
end

#inspect_partsObject



31
32
33
# File 'lib/contrek/finder/concurrent/partitionable.rb', line 31

def inspect_parts
  [" "] + ["#{self.class} parts=#{@parts.size}"] + @parts.map { |p| p.inspect } + [" "]
end

#partition!Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/contrek/finder/concurrent/partitionable.rb', line 35

def partition!
  current_part = nil
  @parts = []
  @first_seam = nil
  @last_seam = nil

  @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)

  transmute_parts!
end