Class: LittleWire::Nunchuck::NunchuckFrame::Vector3D

Inherits:
Object
  • Object
show all
Defined in:
lib/littlewire/gadgets/nunchuck.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x = nil, y = nil, z = nil) ⇒ Vector3D

Returns a new instance of Vector3D.



69
70
71
# File 'lib/littlewire/gadgets/nunchuck.rb', line 69

def initialize x=nil, y=nil, z=nil
  @x,@y,@z = x,y,z
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



73
74
75
# File 'lib/littlewire/gadgets/nunchuck.rb', line 73

def x
  @x
end

#yObject

Returns the value of attribute y.



73
74
75
# File 'lib/littlewire/gadgets/nunchuck.rb', line 73

def y
  @y
end

#zObject

Returns the value of attribute z.



73
74
75
# File 'lib/littlewire/gadgets/nunchuck.rb', line 73

def z
  @z
end

Instance Method Details

#inspectObject



77
78
79
80
81
82
# File 'lib/littlewire/gadgets/nunchuck.rb', line 77

def inspect
  precision = 2
  pretty = lambda { |n| (n >= 0 ? '+' : '-') + n.abs.round(precision).to_s.ljust(precision + 2, '0') }
  numbers = to_a.map { |n| pretty[n] }
  "<Coords:" + numbers.join(',') + ">"
end

#to_aObject



74
# File 'lib/littlewire/gadgets/nunchuck.rb', line 74

def to_a; [@x,@y,@z].compact; end

#to_hObject



75
# File 'lib/littlewire/gadgets/nunchuck.rb', line 75

def to_h; {x: @x, y: @y, z: @z}; end

#to_hashObject



76
# File 'lib/littlewire/gadgets/nunchuck.rb', line 76

def to_hash; to_h; end