Class: JennCad::Primitives::RoundedCube
- Includes:
- Features::Cuttable
- Defined in:
- lib/jenncad/primitives/rounded_cube.rb
Instance Attribute Summary collapse
-
#d ⇒ Object
Returns the value of attribute d.
-
#r ⇒ Object
Returns the value of attribute r.
Attributes inherited from Square
Attributes inherited from Primitive
Attributes inherited from Thing
#anchors, #angle, #calc_h, #calc_x, #calc_y, #calc_z, #csize, #diameter, #fn, #name, #opts, #parent, #parts, #pos, #shape, #sits_on, #transformations, #x, #y
Instance Method Summary collapse
- #flat(*edges) ⇒ Object
-
#initialize(args) ⇒ RoundedCube
constructor
A new instance of RoundedCube.
- #to_openscad ⇒ Object
Methods included from Features::Cuttable
Methods inherited from Cube
Methods included from ZIsh
#cz, #flip_axis, #flip_rotation, #set_anchors_z
Methods inherited from Square
#centered_axis, #cx, #cy, #inner_anchors, #not_centered, #set_anchors, #set_anchors_2d, #size
Methods inherited from Primitive
#feed_opts, #handle_diameter, #handle_margins
Methods inherited from Thing
#anchor, #at, #auto_color, #auto_color!, #auto_extrude, #calculate_center_rotation, #calculated_h, #children_list, #color, #color_or_fallback, #color_parse, #copy_anchor, #copy_anchors, #cut_to, #dbg, #debug?, #find_calculated_h, #fixate, #flip, #flipc, #get_children, #get_contents, #ghost, #has_explicit_color?, #hide, #hl, #inherit_color, #init, #is_2d?, #is_3d?, #mhx, #mhy, #mhz, #mirror, #mix, #miy, #miz, #modify_values, #modify_values!, #move, #movea, #moveai, #moveh, #movei, #multmatrix, #mx, #my, #mz, #on_top_of, #only, #only_color?, #openscad, #openscad_modifier, #option, #parse_xyz_shortcuts, #radians, #referenced_z, #reset, #reset_last_move, #rotate, #rotate_around, #rx, #ry, #rz, #scale, #set_anchor, #set_anchor_from, #set_auto_color, #set_auto_color_for_children, #set_flag, #set_heights_for_auto_extrude, #set_option, #set_parent, #skew, #to_mod, #top_of, #transform, #unset_flag, #z, #z=, #z_margin
Constructor Details
#initialize(args) ⇒ RoundedCube
Returns a new instance of RoundedCube.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 |
# File 'lib/jenncad/primitives/rounded_cube.rb', line 6 def initialize(args) if args.kind_of?(Array) && args[0].kind_of?(Hash) args = args.first end if args.kind_of? Array m = {} if args.last.kind_of? Hash m = args.last end args = [:x, :y, :z, :d].zip(args.flatten).to_h.compact args.deep_merge!(m) end @opts = { d: 5, x: 0, y: 0, z: nil, r: nil, flat_edges: [], center: true, center_y: false, center_x: false, center_z: false, margins: { r: 0, d: 0, x: 0, y: 0, z: 0, }, }.deep_merge!(args) if args.kind_of? Array args.each do |a| feed_opts(parse_xyz_shortcuts(a)) end else feed_opts(parse_xyz_shortcuts(args)) end init(args) @d = opts[:d] @csize = Size.new(x: @opts[:x], y: @opts[:y], z: @opts[:z]) handle_margins handle_diameter if @opts[:z] && opts[:z].to_d > 0 @dimensions = [:x, :y, :z] else @dimensions = [:x, :y] end set_anchors end |
Instance Attribute Details
#d ⇒ Object
Returns the value of attribute d.
3 4 5 |
# File 'lib/jenncad/primitives/rounded_cube.rb', line 3 def d @d end |
#r ⇒ Object
Returns the value of attribute r.
3 4 5 |
# File 'lib/jenncad/primitives/rounded_cube.rb', line 3 def r @r end |
Instance Method Details
#flat(*edges) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/jenncad/primitives/rounded_cube.rb', line 97 def flat(*edges) @opts[:flat_edges] ||= [] edges.each do |edge| @opts[:flat_edges] << edge end self end |
#to_openscad ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/jenncad/primitives/rounded_cube.rb', line 61 def to_openscad # FIXME: this check needs to be done on object creation # otherwise it fails to position it if @d == 0 if @csize.z.to_d > 0 return cube(@opts) else return square(@opts) end end # make diameter not bigger than any side d = [@d, @csize.x, @csize.y].min res = HullObject.new( circle(d: d), circle(d: d).move(x: @csize.x - d, y: 0), circle(d: d).move(x: 0, y: @csize.y - d), circle(d: d).move(x: @csize.x - d, y: @csize.y - d), ) res = res.move(xyh: d) @opts[:flat_edges].each do |edge| res += apply_flat_edge(edge) end if @csize.z.to_d > 0 res = res.extrude(z: @csize.z + z_margin) end res = union(res) # put everything we have in a parent union that we can apply the transformations of this object of res.transformations = @transformations res.moveh(centered_axis.to_h{|a| [a, -@opts[a]] }) res.inherit_color(self) res end |