Class: Contrek::Concurrent::Merger

Inherits:
Finder
  • Object
show all
Includes:
Poolable
Defined in:
lib/contrek/finder/concurrent/merger.rb

Direct Known Subclasses

HorizontalMerger, VerticalMerger

Instance Attribute Summary collapse

Attributes included from Poolable

#number_of_threads

Attributes inherited from Finder

#maximum_width, #options

Instance Method Summary collapse

Methods included from Poolable

#enqueue!, #wait!

Methods inherited from Finder

#transpose?

Constructor Details

#initialize(options: {}) ⇒ Merger

Returns a new instance of Merger.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/contrek/finder/concurrent/merger.rb', line 9

def initialize(options: {})
  @initialize_time = 0
  @current_x = 0
  @tiles = Queue.new
  @whole_tile = nil
  @user_options = options
  @options = {unsafe_mode: false}.merge(@user_options)
  unless safe?
    warn "[Contrek WARNING] Processing tile with 'unsafe_mode: true'. Incompatible result options might lead to unexpected vector geometry."
  end
end

Instance Attribute Details

#tilesObject (readonly)

Returns the value of attribute tiles.



6
7
8
# File 'lib/contrek/finder/concurrent/merger.rb', line 6

def tiles
  @tiles
end

Instance Method Details

#add_tile(result) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/contrek/finder/concurrent/merger.rb', line 21

def add_tile(result)
  @height ||= result.[:height]
  raise ArgumentError, "All results must have the same height" if @height != result.[:height] && safe?
  @options[:versus] ||= result.[:versus]
  raise ArgumentError, "All results must have the same versus option" if @options[:versus] != result.[:versus] && safe?
  if safe? && result.[:options].key?(:compress)
    if (result.[:options][:compress].keys - [:uniq, :linear]).any?
      raise ArgumentError, "Result with not supported postprocessing compression mode"
    end
  end

  end_x = @current_x + result.[:width]

  tile = Tile.new(
    finder: self,
    start_x: @current_x,
    end_x: end_x,
    name: @tiles.size.to_s
  )
  tile.assign_raw_polygons!(result[:polygons])

  @tiles << tile
  @maximum_width = end_x
  @current_x = end_x - 1
end

#process_infoObject



51
52
53
54
# File 'lib/contrek/finder/concurrent/merger.rb', line 51

def process_info
  process_tiles!(nil, height: @height)
  super
end

#safe?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/contrek/finder/concurrent/merger.rb', line 47

def safe?
  !@options[:unsafe_mode]
end