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.



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

def initialize(cluster:, shape:)
  @polylines_sequence = []
  @cluster = cluster
  @outer_polyline = shape.outer_polyline
  @orphan_inners = []
  @shapes = [shape]
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

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



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
71
72
73
74
75
76
77
78
79
80
# File 'lib/contrek/finder/concurrent/cursor.rb', line 45

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? ||
        @polylines_sequence.include?(shape.outer_polyline)
      missing_shapes << shape
    end
  end
  @polylines_sequence.each do |polyline|
    missing_shapes.each do |missing_shape|
      outer_polyline = missing_shape.outer_polyline
      if (intersection = polyline.intersection(outer_polyline)).any?
        inject_sequences_left, inject_sequences_right = polyline.sew!(intersection, outer_polyline)
        combine!(inject_sequences_right, inject_sequences_left).each do |sewn_sequence|
          sewn_sequence.uniq!
          @orphan_inners << sewn_sequence if sewn_sequence.size > 1 && sewn_sequence.map { |c| c[:x] }.uniq.size > 1 # segmenti non sono ammessi, solo aree
        end
        outer_polyline.clear!
        outer_polyline.turn_on(Polyline::TRACKED_OUTER)
        outer_polyline.turn_on(Polyline::TRACKED_INNER)
        @orphan_inners += missing_shape.inner_polylines
      end
    end
  end

  retme = collect_inner_sequences(outer_seq)

  @polylines_sequence.each do |polyline|
    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, @polylines_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
40
41
42
43
# File 'lib/contrek/finder/concurrent/cursor.rb', line 20

def join_outers!
  seq_log = []
  @polylines_sequence << @outer_polyline

  outer_joined_polyline = Sequence.new

  traverse_outer(@outer_polyline.parts.first,
    seq_log,
    @polylines_sequence,
    @shapes,
    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?

  @polylines_sequence.uniq!

  @polylines_sequence.each { |c| c.turn_on(Polyline::TRACKED_OUTER) }
  (@shapes - [@outer_polyline.shape]).each do |shape|
    @orphan_inners += shape.inner_polylines
    shape.clear_inner!
  end

  outer_joined_polyline
end