Class: Contrek::Cpp::CPPResult

Inherits:
Object
  • Object
show all
Includes:
Shared::Result
Defined in:
lib/contrek/cpp/cpp_result.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shared::Result

#to_svg

Class Method Details

.to_numpy(polygons_data) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/contrek/cpp/cpp_result.rb', line 36

def self.to_numpy(polygons_data)
  polygons_data.map do |poly|
    {outer: poly[:outer].flat_map { |p| [p[:x], p[:y]] },
     inner: (poly[:inner] || []).map { |hole| hole.flat_map { |p| [p[:x], p[:y]] } },
     bounds: poly[:bounds]}
  end
end

.to_points(flat_polygon) ⇒ Object



32
33
34
# File 'lib/contrek/cpp/cpp_result.rb', line 32

def self.to_points(flat_polygon)
  flat_polygon.each_slice(2).map { |x, y| {x: x, y: y} }
end

Instance Method Details

#metadata=(map) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/contrek/cpp/cpp_result.rb', line 10

def metadata=(map)
  @metadata_storage = {
    width: 0,
    height: 0,
    benchmarks: {},
    treemap: []
  }.merge(map)
end

#pointsObject



19
20
21
22
23
24
25
26
# File 'lib/contrek/cpp/cpp_result.rb', line 19

def points
  raw_list = polygons.to_a
  @to_points ||= raw_list.map do |polygon|
    {bounds: (polygon[:bounds] if polygon.key?(:bounds)),
     outer: self.class.to_points(polygon[:outer]),
     inner: polygon[:inner].map { |s| self.class.to_points(s) }}.compact
  end
end

#polygons=(list) ⇒ Object



6
7
8
# File 'lib/contrek/cpp/cpp_result.rb', line 6

def polygons=(list)
  @polygons_storage = list
end

#total_timeObject



28
29
30
# File 'lib/contrek/cpp/cpp_result.rb', line 28

def total_time
  [:benchmarks].values.sum
end