Class: LittleWire::Nunchuck::NunchuckFrame::Vector3D
- Inherits:
-
Object
- Object
- LittleWire::Nunchuck::NunchuckFrame::Vector3D
- Defined in:
- lib/littlewire/gadgets/nunchuck.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Instance Method Summary collapse
-
#initialize(x = nil, y = nil, z = nil) ⇒ Vector3D
constructor
A new instance of Vector3D.
- #inspect ⇒ Object
- #to_a ⇒ Object
- #to_h ⇒ Object
- #to_hash ⇒ Object
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
#x ⇒ Object
Returns the value of attribute x.
73 74 75 |
# File 'lib/littlewire/gadgets/nunchuck.rb', line 73 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
73 74 75 |
# File 'lib/littlewire/gadgets/nunchuck.rb', line 73 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
73 74 75 |
# File 'lib/littlewire/gadgets/nunchuck.rb', line 73 def z @z end |
Instance Method Details
#inspect ⇒ Object
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_a ⇒ Object
74 |
# File 'lib/littlewire/gadgets/nunchuck.rb', line 74 def to_a; [@x,@y,@z].compact; end |
#to_h ⇒ Object
75 |
# File 'lib/littlewire/gadgets/nunchuck.rb', line 75 def to_h; {x: @x, y: @y, z: @z}; end |
#to_hash ⇒ Object
76 |
# File 'lib/littlewire/gadgets/nunchuck.rb', line 76 def to_hash; to_h; end |