Class: Mittsu::Vector2

Inherits:
Vector
  • Object
show all
Defined in:
lib/mittsu/math/vector2.rb

Constant Summary collapse

ELEMENTS =
{ x: 0, y: 1 }
DIMENSIONS =
ELEMENTS.count

Instance Attribute Summary

Attributes inherited from Vector

#elements, #index, #uv

Instance Method Summary collapse

Methods inherited from Vector

#==, #[], #[]=, #add, #add_scalar, #add_vectors, #angle_to, #ceil, #clamp, #clamp_scalar, #clone, #copy, #distance_to, #divide, #divide_scalar, #each_dimension, #floor, #from_array, #length, #length_sq, #lerp, #lerp_vectors, #max, #min, #multiply, #multiply_scalar, #multiply_vectors, #negate, #normalize, #project_on_plane, #project_on_vector, #reflect, #round, #round_to_zero, #set_length, #sub, #sub_scalar, #sub_vectors, #to_array, #to_s

Constructor Details

#initialize(x = 0, y = 0) ⇒ Vector2

Returns a new instance of Vector2.



8
9
10
# File 'lib/mittsu/math/vector2.rb', line 8

def initialize(x = 0, y = 0)
  super [x.to_f, y.to_f]
end

Instance Method Details

#distance_to_squared(v) ⇒ Object



26
27
28
29
# File 'lib/mittsu/math/vector2.rb', line 26

def distance_to_squared(v)
  dx, dy = x - v.x, y - v.y
  dx * dx + dy * dy
end

#dot(v) ⇒ Object



22
23
24
# File 'lib/mittsu/math/vector2.rb', line 22

def dot(v)
  x * v.x + y * v.y
end

#from_attribute(attribute, index, offset = 0) ⇒ Object



31
32
33
34
35
36
# File 'lib/mittsu/math/vector2.rb', line 31

def from_attribute(attribute, index, offset = 0)
  index = index * attribute.item_size + offset
  @elements[0] = attribute.array[index]
  @elements[1] = attribute.array[index + 1]
  self
end

#set(x, y) ⇒ Object



12
13
14
# File 'lib/mittsu/math/vector2.rb', line 12

def set(x, y)
  super [x.to_f, y.to_f]
end

#xObject



16
# File 'lib/mittsu/math/vector2.rb', line 16

def x; @elements[0]; end

#x=(value) ⇒ Object



19
# File 'lib/mittsu/math/vector2.rb', line 19

def x=(value); @elements[0] = value.to_f; end

#yObject



17
# File 'lib/mittsu/math/vector2.rb', line 17

def y; @elements[1]; end

#y=(value) ⇒ Object



20
# File 'lib/mittsu/math/vector2.rb', line 20

def y=(value); @elements[1] = value.to_f; end