Class: JennCad::Primitives::SubtractObject
- Inherits:
-
BooleanObject
- Object
- Thing
- Primitive
- BooleanObject
- JennCad::Primitives::SubtractObject
- Defined in:
- lib/jenncad/primitives/subtract_object.rb
Instance Attribute Summary
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
- #analyze_z_fighting ⇒ Object
- #compare_z(others, compare_h, compare_z) ⇒ Object
- #get_heights(obj) ⇒ Object
- #get_z(obj) ⇒ Object
- #inherit_z ⇒ Object
Methods inherited from BooleanObject
#add, #add_or_new, #after_add, #get_primitives, #inherit_debug, #inherit_zref, #initialize, #only_additives_of
Methods inherited from Primitive
#feed_opts, #handle_diameter, #handle_margins, #initialize
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, #initialize, #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
This class inherits a constructor from JennCad::Primitives::BooleanObject
Instance Method Details
#analyze_z_fighting ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jenncad/primitives/subtract_object.rb', line 38 def analyze_z_fighting first = get_primitives(@parts.first).flatten others = get_primitives(@parts[1..-1]).flatten first_h = get_heights(first).uniq first_z = get_z(first).uniq #puts first.inspect if first_h.size > 1 # puts "first item has multiple heights: #{first_h.inspect}" first_h.each do |h| compare_z(others, h, first_z.first) end else compare_z(others, first_h.first, first_z.first) end self end |
#compare_z(others, compare_h, compare_z) ⇒ Object
56 57 58 59 60 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 96 97 98 99 100 101 102 103 |
# File 'lib/jenncad/primitives/subtract_object.rb', line 56 def compare_z(others,compare_h,compare_z) others.each do |part| #puts part.inspect #puts "#{part.calc_z+part.calc_h} ; #{compare_h}" add_z = nil if part.respond_to? :z part.opts[:margins] ||= {} if part.referenced_z && part.z != 0.0 && part.is_3d? case part when JennCad::BooleanObject else # $log.debug part if part.opts[:debug] part.opts[:margins][:z] ||= 0.0 unless part.opts[:margins][:z] == 0.2 $log.debug "fixing possible z fighting for referenced object: #{part.class} #{part.z} 0.1 down" if part.opts[:debug] part.opts[:margins][:z] = 0.2 part.mz(-0.1) end end elsif part.z == compare_h $log.debug "fixing possible z fighting: #{part.class} #{part.z}" if part.opts[:debug] add_z = 0.008 move_z = -0.004 elsif part.calc_z == compare_z # puts "z fighting at bottom: #{part.calc_z}" add_z = 0.004 # part.z+=0.004 move_z = -0.002 elsif part.calc_z.to_d+part.calc_h.to_d == compare_h # puts "z fighting at top: #{compare_h}" #part.z+=0.004 add_z = 0.004 move_z = 0.002 end if add_z && part.is_3d? if part.kind_of? Part part.modify_values(part, {z: add_z}, {mode: :add}) end part.opts[:margins][:z] += add_z part.mz(move_z) end end end end |
#get_heights(obj) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/jenncad/primitives/subtract_object.rb', line 18 def get_heights(obj) res = [] obj.each do |part| if part.respond_to? :calc_h res << part.calc_h end end res end |
#get_z(obj) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/jenncad/primitives/subtract_object.rb', line 28 def get_z(obj) res = [] obj.each do |part| if part.respond_to? :calc_z res << part.calc_z end end res end |
#inherit_z ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/jenncad/primitives/subtract_object.rb', line 3 def inherit_z @z = 0 @calc_z = parts.first.calc_z.to_d only_additives_of(@parts).each do |p| if option(:debug) $log.debug "inherit_z checks for: #{p}" end z = p.z.to_d @z = z if z > @z end $log.debug "inherit_z called, biggest z found: #{@z}" if option(:debug) end |