Class: CreateGCodeArrayFromSVGCommands
- Inherits:
-
Object
- Object
- CreateGCodeArrayFromSVGCommands
- Defined in:
- lib/convert_svg_string_to_gcode/helpers/create_gcode_array_from_svg_commands.rb
Class Method Summary collapse
- .create_gcode_path_from_bezier(start_point, svg_command, step) ⇒ Object
- .draw_to_point(new_point) ⇒ Object
- .move_to_point(new_point) ⇒ Object
- .perform(commands, options = {step: 0.20}) ⇒ Object
Class Method Details
.create_gcode_path_from_bezier(start_point, svg_command, step) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/convert_svg_string_to_gcode/helpers/create_gcode_array_from_svg_commands.rb', line 36 def self.create_gcode_path_from_bezier(start_point, svg_command, step) p0x = start_point[:x].to_f p0y = start_point[:y].to_f cp0x = svg_command[:cp0x].to_f cp0y = svg_command[:cp0y].to_f cp1x = svg_command[:cp1x].to_f cp1y = svg_command[:cp1y].to_f p1x = svg_command[:p1x].to_f p1y = svg_command[:p1y].to_f t = step gcode_array = [] while t<1 do ax = ( (1 - t) * p0x ) + (t * cp0x) ay = ( (1 - t) * p0y ) + (t * cp0y) bx = ( (1 - t) * cp0x ) + (t * cp1x) by = ( (1 - t) * cp0y ) + (t * cp1y) cx = ( (1 - t) * cp1x ) + (t * p1x) cy = ( (1 - t) * cp1y ) + (t * p1y) dx = ( (1 - t) * ax ) + (t * bx) dy = ( (1 - t) * ay ) + (t * by) ex = ( (1 - t) * bx ) + (t * cx) ey = ( (1 - t) * by ) + (t * cy) new_point_x = ( (1 - t) * dx ) + (t * ex) new_point_y = ( (1 - t) * dy ) + (t * ey) gcode_array << "G1 X#{new_point_x} Y#{new_point_y} Z0" t+=step end return gcode_array, {x: p1x, y: p1y} end |
.draw_to_point(new_point) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/convert_svg_string_to_gcode/helpers/create_gcode_array_from_svg_commands.rb', line 29 def self.draw_to_point(new_point) x_value = new_point[:x].to_f y_value = new_point[:y].to_f command = ["G1 X#{x_value} Y#{y_value} #{MakeblockXYConfig::Z_DOWN}"] return command, new_point end |
.move_to_point(new_point) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/convert_svg_string_to_gcode/helpers/create_gcode_array_from_svg_commands.rb', line 22 def self.move_to_point(new_point) x_value = new_point[:x].to_f y_value = new_point[:y].to_f command = ["G0 X#{x_value} Y#{y_value} #{MakeblockXYConfig::Z_UP}"] return command, new_point end |
.perform(commands, options = {step: 0.20}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/convert_svg_string_to_gcode/helpers/create_gcode_array_from_svg_commands.rb', line 3 def self.perform(commands, = {step: 0.20}) start_point = nil step=[:step] gcode_array = commands.map do |c| case c[:command] when ConversionConstants::MOVE command_array, start_point = move_to_point(c) when ConversionConstants::LINE_TO command_array, start_point = draw_to_point(c) when ConversionConstants::CURVE command_array, start_point = create_gcode_path_from_bezier(start_point, c,step) else throw Error end command_array end end |