Module: Vector2d::Properties

Includes:
Contracts
Included in:
Vector2d
Defined in:
lib/vector2d/properties.rb

Instance Method Summary collapse

Instance Method Details

#angleObject



12
13
14
# File 'lib/vector2d/properties.rb', line 12

def angle
  Math.atan2(y, x)
end

#aspect_ratioObject



21
22
23
# File 'lib/vector2d/properties.rb', line 21

def aspect_ratio
  (x.to_f / y.to_f).abs
end

#lengthObject



30
31
32
# File 'lib/vector2d/properties.rb', line 30

def length
  Math.sqrt(squared_length)
end

#normalized?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/vector2d/properties.rb', line 49

def normalized?
  self.length.to_f == 1.0
end

#squared_lengthObject



39
40
41
# File 'lib/vector2d/properties.rb', line 39

def squared_length
  x * x + y * y
end