Class: Contrek::Concurrent::Tile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#benchmarksObject (readonly)

Returns the value of attribute benchmarks.



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

def benchmarks
  @benchmarks
end

#circular_nextObject

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

#clusterObject

Returns the value of attribute cluster.



5
6
7
# File 'lib/contrek/finder/concurrent/tile.rb', line 5

def cluster
  @cluster
end

#end_xObject (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

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#nextObject

Returns the value of attribute next.



5
6
7
# File 'lib/contrek/finder/concurrent/tile.rb', line 5

def next
  @next
end

#prevObject

Returns the value of attribute prev.



5
6
7
# File 'lib/contrek/finder/concurrent/tile.rb', line 5

def prev
  @prev
end

#shapesObject (readonly)

Returns the value of attribute shapes.



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

def shapes
  @shapes
end

#start_xObject (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_shapesObject



34
35
36
# File 'lib/contrek/finder/concurrent/tile.rb', line 34

def boundary_shapes
  @bbs ||= shapes.select { |s| s.outer_polyline.boundary? }
end

#infoObject



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

#inspectObject



73
74
75
# File 'lib/contrek/finder/concurrent/tile.rb', line 73

def inspect
  "#{self.class}[#{@name}]"
end

#iterateObject



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

Returns:

  • (Boolean)


21
22
23
# File 'lib/contrek/finder/concurrent/tile.rb', line 21

def left?
  @start_x == 0
end

#right?Boolean

Returns:

  • (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

Returns:

  • (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_polygonsObject



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

Returns:

  • (Boolean)


17
18
19
# File 'lib/contrek/finder/concurrent/tile.rb', line 17

def whole?
  @start_x == 0 && @end_x == @finder.maximum_width
end