Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/shapes.rb,
lib/kernel/array.rb

Overview

Array クラス拡張メソッド

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.originObject



129
130
131
# File 'lib/kernel/array.rb', line 129

def self.origin
  [0, 0, 0]
end

Instance Method Details

#bndboxObject

Raises:

  • (NotImplementedError)


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

#compoundsObject



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

#edgesObject



40
# File 'lib/shapes.rb', line 40

def edges;      self.map(&:edges).flatten      end

#equal?(other, lintol) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/kernel/array.rb', line 34

def equal?(other, lintol)
  dist(other) < lintol
end

#facesObject



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

#shellsObject



43
# File 'lib/shapes.rb', line 43

def shells;     self.map(&:shells).flatten     end

#solidsObject



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_compObject



35
36
37
# File 'lib/shapes.rb', line 35

def to_comp
  Siren::Compound.new self
end

#to_loftObject

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/shapes.rb', line 19

def to_loft
  raise NotImplementedError
end

#to_polygonObject



11
12
13
# File 'lib/shapes.rb', line 11

def to_polygon
  Siren.polygon self
end

#to_polylineObject



7
8
9
# File 'lib/shapes.rb', line 7

def to_polyline
  Siren.polyline self
end

#to_revolObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/shapes.rb', line 23

def to_revol
  raise NotImplementedError
end

#to_shellObject



27
28
29
# File 'lib/shapes.rb', line 27

def to_shell
  Siren.shell self
end

#to_solidObject



31
32
33
# File 'lib/shapes.rb', line 31

def to_solid
  Siren.solid self.to_shell
end

#to_vObject



6
7
8
# File 'lib/kernel/array.rb', line 6

def to_v
  Siren::Vec.new self
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

#verticesObject



39
# File 'lib/shapes.rb', line 39

def vertices;   self.map(&:vertices).flatten   end

#wiresObject



41
# File 'lib/shapes.rb', line 41

def wires;      self.map(&:wires).flatten      end

#xObject



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

#xyzObject



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

#yObject



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

#zObject



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