Class: Contrek::Concurrent::Part

Inherits:
Object
  • Object
show all
Includes:
Queueable
Defined in:
lib/contrek/finder/concurrent/part.rb

Constant Summary collapse

SEAM =
1
EXCLUSIVE =
0
ADDED =
2

Instance Attribute Summary collapse

Attributes included from Queueable

#head, #size, #tail

Instance Method Summary collapse

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_nextObject

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

#indexObject (readonly)

Returns the value of attribute index.



10
11
12
# File 'lib/contrek/finder/concurrent/part.rb', line 10

def index
  @index
end

#invertsObject

Returns the value of attribute inverts.



11
12
13
# File 'lib/contrek/finder/concurrent/part.rb', line 11

def inverts
  @inverts
end

#nextObject

Returns the value of attribute next.



11
12
13
# File 'lib/contrek/finder/concurrent/part.rb', line 11

def next
  @next
end

#passesObject

Returns the value of attribute passes.



11
12
13
# File 'lib/contrek/finder/concurrent/part.rb', line 11

def passes
  @passes
end

#polylineObject (readonly)

Returns the value of attribute polyline.



10
11
12
# File 'lib/contrek/finder/concurrent/part.rb', line 10

def polyline
  @polyline
end

#prevObject

Returns the value of attribute prev.



11
12
13
# File 'lib/contrek/finder/concurrent/part.rb', line 11

def prev
  @prev
end

#touchedObject (readonly)

Returns the value of attribute touched.



10
11
12
# File 'lib/contrek/finder/concurrent/part.rb', line 10

def touched
  @touched
end

#trasmutedObject

Returns the value of attribute trasmuted.



11
12
13
# File 'lib/contrek/finder/concurrent/part.rb', line 11

def trasmuted
  @trasmuted
end

#typeObject

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

Returns:

  • (Boolean)


60
61
62
# File 'lib/contrek/finder/concurrent/part.rb', line 60

def innerable?
  (@touched == false) && is?(EXCLUSIVE)
end

#inspectObject



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

Returns:

  • (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

Returns:

  • (Boolean)


24
25
26
# File 'lib/contrek/finder/concurrent/part.rb', line 24

def is?(type)
  @type == type
end

#nameObject



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