Class: Contrek::Concurrent::Cursor
- Inherits:
-
Object
- Object
- Contrek::Concurrent::Cursor
- Defined in:
- lib/contrek/finder/concurrent/cursor.rb
Instance Attribute Summary collapse
-
#orphan_inners ⇒ Object
readonly
Returns the value of attribute orphan_inners.
-
#shapes_sequence ⇒ Object
readonly
Returns the value of attribute shapes_sequence.
Instance Method Summary collapse
-
#initialize(cluster:, shape:) ⇒ Cursor
constructor
A new instance of Cursor.
- #inspect ⇒ Object
- #join_inners!(outer_seq) ⇒ Object
-
#join_outers! ⇒ Object
Given the initial polyline, draw its outer boundary, possibly extending into adjacent polylines, and then connect them.
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_inners ⇒ Object (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_sequence ⇒ Object (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
#inspect ⇒ Object
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 71 |
# File 'lib/contrek/finder/concurrent/cursor.rb', line 41 def join_inners!(outer_seq) return_inner_polylines = [] @processing_shapes = @shapes_sequence.to_a @processing_shapes.each do |shape| polyline = shape.outer_polyline polyline.parts.each do |part| if part.innerable? all_parts = [] bounds = {min: polyline.max_y, max: 0} traverse_inner(part, all_parts, bounds) range_of_bounds = (bounds[:min]..bounds[:max]) retme_sequence = Sequence.new all_parts.each do |part| part.touch! retme_sequence.move_from(part) do |position| next false if part.is?(Part::ADDED) && !(range_of_bounds === position.payload[:y]) !(polyline.tile.tg_border?(position.payload) && position.end_point.tracked_outer) end end if retme_sequence.is_not_vertical return_inner_polylines << InnerPolyline.new(sequence: retme_sequence) end end end end return_inner_polylines 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 |