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



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

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



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

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
# File 'lib/contrek/cpp/cpp_result.rb', line 19

def points
  raw_list = polygons.to_a
  @to_points ||= raw_list.map do |polygon|
    {outer: self.class.to_points(polygon[:outer]),
     inner: polygon[:inner].map { |s| self.class.to_points(s) }}
  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



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

def total_time
  [:benchmarks].values.sum
end