Class: AdjustSVGCommandsForPlotter
- Inherits:
-
Object
- Object
- AdjustSVGCommandsForPlotter
- Defined in:
- lib/convert_svg_string_to_gcode/helpers/adjust_svg_commands_for_plotter.rb
Class Method Summary collapse
- .add_margin_to_svg_commands(svg_commands, min_x, min_y, buffer = 20.0) ⇒ Object
- .get_min_x_y(svg_commands) ⇒ Object
- .perform(svg_commands, proportion = 0.10) ⇒ Object
- .resize_svg_commands_by_proportion_and_get_min_x_y(svg_commands, proportion) ⇒ Object
Class Method Details
.add_margin_to_svg_commands(svg_commands, min_x, min_y, buffer = 20.0) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/convert_svg_string_to_gcode/helpers/adjust_svg_commands_for_plotter.rb', line 41 def self.add_margin_to_svg_commands(svg_commands, min_x, min_y, buffer=20.0) svg_commands.map do |command| buffered_command={} command.each_key do |k| if [:x,:cp0x,:cp1x,:p1x].include? k buffered_command[k] = command[k]-min_x+buffer elsif [:y,:cp0y,:cp1y,:p1y].include? k buffered_command[k] = command[k]-min_y+buffer else buffered_command[k] = command[k] end end buffered_command end end |
.get_min_x_y(svg_commands) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/convert_svg_string_to_gcode/helpers/adjust_svg_commands_for_plotter.rb', line 23 def self.get_min_x_y(svg_commands) min_x = nil min_y = nil svg_commands.map do |command| command.each_key do |key| if ConversionConstants::X_LABELS.include? key min_x = command[key] if !min_x || command[key]<min_x end if ConversionConstants::Y_LABELS.include? key min_y = command[key] if !min_y || command[key]<min_y end end end return min_x, min_y end |
.perform(svg_commands, proportion = 0.10) ⇒ Object
3 4 5 6 7 |
# File 'lib/convert_svg_string_to_gcode/helpers/adjust_svg_commands_for_plotter.rb', line 3 def self.perform(svg_commands,proportion=0.10) skewed_svg_commands, min_x, min_y = resize_svg_commands_by_proportion_and_get_min_x_y(svg_commands, proportion) min_x, min_y = get_min_x_y(skewed_svg_commands) buffered_svg_commands = add_margin_to_svg_commands(skewed_svg_commands, min_x, min_y) end |
.resize_svg_commands_by_proportion_and_get_min_x_y(svg_commands, proportion) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/convert_svg_string_to_gcode/helpers/adjust_svg_commands_for_plotter.rb', line 9 def self.resize_svg_commands_by_proportion_and_get_min_x_y(svg_commands, proportion) min_x = nil min_y = nil skewed_svg_commands = svg_commands.map do |command| mutated_command = {} command.each_key do |k| mutated_command[k] = Float(command[k])*proportion unless k==:command mutated_command[k] = command[k] if k==:command end mutated_command end return skewed_svg_commands, min_x, min_y end |