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, #each, #forward!, #iterator, #map, #move_from, #next_of!, #pop!, #rem, #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
23
# 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
  @versus = 0
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

#dead_endObject

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

#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

#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

#versusObject

Returns the value of attribute versus.



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

def versus
  @versus
end

Instance Method Details

#add_position(position) ⇒ Object



29
30
31
32
# File 'lib/contrek/finder/concurrent/part.rb', line 29

def add_position(position)
  hub = is?(EXCLUSIVE) ? nil : polyline.tile.cluster.hub
  add(Position.new(position: position, hub: hub))
end

#continuum_to?(other) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/contrek/finder/concurrent/part.rb', line 74

def continuum_to?(other)
  return [] if size <= 2 && inverts && other.size <= 2 && other.inverts
  return [] if other.head.nil?

  target = other.head.payload
  cursor = tail
  while cursor
    if cursor.payload == target
      s = cursor
      o = other.head
      match = true
      nodes = []
      while s && o
        if s.payload != o.payload
          match = false
          break
        end
        nodes << s.end_point
        s = s.next
        o = o.next
      end
      if match && s.nil?
        return nodes
      end
    end
    cursor = cursor.prev
  end
  []
end

#innerable?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/contrek/finder/concurrent/part.rb', line 62

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

#inspectObject



58
59
60
# File 'lib/contrek/finder/concurrent/part.rb', line 58

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

#is?(type) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#nameObject



52
53
54
55
56
# File 'lib/contrek/finder/concurrent/part.rb', line 52

def name
  {Part::EXCLUSIVE => "EXCLUSIVE",
   Part::SEAM => "SEAM",
   Part::ADDED => "ADDED"}[type]
end

#next_position(force_position = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/contrek/finder/concurrent/part.rb', line 34

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



66
67
68
69
70
71
72
# File 'lib/contrek/finder/concurrent/part.rb', line 66

def orient!
  @versus = if size <= 1 || (size == 2 && @inverts)
    0
  else
    (tail.payload[:y] - head.payload[:y]).positive? ? 1 : -1
  end
end

#touch!Object



48
49
50
# File 'lib/contrek/finder/concurrent/part.rb', line 48

def touch!
  @touched = true
end