Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ General Considerations

- All arguments are passed as named hash values matching the openscad spec, exceptions are for functions fa, fs, fn, echo, include, and use (see below).
openscad: `cube(6)`
rubyscad: `cube(size: 6)`
rubyscad: `cube(size: 6)`
- It is however possible to use ruby arrays (or vectors and even matrices) as an argument instead of a hash as a shortcut.
The following 4 snippets produce identical output.
openscad: `cube(size = [6,6,12]);`
rubyscad: `cube(size: [6,6,12])`
openscad: `cube([6,6,12]);`
rubyscad: `cube([6,6,12])`
Please notice though that Rubyscad doesn't check if the code with an array as argument is valid openscad code, eg. `cylinder([10,10,5])` becomes `cylinder([10, 10, 5]);`, which is nonsense openscad code.
- Any hash values may be passed to functions (with the exception of the ones noted above) but openscad may or may not use these values
*cube(openscadwontusethis: 5)* will produce *cube(openscadwontusethis = 5);*
nothing bad will happen here, the value will just have no effect
Expand Down Expand Up @@ -320,4 +327,4 @@ RubyScad Functions:

`format_output`

* outputs a string at the correct tab level
* outputs a string at the correct tab level
10 changes: 7 additions & 3 deletions lib/rubyscad/RubyScad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ def color(args={}, &block)
end

def format_command(cmd_str, args={}, &block)
unless args.kind_of? String
arg_str = args.collect { |k, v| "#{format_key(k)} = #{format_value(v)}" }.join(', ')
if args.kind_of? String
arg_str = args
elsif [Array, Vector, Matrix].any? { |klass| args.is_a? klass }
arg_str = format_value(args)
else
arg_str = args
arg_str = args.collect { |k, v| "#{format_key(k)} = #{format_value(v)}" }.join(', ')
end

format_block cmd_str % {args: arg_str}, &block
end

Expand All @@ -258,6 +261,7 @@ def delete_from(hash, *keys)
end

def vector_input(args, element)
return unless args.is_a? Hash
unless args.include?(element)
args[element] = [args.fetch(:x, 0), args.fetch(:y, 0)]
args[element].push(args[:z]) if args.include?(:z)
Expand Down