Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/shapes.rb,
lib/kernel/array.rb
Overview
Array クラス拡張メソッド
Class Method Summary collapse
Instance Method Summary collapse
- #bndbox ⇒ Object
- #center(other) ⇒ Object
- #compounds ⇒ Object
- #dist(other) ⇒ Object
- #edges ⇒ Object
- #equal?(other, lintol) ⇒ Boolean
- #faces ⇒ Object
- #from(other) ⇒ Object
- #mirror(op, dir = Siren::Vec.zero) ⇒ Object
- #mirror!(op, dir = Siren::Vec.zero) ⇒ Object
- #rotate(op, dir, angle) ⇒ Object
- #rotate!(op, dir, angle) ⇒ Object
- #scale(op, f) ⇒ Object
- #scale!(op, f) ⇒ Object
- #shells ⇒ Object
- #solids ⇒ Object
- #to(other) ⇒ Object
- #to_comp ⇒ Object
- #to_loft ⇒ Object
- #to_polygon ⇒ Object
- #to_polyline ⇒ Object
- #to_revol ⇒ Object
- #to_shell ⇒ Object
- #to_solid ⇒ Object
- #to_v ⇒ Object
- #to_wire(tol = 0.001) ⇒ Object
- #trans(t) ⇒ Object
- #trans!(t) ⇒ Object
- #translate(t) ⇒ Object
- #translate!(t) ⇒ Object
- #vertices ⇒ Object
- #wires ⇒ Object
- #x ⇒ Object
- #x=(val) ⇒ Object
- #xyz ⇒ Object
- #xyz=(val) ⇒ Object
- #y ⇒ Object
- #y=(val) ⇒ Object
- #z ⇒ Object
- #z=(val) ⇒ Object
Class Method Details
.origin ⇒ Object
129 130 131 |
# File 'lib/kernel/array.rb', line 129 def self.origin [0, 0, 0] end |
Instance Method Details
#bndbox ⇒ Object
47 48 49 |
# File 'lib/shapes.rb', line 47 def bndbox raise NotImplementedError end |
#center(other) ⇒ Object
30 31 32 |
# File 'lib/kernel/array.rb', line 30 def center(other) ((self.to_v + other.to_v) / 2.0).xyz end |
#compounds ⇒ Object
45 |
# File 'lib/shapes.rb', line 45 def compounds; self.map(&:compounds).flatten end |
#dist(other) ⇒ Object
26 27 28 |
# File 'lib/kernel/array.rb', line 26 def dist(other) (self.to_v - other.to_v).magnitude end |
#edges ⇒ Object
40 |
# File 'lib/shapes.rb', line 40 def edges; self.map(&:edges).flatten end |
#equal?(other, lintol) ⇒ Boolean
34 35 36 |
# File 'lib/kernel/array.rb', line 34 def equal?(other, lintol) dist(other) < lintol end |
#faces ⇒ Object
42 |
# File 'lib/shapes.rb', line 42 def faces; self.map(&:faces).flatten end |
#from(other) ⇒ Object
14 15 16 |
# File 'lib/kernel/array.rb', line 14 def from(other) self.to_v - other.to_v end |
#mirror(op, dir = Siren::Vec.zero) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/kernel/array.rb', line 71 def mirror(op, dir = Siren::Vec.zero) if dir == Siren::Vec.zero op.translate(self.to(op)).xyz else self.from(op).mirror(dir).xyz.translate(op).xyz end end |
#mirror!(op, dir = Siren::Vec.zero) ⇒ Object
79 80 81 |
# File 'lib/kernel/array.rb', line 79 def mirror!(op, dir = Siren::Vec.zero) self.xyz = mirror(op, dir) end |
#rotate(op, dir, angle) ⇒ Object
51 52 53 |
# File 'lib/kernel/array.rb', line 51 def rotate(op, dir, angle) self.from(op).rotate(dir, angle).xyz.translate(op).xyz end |
#rotate!(op, dir, angle) ⇒ Object
55 56 57 |
# File 'lib/kernel/array.rb', line 55 def rotate!(op, dir, angle) self.xyz = rotate(op, dir, angle) end |
#scale(op, f) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/kernel/array.rb', line 59 def scale(op, f) if (op.equal?(self, 1.0e-7)) self.xyz else (self.from(op).normal * f).xyz.translate(op).xyz end end |
#scale!(op, f) ⇒ Object
67 68 69 |
# File 'lib/kernel/array.rb', line 67 def scale!(op, f) self.xyz = scale(op, f) end |
#shells ⇒ Object
43 |
# File 'lib/shapes.rb', line 43 def shells; self.map(&:shells).flatten end |
#solids ⇒ Object
44 |
# File 'lib/shapes.rb', line 44 def solids; self.map(&:solids).flatten end |
#to(other) ⇒ Object
10 11 12 |
# File 'lib/kernel/array.rb', line 10 def to(other) other.to_v - self.to_v end |
#to_loft ⇒ Object
19 20 21 |
# File 'lib/shapes.rb', line 19 def to_loft raise NotImplementedError end |
#to_polygon ⇒ Object
11 12 13 |
# File 'lib/shapes.rb', line 11 def to_polygon Siren.polygon self end |
#to_polyline ⇒ Object
7 8 9 |
# File 'lib/shapes.rb', line 7 def to_polyline Siren.polyline self end |
#to_revol ⇒ Object
23 24 25 |
# File 'lib/shapes.rb', line 23 def to_revol raise NotImplementedError end |
#to_shell ⇒ Object
27 28 29 |
# File 'lib/shapes.rb', line 27 def to_shell Siren.shell self end |
#to_solid ⇒ Object
31 32 33 |
# File 'lib/shapes.rb', line 31 def to_solid Siren.solid self.to_shell end |
#to_wire(tol = 0.001) ⇒ Object
15 16 17 |
# File 'lib/shapes.rb', line 15 def to_wire(tol = 0.001) Siren.wire self, tol end |
#trans(t) ⇒ Object
83 84 85 |
# File 'lib/kernel/array.rb', line 83 def trans(t) t.move_point self end |
#trans!(t) ⇒ Object
87 88 89 90 |
# File 'lib/kernel/array.rb', line 87 def trans!(t) r = t.move_point self self.xyz = r.xyz end |
#translate(t) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/kernel/array.rb', line 38 def translate(t) if t.is_a? Siren::Vec v = t else v = t.to_v end (self.to_v + v).xyz end |
#translate!(t) ⇒ Object
47 48 49 |
# File 'lib/kernel/array.rb', line 47 def translate!(t) self.xyz = translate(t) end |
#vertices ⇒ Object
39 |
# File 'lib/shapes.rb', line 39 def vertices; self.map(&:vertices).flatten end |
#wires ⇒ Object
41 |
# File 'lib/shapes.rb', line 41 def wires; self.map(&:wires).flatten end |
#x ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/kernel/array.rb', line 92 def x val = (self[0] ||= 0.0) if val.is_a?(Float) val elsif val.is_a?(Numeric) val.to_f else 0.0 end end |
#x=(val) ⇒ Object
125 |
# File 'lib/kernel/array.rb', line 125 def x=(val); self[0] = val end |
#xyz ⇒ Object
18 19 20 |
# File 'lib/kernel/array.rb', line 18 def xyz self[0,3] end |
#xyz=(val) ⇒ Object
22 23 24 |
# File 'lib/kernel/array.rb', line 22 def xyz=(val) self[0,3] = val end |
#y ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/kernel/array.rb', line 103 def y val = (self[1] ||= 0.0) if val.is_a?(Float) val elsif val.is_a?(Numeric) val.to_f else 0.0 end end |
#y=(val) ⇒ Object
126 |
# File 'lib/kernel/array.rb', line 126 def y=(val); self[1] = val end |
#z ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/kernel/array.rb', line 114 def z val = (self[2] ||= 0.0) if val.is_a?(Float) val elsif val.is_a?(Numeric) val.to_f else 0.0 end end |
#z=(val) ⇒ Object
127 |
# File 'lib/kernel/array.rb', line 127 def z=(val); self[2] = val end |