Class: JennCad::Primitives::Cylinder
- Includes:
- ZIsh
- Defined in:
- lib/jenncad/primitives/cylinder.rb
Instance Attribute Summary collapse
-
#anchors ⇒ Object
Returns the value of attribute anchors.
-
#d ⇒ Object
Returns the value of attribute d.
-
#d1 ⇒ Object
Returns the value of attribute d1.
-
#d2 ⇒ Object
Returns the value of attribute d2.
-
#fn ⇒ Object
Returns the value of attribute fn.
-
#r ⇒ Object
Returns the value of attribute r.
Attributes inherited from Primitive
Attributes inherited from Thing
#angle, #calc_h, #calc_x, #calc_y, #calc_z, #csize, #diameter, #name, #opts, #parent, #parts, #pos, #shape, #sits_on, #transformations, #x, #y
Instance Method Summary collapse
-
#cz ⇒ Object
Centers the cylinder around it's center point by height This will transform the cylinder around the center point.
- #h ⇒ Object
-
#initialize(args) ⇒ Cylinder
constructor
A new instance of Cylinder.
- #openscad_params ⇒ Object
- #set_anchors ⇒ Object
- #z=(val) ⇒ Object
Methods included from ZIsh
#flip_axis, #flip_rotation, #set_anchors_z
Methods included from CircleIsh
#auto_dn!, #handle_fn, #handle_radius_diameter, #radius, #set_anchors_2d
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_margin
Constructor Details
#initialize(args) ⇒ Cylinder
Returns a new instance of Cylinder.
5 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 |
# File 'lib/jenncad/primitives/cylinder.rb', line 5 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 = [:d, :z].zip(args.flatten).to_h args.deep_merge!(m) end args[:z] ||= args[:h] args[:center_z] ||= args[:cz] @opts = { d: 0, d1: nil, d2: nil, r1: nil, r2: nil, z: nil, r: 0, center_z: false, margins: { r: 0, d: 0, z: 0, }, fn: nil, }.deep_merge!(args) init(args) # FIXME: # - margins calculation needs to go to output # - assinging these variables has to stop # - r+z margin not implemented atm # - need to migrate classes to provide all possible outputs (and non-conflicting ones) to openscad exporter @z = args[:z] || args[:h] handle_radius_diameter handle_fn @dimensions = [:x, :y, :z] set_anchors @csize = Size.new(x: @opts[:d], y: @opts[:d], d: @opts[:d], z: @z) end |
Instance Attribute Details
#anchors ⇒ Object
Returns the value of attribute anchors.
4 5 6 |
# File 'lib/jenncad/primitives/cylinder.rb', line 4 def anchors @anchors end |
#d ⇒ Object
Returns the value of attribute d.
4 5 6 |
# File 'lib/jenncad/primitives/cylinder.rb', line 4 def d @d end |
#d1 ⇒ Object
Returns the value of attribute d1.
4 5 6 |
# File 'lib/jenncad/primitives/cylinder.rb', line 4 def d1 @d1 end |
#d2 ⇒ Object
Returns the value of attribute d2.
4 5 6 |
# File 'lib/jenncad/primitives/cylinder.rb', line 4 def d2 @d2 end |
#fn ⇒ Object
Returns the value of attribute fn.
4 5 6 |
# File 'lib/jenncad/primitives/cylinder.rb', line 4 def fn @fn end |
#r ⇒ Object
Returns the value of attribute r.
4 5 6 |
# File 'lib/jenncad/primitives/cylinder.rb', line 4 def r @r end |
Instance Method Details
#cz ⇒ Object
Centers the cylinder around it's center point by height This will transform the cylinder around the center point.
75 76 77 78 79 80 81 |
# File 'lib/jenncad/primitives/cylinder.rb', line 75 def cz @opts[:center_z] = true @transformations ||= [] @transformations << Move.new(z: -@z / 2.0) set_anchors self end |
#h ⇒ Object
91 92 93 |
# File 'lib/jenncad/primitives/cylinder.rb', line 91 def h z + z_margin end |
#openscad_params ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/jenncad/primitives/cylinder.rb', line 59 def openscad_params res = {} if @opts[:d1] [:d1, :d2, :h, :fn].each do |n| res[n] = self.send n end else [:d, :h, :fn].each do |n| res[n] = self.send n end end res end |
#set_anchors ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/jenncad/primitives/cylinder.rb', line 50 def set_anchors set_anchors_2d set_anchors_z # TODO: figure out if we also want to have "corners" # - possibly move it like a cube # - points at 45 ° angles might not be that useful unless you can get the point on the circle at a given angle # - inner/outer points could be useful for small $fn values end |
#z=(val) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/jenncad/primitives/cylinder.rb', line 83 def z=(val) @z = val @h = val opts[:h] = val opts[:z] = val set_anchors end |