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
40
41
42
43
44
45
46
47
48
49
|
# 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
@x = args[:x]
@y = args[:y] || @x
@z = args[:z] || @y
centered = args.delete(:center) || args.delete(:c)
super(args)
if centered == true || centered == [:x, :y, :z]
@centered = true
else
@centered = false
centered = [centered].flatten
center_x if centered.include?(:x)
center_y if centered.include?(:y)
center_z if centered.include?(:z)
end
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
71
72
73
74
|
# File 'lib/solidruby/primitives/cube.rb', line 71
def center
@centered = true
self
end
|
#center_x ⇒ Object
56
57
58
59
|
# File 'lib/solidruby/primitives/cube.rb', line 56
def center_x
@transformations << Translate.new(x: -@x / 2.0)
self
end
|
#center_xy ⇒ Object
51
52
53
54
|
# File 'lib/solidruby/primitives/cube.rb', line 51
def center_xy
@transformations << Translate.new(x: -@x / 2.0, y: -@y / 2.0)
self
end
|
#center_y ⇒ Object
61
62
63
64
|
# File 'lib/solidruby/primitives/cube.rb', line 61
def center_y
@transformations << Translate.new(y: -@y / 2.0)
self
end
|
#center_z ⇒ Object
66
67
68
69
|
# File 'lib/solidruby/primitives/cube.rb', line 66
def center_z
@transformations << Translate.new(z: -@z / 2.0)
self
end
|
#centered? ⇒ Boolean
76
77
78
|
# File 'lib/solidruby/primitives/cube.rb', line 76
def centered?
@centered
end
|
#chamfer(args = {}) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/solidruby/primitives/cube.rb', line 80
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 = args[:exclude_self] ? nil : self
trans.each do |t|
res -= Helpers::chamfer(l: t[:length] + 0.02, h: height, a: args[:a] || args[:angle])
.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
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/solidruby/primitives/cube.rb', line 104
def fillet(args = {})
faces = normalise_edges(args)
radius = args[:r] || args[:radius]
trans = translations_for_edge(onto: self, faces: faces, x: @x, y: @y, z: @z, clearance: 0)
res = args[:exclude_self] ? nil : 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
94
95
96
97
98
99
100
101
102
|
# File 'lib/solidruby/primitives/cube.rb', line 94
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
118
119
120
121
122
|
# File 'lib/solidruby/primitives/cube.rb', line 118
def to_rubyscad
args = { size: [@x, @y, @z] }
args[:center] = @centered if @centered
RubyScadBridge.new.cube(args)
end
|