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(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(svg_command, step) ⇒ Object
35 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 |
# File 'lib/convert_svg_string_to_gcode/helpers/create_gcode_array_from_svg_commands.rb', line 35 def self.create_gcode_path_from_bezier(svg_command, step) p0x = svg_command.p0x p0y = svg_command.p0y cp0x = svg_command.cp0x cp0y = svg_command.cp0y cp1x = svg_command.cp1x cp1y = svg_command.cp1y p1x = svg_command.p1x p1y = svg_command.p1y 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} #{PlotterConfig::Z_DOWN}" t+=step end return gcode_array end |
.draw_to_point(new_point) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/convert_svg_string_to_gcode/helpers/create_gcode_array_from_svg_commands.rb', line 28 def self.draw_to_point(new_point) x_value = new_point.p1x y_value = new_point.p1y command = ["G1 X#{x_value} Y#{y_value} #{PlotterConfig::Z_DOWN}"] return command end |
.move_to_point(new_point) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/convert_svg_string_to_gcode/helpers/create_gcode_array_from_svg_commands.rb', line 21 def self.move_to_point(new_point) x_value = new_point.p1x y_value = new_point.p1y command = ["G0 X#{x_value} Y#{y_value} #{PlotterConfig::Z_UP}"] return command 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 |
# 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.type when ConversionConstants::MOVE move_to_point(c) when ConversionConstants::LINE_TO draw_to_point(c) when ConversionConstants::CURVE create_gcode_path_from_bezier(c, step) else throw Error end end end |