Class: JennCad::Primitives::Primitive

Inherits:
Thing
  • Object
show all
Defined in:
lib/jenncad/primitives/primitive.rb

Direct Known Subclasses

BooleanObject, Circle, Polygon, Polyhedron, Slot, Sphere, Square, Text

Instance Attribute Summary collapse

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

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) ⇒ Primitive

Returns a new instance of Primitive.



5
6
7
# File 'lib/jenncad/primitives/primitive.rb', line 5

def initialize(*args)
  super(*args)
end

Instance Attribute Details

#dimensionsObject

Returns the value of attribute dimensions.



3
4
5
# File 'lib/jenncad/primitives/primitive.rb', line 3

def dimensions
  @dimensions
end

Instance Method Details

#feed_opts(args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jenncad/primitives/primitive.rb', line 27

def feed_opts(args)
  if args.kind_of? Array
    m = {}
    if args.last.kind_of? Hash
      m = args.last
    end
    args = [:x, :y, :z].zip(args.flatten).to_h
    args.deep_merge!(m)
    @opts.deep_merge!(args)
  else
    @opts.deep_merge!(args)
  end
end

#handle_diameterObject



17
18
19
20
21
22
23
24
25
# File 'lib/jenncad/primitives/primitive.rb', line 17

def handle_diameter
  @d = opts[:d].to_d
  @r = opts[:r].to_d
  if @d
    @r = @d/2.0
  elsif @r
    @d = @r*2
  end
end

#handle_marginsObject



9
10
11
12
13
14
15
# File 'lib/jenncad/primitives/primitive.rb', line 9

def handle_margins
  @x = @opts[:x].to_d + @opts[:margins][:x].to_d
  @y = @opts[:y].to_d + @opts[:margins][:y].to_d
  if @opts[:z]
    @z = @opts[:z].to_d + @opts[:margins][:z].to_d
  end
end