Module: Contrek::Shared::Result

Included in:
Cpp::CPPResult, Finder::Result
Defined in:
lib/contrek/shared/result.rb

Instance Method Summary collapse

Instance Method Details

#to_svgObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/contrek/shared/result.rb', line 4

def to_svg
  width = [:width]
  height = [:height]
  lines = []
  lines << %(<svg xmlns="http://www.w3.org/2000/svg" width="#{width}" height="#{height}">)
  points.each do |poly|
    pts = poly[:outer].map { |p| "#{p[:x]},#{p[:y]}" }.join(" ")
    lines << %(<polygon points="#{pts}" fill="none" stroke="red" stroke-width="1"/>)
    poly[:inner].each do |sequence|
      next if sequence.empty?
      pts = sequence.map { |p| "#{p[:x]},#{p[:y]}" }.join(" ")
      lines << %(<polygon points="#{pts}" fill="none" stroke="green" stroke-width="1"/>)
    end
  end
  lines << "</svg>"
  lines.join("\n")
end