Class: Contrek::Concurrent::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/contrek/finder/concurrent/cursor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster:, shape:) ⇒ Cursor

Returns a new instance of Cursor.



6
7
8
9
10
11
# File 'lib/contrek/finder/concurrent/cursor.rb', line 6

def initialize(cluster:, shape:)
  @shapes_sequence = Set.new([shape])
  @cluster = cluster
  @outer_polyline = shape.outer_polyline
  @orphan_inners = []
end

Instance Attribute Details

#orphan_innersObject (readonly)

Returns the value of attribute orphan_inners.



4
5
6
# File 'lib/contrek/finder/concurrent/cursor.rb', line 4

def orphan_inners
  @orphan_inners
end

#shapes_sequenceObject (readonly)

Returns the value of attribute shapes_sequence.



4
5
6
# File 'lib/contrek/finder/concurrent/cursor.rb', line 4

def shapes_sequence
  @shapes_sequence
end

Instance Method Details

#inspectObject



13
14
15
# File 'lib/contrek/finder/concurrent/cursor.rb', line 13

def inspect
  self.class
end

#join_inners!(outer_seq) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/contrek/finder/concurrent/cursor.rb', line 41

def join_inners!(outer_seq)
  # search for missing sequence to sew
  missing_shapes = []
  @cluster.tiles.each do |tile|
    tile.shapes.each do |shape|
      next if shape.outer_polyline.on?(Polyline::TRACKED_OUTER) ||
        shape.outer_polyline.on?(Polyline::TRACKED_INNER) ||
        !shape.outer_polyline.boundary? ||
        @shapes_sequence.include?(shape)
      missing_shapes << shape
    end
  end

  if missing_shapes.any?
    to_delay_shapes = connect_missings(@shapes_sequence, missing_shapes)
    if to_delay_shapes.any?
      connect_missings(to_delay_shapes, missing_shapes)
      while to_delay_shapes.any?
        to_delay_shapes = connect_missings(@shapes_sequence, to_delay_shapes)
      end
    end
  end

  retme = collect_inner_sequences(outer_seq)

  @shapes_sequence.each do |shape|
    shape.outer_polyline.turn_on(Polyline::TRACKED_INNER)
  end
  retme
end

#join_outers!Object

Given the initial polyline, draw its outer boundary, possibly extending into adjacent polylines, and then connect them. At the end, @shapes_sequence contains the merged polylines. Returns a new resulting polyline.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/contrek/finder/concurrent/cursor.rb', line 20

def join_outers!
  seq_log = []

  outer_joined_polyline = Sequence.new
  traverse_outer(@outer_polyline.parts.first,
    seq_log,
    @shapes_sequence,
    outer_joined_polyline)
  outer_joined_polyline.pop! if outer_joined_polyline.head.payload == outer_joined_polyline.tail.payload &&
    @cluster.tiles.first.left? && @cluster.tiles.last.right?

  @shapes_sequence.each do |shape|
    shape.outer_polyline.turn_on(Polyline::TRACKED_OUTER)
    next if shape == @outer_polyline.shape
    @orphan_inners += shape.inner_polylines
    shape.clear_inner!
  end

  outer_joined_polyline
end