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_shapes!(shapes) ⇒ Object
- #boundary_shapes ⇒ 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.
7 8 9 10 11 12 13 14 15 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 7 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.
4 5 6 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 4 def benchmarks @benchmarks end |
#circular_next ⇒ Object
Returns the value of attribute circular_next.
5 6 7 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 5 def circular_next @circular_next end |
#cluster ⇒ Object
Returns the value of attribute cluster.
5 6 7 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 5 def cluster @cluster end |
#end_x ⇒ Object (readonly)
Returns the value of attribute end_x.
4 5 6 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 4 def end_x @end_x end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 4 def name @name end |
#next ⇒ Object
Returns the value of attribute next.
5 6 7 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 5 def next @next end |
#prev ⇒ Object
Returns the value of attribute prev.
5 6 7 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 5 def prev @prev end |
#shapes ⇒ Object (readonly)
Returns the value of attribute shapes.
4 5 6 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 4 def shapes @shapes end |
#start_x ⇒ Object (readonly)
Returns the value of attribute start_x.
4 5 6 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 4 def start_x @start_x end |
Instance Method Details
#assign_shapes!(shapes) ⇒ Object
51 52 53 54 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 51 def assign_shapes!(shapes) shapes.each { |s| s.outer_polyline.tile = self } @shapes = shapes end |
#boundary_shapes ⇒ Object
34 35 36 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 34 def boundary_shapes @bbs ||= shapes.select { |s| s.outer_polyline.boundary? } end |
#info ⇒ Object
65 66 67 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 65 def info {name: @name, start_x: @start_x, end_x: @end_x} end |
#initial_process!(finder) ⇒ Object
29 30 31 32 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 29 def initial_process!(finder) result = finder.process_info assign_raw_polygons!(result[:polygons]) end |
#inspect ⇒ Object
73 74 75 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 73 def inspect "#{self.class}[#{@name}]" end |
#iterate ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 38 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
21 22 23 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 21 def left? @start_x == 0 end |
#right? ⇒ Boolean
25 26 27 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 25 def right? @end_x == @finder.maximum_width end |
#tg_border?(coord) ⇒ Boolean
69 70 71 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 69 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 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 56 def to_raw_polygons @shapes.filter_map do |shape| unless shape.outer_polyline.empty? {outer: shape.outer_polyline.raw, inner: shape.inner_polylines} end end end |
#whole? ⇒ Boolean
17 18 19 |
# File 'lib/contrek/finder/concurrent/tile.rb', line 17 def whole? @start_x == 0 && @end_x == @finder.maximum_width end |