Class: Contrek::Concurrent::Tile
- Inherits:
-
Object
- Object
- Contrek::Concurrent::Tile
- Defined in:
- lib/contrek/finder/concurrent/tile.rb
Instance Attribute Summary collapse
-
#benchmarks ⇒ Object
readonly
Returns the value of attribute benchmarks.
-
#circular_next ⇒ Object
Returns the value of attribute circular_next.
-
#cluster ⇒ Object
Returns the value of attribute cluster.
-
#end_x ⇒ Object
readonly
Returns the value of attribute end_x.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#next ⇒ Object
Returns the value of attribute next.
-
#prev ⇒ Object
Returns the value of attribute prev.
-
#shapes ⇒ Object
readonly
Returns the value of attribute shapes.
-
#start_x ⇒ Object
readonly
Returns the value of attribute start_x.
Instance Method Summary collapse
- #assign_raw_polygons!(raw_polylines, treemap = nil) ⇒ Object
- #assign_shapes!(shapes) ⇒ Object
- #compute_treemap ⇒ Object
- #info ⇒ Object
- #initial_process!(finder) ⇒ Object
-
#initialize(finder:, start_x:, end_x:, name:, benchmarks: {}) ⇒ Tile
constructor
A new instance of Tile.
- #inspect ⇒ Object
- #iterate ⇒ Object
- #left? ⇒ Boolean
- #right? ⇒ Boolean
- #tg_border?(coord) ⇒ Boolean
- #to_raw_polygons ⇒ Object
- #whole? ⇒ Boolean
Constructor Details
#initialize(finder:, start_x:, end_x:, name:, benchmarks: {}) ⇒ Tile
Returns a new instance of Tile.
9 10 11 12 13 14 15 16 17 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 9 def initialize(finder:, start_x:, end_x:, name:, benchmarks: {}) @finder = finder @start_x = start_x @end_x = end_x @name = name @prev = nil @next = nil @benchmarks = {outer: 0, inner: 0}.merge(benchmarks) end |
Instance Attribute Details
#benchmarks ⇒ Object (readonly)
Returns the value of attribute benchmarks.
6 7 8 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 6 def benchmarks @benchmarks end |
#circular_next ⇒ Object
Returns the value of attribute circular_next.
7 8 9 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 7 def circular_next @circular_next end |
#cluster ⇒ Object
Returns the value of attribute cluster.
7 8 9 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 7 def cluster @cluster end |
#end_x ⇒ Object (readonly)
Returns the value of attribute end_x.
6 7 8 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 6 def end_x @end_x end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 6 def name @name end |
#next ⇒ Object
Returns the value of attribute next.
7 8 9 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 7 def next @next end |
#prev ⇒ Object
Returns the value of attribute prev.
7 8 9 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 7 def prev @prev end |
#shapes ⇒ Object (readonly)
Returns the value of attribute shapes.
6 7 8 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 6 def shapes @shapes end |
#start_x ⇒ Object (readonly)
Returns the value of attribute start_x.
6 7 8 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 6 def start_x @start_x end |
Instance Method Details
#assign_raw_polygons!(raw_polylines, treemap = nil) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 94 def assign_raw_polygons!(raw_polylines, treemap = nil) @shapes = [] shapes_map = {} raw_polylines.each_with_index do |raw_polyline, polyline_index| next if raw_polyline[:bounds][:max_x] - raw_polyline[:bounds][:min_x] == 0 shape = Shape.new.tap do |shape| shape.outer_polyline = Polyline.new(tile: self, polygon: raw_polyline[:outer], shape: shape, bounds: raw_polyline[:bounds]) shape.inner_polylines = raw_polyline[:inner].map { |raw| InnerPolyline.new(shape: shape, raw_coordinates: raw) } end @shapes << shape if treemap && (treemap_entry = treemap[polyline_index]) shapes_map[polyline_index] = shape if treemap_entry != [-1, -1] parent = shapes_map[treemap_entry.first] shape.set_parent_shape(parent) shape.fixed = true shape.parent_inner_polyline = parent.inner_polylines[treemap_entry.last] end end end end |
#assign_shapes!(shapes) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 49 def assign_shapes!(shapes) shapes.each do |s| s.outer_polyline.tile = self end @shapes = shapes end |
#compute_treemap ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 66 def compute_treemap shapes_map = {} shape_index = 0 shapes.map do |shape| next if shape.outer_polyline.empty? shapes_map[shape] = shape_index shape_index += 1 if shape.parent_shape [shapes_map[shape.parent_shape], shape.parent_shape.inner_polylines.index(shape.parent_inner_polyline)] else [-1, -1] end end end |
#info ⇒ Object
82 83 84 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 82 def info {name: @name, start_x: @start_x, end_x: @end_x} end |
#initial_process!(finder) ⇒ Object
31 32 33 34 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 31 def initial_process!(finder) result = finder.process_info assign_raw_polygons!(result[:polygons], result.[:treemap]) end |
#inspect ⇒ Object
90 91 92 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 90 def inspect "#{self.class}[#{@name}]" end |
#iterate ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 36 def iterate @shapes.each do |shape| shape.outer_polyline.raw.each do |position| yield(position, "O") end shape.inner_polylines.each do |inner| inner.each do |position| yield(position, "I") end end end end |
#left? ⇒ Boolean
23 24 25 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 23 def left? @start_x == 0 end |
#right? ⇒ Boolean
27 28 29 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 27 def right? @end_x == @finder.maximum_width end |
#tg_border?(coord) ⇒ Boolean
86 87 88 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 86 def tg_border?(coord) coord[:x] == (@next.nil? ? @start_x : (@end_x - 1)) end |
#to_raw_polygons ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 56 def to_raw_polygons @shapes.filter_map do |shape| unless shape.outer_polyline.empty? {bounds: (shape.outer_polyline.get_bounds if @finder.[:bounds]), outer: shape.outer_polyline.raw, inner: shape.inner_polylines.map(&:raw)}.compact end end end |
#whole? ⇒ Boolean
19 20 21 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 19 def whole? @start_x == 0 && @end_x == @finder.maximum_width end |