Class: CGLM::VectorType

Inherits:
Base
  • Object
show all
Defined in:
lib/cglm/vector_type.rb,
ext/cglm/rb_cglm.c

Direct Known Subclasses

Vec3, Vec4

Instance Attribute Summary

Attributes inherited from Base

#addr

Instance Method Summary collapse

Methods inherited from Base

#copy_to, #dup, #initialize_dup

Constructor Details

#initialize(initial = nil, **args) ⇒ VectorType

Returns a new instance of VectorType.



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cglm/vector_type.rb', line 3

def initialize(initial = nil, **args)
  super(**args)
  case initial
  when Array
    initial.each_with_index { |v, i| self[i] = v; break if i >= 3 }
  when Quat, Vec3, Vec4
    size = initial.class.size > self.class.size ? self.class.size : initial.class.size
    addr[0, size] = initial.addr[0, size]
  when nil
  else
    raise ArgumentError, 'initial values must be an Array, Quat, Vec3 or Vec4'
  end
end

Instance Method Details

#each(&block) ⇒ Object



24
25
26
# File 'lib/cglm/vector_type.rb', line 24

def each(&block)
  to_enum.each(&block)
end

#to_aObject



28
29
30
# File 'lib/cglm/vector_type.rb', line 28

def to_a
  to_enum.to_a
end

#to_enumObject



17
18
19
20
21
22
# File 'lib/cglm/vector_type.rb', line 17

def to_enum
  size = self.size
  Enumerator.new(size) do |y|
    size.times { |i| y << self[i] }
  end
end