Class: Shape
- Inherits:
-
Object
show all
- Defined in:
- lib/rcad.rb
Direct Known Subclasses
BaseBoltPart, Box, Circle, Cone, Cylinder, GearProfile, HelicalGear, HerringboneGear, LinearExtrusion, Polygon, Polyhedron, Revolution, Sphere, SpurGear, Text, Torus, TransformedShape
Instance Method Summary
collapse
Instance Method Details
#*(right) ⇒ Object
107
108
109
|
# File 'lib/rcad.rb', line 107
def *(right)
Intersection.new(self, right)
end
|
#+(right) ⇒ Object
99
100
101
|
# File 'lib/rcad.rb', line 99
def +(right)
Union.new(self, right)
end
|
#-(right) ⇒ Object
103
104
105
|
# File 'lib/rcad.rb', line 103
def -(right)
Difference.new(self, right)
end
|
#align(*align_pts) ⇒ Object
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
# File 'lib/rcad.rb', line 294
def align(*align_pts)
at = align_pts.pop
if align_pts.empty?
return self.transform(at)
end
combined = align_pts
.map { |apt| (apt.is_a? Transform) ? apt : self.send(apt) }
.reduce :*
combined = (yield self) * combined if block_given?
self.transform(at * combined.inverse)
end
|
#back ⇒ Object
266
267
268
|
# File 'lib/rcad.rb', line 266
def back
I.move_y(maxy)
end
|
#bbox ⇒ Object
198
199
200
201
202
203
204
|
# File 'lib/rcad.rb', line 198
def bbox
if @bbox == nil
@bbox = _bbox
end
@bbox
end
|
#bottom ⇒ Object
274
275
276
|
# File 'lib/rcad.rb', line 274
def bottom
I.move_z(minz)
end
|
#center ⇒ Object
290
291
292
|
# File 'lib/rcad.rb', line 290
def center
I.move(cx, cy, cz)
end
|
#cx ⇒ Object
242
243
244
|
# File 'lib/rcad.rb', line 242
def cx
(minx + maxx) / 2.0
end
|
#cy ⇒ Object
246
247
248
|
# File 'lib/rcad.rb', line 246
def cy
(miny + maxy) / 2.0
end
|
#cz ⇒ Object
250
251
252
|
# File 'lib/rcad.rb', line 250
def cz
(minz + maxz) / 2.0
end
|
#extrude(height, twist = 0) ⇒ Object
190
191
192
|
# File 'lib/rcad.rb', line 190
def extrude(height, twist=0)
LinearExtrusion.new(self, height, twist)
end
|
#front ⇒ Object
262
263
264
|
# File 'lib/rcad.rb', line 262
def front
I.move_y(miny)
end
|
#left ⇒ Object
254
255
256
|
# File 'lib/rcad.rb', line 254
def left
I.move_x(minx)
end
|
#maxx ⇒ Object
218
219
220
|
# File 'lib/rcad.rb', line 218
def maxx
bbox[1][0]
end
|
#maxy ⇒ Object
222
223
224
|
# File 'lib/rcad.rb', line 222
def maxy
bbox[1][1]
end
|
#maxz ⇒ Object
226
227
228
|
# File 'lib/rcad.rb', line 226
def maxz
bbox[1][2]
end
|
#minx ⇒ Object
206
207
208
|
# File 'lib/rcad.rb', line 206
def minx
bbox[0][0]
end
|
#miny ⇒ Object
210
211
212
|
# File 'lib/rcad.rb', line 210
def miny
bbox[0][1]
end
|
#minz ⇒ Object
214
215
216
|
# File 'lib/rcad.rb', line 214
def minz
bbox[0][2]
end
|
#mirror(x, y, z) ⇒ Object
138
139
140
|
# File 'lib/rcad.rb', line 138
def mirror(x, y, z)
TransformedShape.new(self, I.mirror(x, y, z))
end
|
#mirror_x ⇒ Object
178
179
180
|
# File 'lib/rcad.rb', line 178
def mirror_x
mirror(1, 0, 0)
end
|
#mirror_y ⇒ Object
182
183
184
|
# File 'lib/rcad.rb', line 182
def mirror_y
mirror(0, 1, 0)
end
|
#mirror_z ⇒ Object
186
187
188
|
# File 'lib/rcad.rb', line 186
def mirror_z
mirror(0, 0, 1)
end
|
#move(x, y, z) ⇒ Object
126
127
128
|
# File 'lib/rcad.rb', line 126
def move(x, y, z)
TransformedShape.new(self, I.move(x, y, z))
end
|
#move_x(delta) ⇒ Object
142
143
144
|
# File 'lib/rcad.rb', line 142
def move_x(delta)
move(delta, 0, 0)
end
|
#move_y(delta) ⇒ Object
146
147
148
|
# File 'lib/rcad.rb', line 146
def move_y(delta)
move(0, delta, 0)
end
|
#move_z(delta) ⇒ Object
150
151
152
|
# File 'lib/rcad.rb', line 150
def move_z(delta)
move(0, 0, delta)
end
|
#render ⇒ Object
if @shape isn’t defined in a Shape’s initialize() method, then render() should be overridden to create and return it on-the-fly.
95
96
97
|
# File 'lib/rcad.rb', line 95
def render
@shape
end
|
#revolve(angle = nil) ⇒ Object
194
195
196
|
# File 'lib/rcad.rb', line 194
def revolve(angle=nil)
Revolution.new(self, angle)
end
|
#right ⇒ Object
258
259
260
|
# File 'lib/rcad.rb', line 258
def right
I.move_x(maxx)
end
|
#rot_x(angle) ⇒ Object
154
155
156
|
# File 'lib/rcad.rb', line 154
def rot_x(angle)
rotate(angle, [1, 0, 0])
end
|
#rot_y(angle) ⇒ Object
158
159
160
|
# File 'lib/rcad.rb', line 158
def rot_y(angle)
rotate(angle, [0, 1, 0])
end
|
#rot_z(angle) ⇒ Object
162
163
164
|
# File 'lib/rcad.rb', line 162
def rot_z(angle)
rotate(angle, [0, 0, 1])
end
|
#rotate(angle, axis) ⇒ Object
130
131
132
|
# File 'lib/rcad.rb', line 130
def rotate(angle, axis)
TransformedShape.new(self, I.rotate(angle, axis))
end
|
#scale(x, y, z) ⇒ Object
134
135
136
|
# File 'lib/rcad.rb', line 134
def scale(x, y, z)
TransformedShape.new(self, I.scale(x, y, z))
end
|
#scale_x(factor) ⇒ Object
166
167
168
|
# File 'lib/rcad.rb', line 166
def scale_x(factor)
scale(factor, 1, 1)
end
|
#scale_y(factor) ⇒ Object
170
171
172
|
# File 'lib/rcad.rb', line 170
def scale_y(factor)
scale(1, factor, 1)
end
|
#scale_z(factor) ⇒ Object
174
175
176
|
# File 'lib/rcad.rb', line 174
def scale_z(factor)
scale(1, 1, factor)
end
|
#top ⇒ Object
270
271
272
|
# File 'lib/rcad.rb', line 270
def top
I.move_z(maxz)
end
|
122
123
124
|
# File 'lib/rcad.rb', line 122
def transform(trsf)
TransformedShape.new(self, trsf)
end
|
#xcenter ⇒ Object
278
279
280
|
# File 'lib/rcad.rb', line 278
def xcenter
I.move_x(cx)
end
|
#xsize ⇒ Object
230
231
232
|
# File 'lib/rcad.rb', line 230
def xsize
maxx - minx
end
|
#ycenter ⇒ Object
282
283
284
|
# File 'lib/rcad.rb', line 282
def ycenter
I.move_y(cy)
end
|
#ysize ⇒ Object
234
235
236
|
# File 'lib/rcad.rb', line 234
def ysize
maxy - miny
end
|
#zcenter ⇒ Object
286
287
288
|
# File 'lib/rcad.rb', line 286
def zcenter
I.move_z(cz)
end
|
#zsize ⇒ Object
238
239
240
|
# File 'lib/rcad.rb', line 238
def zsize
maxz - minz
end
|
#~@ ⇒ Object
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/rcad.rb', line 111
def ~@
if $shape_mode == :hull
$shape << self
else
$shape = ($shape == nil) ? self : $shape.send($shape_mode, self)
end
p self
self
end
|