Class: Moon::Vector4

Inherits:
Object show all
Includes:
Comparable, Serializable, Serializable::Properties
Defined in:
lib/moon/packages/std/vector4.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(data, depth = 0) ⇒ Moon::Vector4

Returns:


115
116
117
# File 'lib/moon/packages/std/vector4.rb', line 115

def self.load(data, depth = 0)
  new data['x'], data['y'], data['z'], data['w']
end

.zeroMoon::Vector4

Returns:


110
111
112
# File 'lib/moon/packages/std/vector4.rb', line 110

def self.zero
  new 0.0, 0.0, 0.0, 0.0
end

Instance Method Details

#<=>(other) ⇒ Object


21
22
23
# File 'lib/moon/packages/std/vector4.rb', line 21

def <=>(other)
  [x, y, z, w] <=> Vector4.extract(other)
end

#[](index) ⇒ Object


70
71
72
73
74
75
76
77
# File 'lib/moon/packages/std/vector4.rb', line 70

def [](index)
  case index
  when :x, 'x', 0 then x
  when :y, 'y', 1 then y
  when :z, 'z', 2 then z
  when :w, 'w', 3 then w
  end
end

#[]=(index, value) ⇒ Object


79
80
81
82
83
84
85
86
# File 'lib/moon/packages/std/vector4.rb', line 79

def []=(index, value)
  case index
  when :x, 'x', 0 then self.x = value
  when :y, 'y', 1 then self.y = value
  when :z, 'z', 2 then self.z = value
  when :w, 'w', 3 then self.w = value
  end
end

#absObject


100
101
102
# File 'lib/moon/packages/std/vector4.rb', line 100

def abs
  Vector4.new x.abs, y.abs, z.abs, w.abs
end

#ceilObject


96
97
98
# File 'lib/moon/packages/std/vector4.rb', line 96

def ceil
  Vector4.new x.ceil, y.ceil, z.ceil, w.ceil
end

#floorObject


92
93
94
# File 'lib/moon/packages/std/vector4.rb', line 92

def floor
  Vector4.new x.floor, y.floor, z.floor, w.floor
end

#near?(other, threshold) ⇒ Boolean

Returns:


104
105
106
107
# File 'lib/moon/packages/std/vector4.rb', line 104

def near?(other, threshold)
  diff = (self - other).abs
  (diff.x <= threshold.x && diff.y <= threshold.y && diff.z <= threshold.z && diff.w <= threshold.w)
end

#round(*a) ⇒ Object


88
89
90
# File 'lib/moon/packages/std/vector4.rb', line 88

def round(*a)
  Vector4.new x.round(*a), y.round(*a), z.round(*a), w.round(*a)
end

#sumFloat

Returns:


13
14
15
# File 'lib/moon/packages/std/vector4.rb', line 13

def sum
  x + y + z + w
end

#to_hObject


66
67
68
# File 'lib/moon/packages/std/vector4.rb', line 66

def to_h
  { x: x, y: y, z: z, w: w }
end

#to_sString

Returns:


62
63
64
# File 'lib/moon/packages/std/vector4.rb', line 62

def to_s
  "#{x}, #{y}, #{z}, #{w}"
end

#xyObject Also known as: to_vec2


25
26
27
# File 'lib/moon/packages/std/vector4.rb', line 25

def xy
  Vector2.new x, y
end

#xy=(other) ⇒ Object


29
30
31
# File 'lib/moon/packages/std/vector4.rb', line 29

def xy=(other)
  self.x, self.y = *Vector2.extract(other)
end

#xyzObject Also known as: to_vec3, rgb


41
42
43
# File 'lib/moon/packages/std/vector4.rb', line 41

def xyz
  Vector3.new x, y, z
end

#xyz=(other) ⇒ Object Also known as: rgb=


45
46
47
# File 'lib/moon/packages/std/vector4.rb', line 45

def xyz=(other)
  self.x, self.y, self.z = *Vector3.extract(other)
end

#xyzwObject Also known as: to_vec4, rgba


49
50
51
# File 'lib/moon/packages/std/vector4.rb', line 49

def xyzw
  dup
end

#xyzw=(other) ⇒ Object Also known as: rgba=


53
54
55
# File 'lib/moon/packages/std/vector4.rb', line 53

def xyzw=(other)
  self.x, self.y, self.z, self.w = *Vector4.extract(other)
end

#zero?Boolean

Returns:


17
18
19
# File 'lib/moon/packages/std/vector4.rb', line 17

def zero?
  x == 0 && y == 0 && z == 0 && w == 0
end

#zwObject


33
34
35
# File 'lib/moon/packages/std/vector4.rb', line 33

def zw
  Vector2.new z, w
end

#zw=(other) ⇒ Object


37
38
39
# File 'lib/moon/packages/std/vector4.rb', line 37

def zw=(other)
  self.z, self.w = *Vector2.extract(other)
end