Class: SolidRuby::Primitives::Cube
Instance Attribute Summary collapse
#attributes, #children, #siblings, #transformations
Instance Method Summary
collapse
#&, alias_attr, #debug, #debug?, #mirror, #place, #rotate, #rotate_around, #save, #scale, #translate, #union, #walk_tree, #walk_tree_classes
Constructor Details
#initialize(args = {}, y = nil, z = nil) ⇒ Cube
Returns a new instance of Cube.
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/solidruby/primitives/cube.rb', line 20
def initialize(args={}, y = nil, z = nil)
if args.is_a? Array
args = { x: args[0], y: args[1], z: args[2] }
elsif args.is_a?(Hash) && args[:size]
args[:x] ||= args[:size][0] || 0
args[:y] ||= args[:size][1] || 0
args[:z] ||= args[:size][2] || 0
elsif args.is_a? Numeric
x = args
y ||= x
z ||= y
args = { x: x, y: y, z: z }
end
@centered = args.delete(:center) || args.delete(:c)
@x = args[:x]
@y = args[:y] || @x
@z = args[:z] || @y
super(args)
end
|
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
18
19
20
|
# File 'lib/solidruby/primitives/cube.rb', line 18
def x
@x
end
|
#y ⇒ Object
Returns the value of attribute y.
18
19
20
|
# File 'lib/solidruby/primitives/cube.rb', line 18
def y
@y
end
|
#z ⇒ Object
Returns the value of attribute z.
18
19
20
|
# File 'lib/solidruby/primitives/cube.rb', line 18
def z
@z
end
|
Instance Method Details
#center ⇒ Object
61
62
63
64
|
# File 'lib/solidruby/primitives/cube.rb', line 61
def center
@centered = true
self
end
|
#center_x ⇒ Object
46
47
48
49
|
# File 'lib/solidruby/primitives/cube.rb', line 46
def center_x
@transformations << Translate.new(x: -@x / 2.0)
self
end
|
#center_xy ⇒ Object
41
42
43
44
|
# File 'lib/solidruby/primitives/cube.rb', line 41
def center_xy
@transformations << Translate.new(x: -@x / 2.0, y: -@y / 2.0)
self
end
|
#center_y ⇒ Object
51
52
53
54
|
# File 'lib/solidruby/primitives/cube.rb', line 51
def center_y
@transformations << Translate.new(y: -@y / 2.0)
self
end
|
#center_z ⇒ Object
56
57
58
59
|
# File 'lib/solidruby/primitives/cube.rb', line 56
def center_z
@transformations << Translate.new(z: -@z / 2.0)
self
end
|
#centered? ⇒ Boolean
66
67
68
|
# File 'lib/solidruby/primitives/cube.rb', line 66
def centered?
@centered
end
|
#chamfer(args = {}) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/solidruby/primitives/cube.rb', line 70
def chamfer(args = {})
faces = normalise_edges(args)
height = args[:h] || args[:height]
trans = translations_for_edge(onto: self, faces: faces, x: @x, y: @y, z: @z)
res = self
trans.each do |t|
res -= Helpers::chamfer(l: t[:length] + 0.02, h: height)
.rotate(z: (t[:z_rot] - 180))
.rotate(x: t[:x_rot], y: t[:y_rot])
.translate(x: t[:x_trans], y: t[:y_trans], z: t[:z_trans])
end
res
end
|
#fillet(args = {}) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/solidruby/primitives/cube.rb', line 94
def fillet(args = {})
faces = normalise_edges(args)
radius = args[:r] || args[:radiusg]
trans = translations_for_edge(onto: self, faces: faces, x: @x, y: @y, z: @z, tolerance: 0)
res = self
trans.each do |t|
res -= Helpers::fillet(h: t[:length], r: radius)
.rotate(z: t[:z_rot])
.rotate(x: t[:x_rot], y: t[:y_rot])
.translate(x: t[:x_trans], y: t[:y_trans], z: t[:z_trans])
end
res
end
|
#get_point_on(args = {}) ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'lib/solidruby/primitives/cube.rb', line 84
def get_point_on(args = {})
args[:x] = @x
args[:y] = @y
args[:z] = @z
args[:centered] = @centered
args[:centered_z] = @centered
args[:transformations] = @transformations
calculate_point_on(args)
end
|
#to_rubyscad ⇒ Object
108
109
110
111
112
|
# File 'lib/solidruby/primitives/cube.rb', line 108
def to_rubyscad
args = { size: [@x, @y, @z] }
args[:center] = @centered if @centered
RubyScadBridge.new.cube(args)
end
|