Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hand.js #295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions test/hand.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
describe('Hand', function(){
describe("an instance", function() {
var data = fakeFrame({fingers: 5, hands:1})
var frame = createFrame(data);
var hand = frame.hands[0];
let data = fakeFrame({fingers: 5, hands:1})
let frame = createFrame(data);
let hand = frame.hands[0];

describe("properties", function() {
it('should have palmPosition', function() { assert(hand.palmPosition) })
Expand Down Expand Up @@ -32,8 +32,8 @@ describe('Hand', function(){


it('should return fingers ordered by id', function(){
var hand = fakeActualFrame().hands[0];
for (var i = 1; i < hand.fingers.length; i++){
let hand = fakeActualFrame().hands[0];
for (let i = 1; i < hand.fingers.length; i++){
assert(hand.fingers[i].id > hand.fingers[i-1].id,
"Fingers to be in sequential order. Got '" + hand.fingers[i].id + ', ' + hand.fingers[i-1].id + "'");
}
Expand All @@ -42,54 +42,54 @@ describe('Hand', function(){

describe("#rotationAngle", function() {
it('should work', function() {
var frame1 = createFrame(data);
let frame1 = createFrame(data);
frame1.hand(0)._rotation = [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0];
var frame2 = createFrame(data);
let frame2 = createFrame(data);
frame2.hand(0)._rotation = [1.0,0.0,0.0,0.0,1.0,0.0,0.5,0.0,0.5];
var result = frame2.hand(0).rotationAngle(frame1);
let result = frame2.hand(0).rotationAngle(frame1);
assert.closeTo(0.72273, result, 0.0001)
})
})
});

describe('#translation()', function(){
it('should return the translation', function(){
var data1 = fakeFrame({handData: [fakeHand({translation: [1, 2, 3]})]})
var frame1 = createFrame(data1);
var data2 = fakeFrame({handData: [fakeHand({translation: [3, 1, 5]})]})
var frame2 = createFrame(data2);
let data1 = fakeFrame({handData: [fakeHand({translation: [1, 2, 3]})]})
let frame1 = createFrame(data1);
let data2 = fakeFrame({handData: [fakeHand({translation: [3, 1, 5]})]})
let frame2 = createFrame(data2);
assert.deepEqual([-2, 1, -2], frame1.hand(0).translation(frame2))
})
})

describe('#rotationAxis()', function(){
it('should return the rotationAxis', function(){
var data1 = fakeFrame({handData: [fakeHand({rotation: [[0,1,2], [2,3,4], [2,3,4]]})]})
var frame1 = createFrame(data1);
var data2 = fakeFrame({handData: [fakeHand({rotation: [[0,4,5], [1,3,7], [5,4,2]]})]})
var frame2 = createFrame(data2);
var result = frame1.hand(0).rotationAxis(frame2);
let data1 = fakeFrame({handData: [fakeHand({rotation: [[0,1,2], [2,3,4], [2,3,4]]})]})
let frame1 = createFrame(data1);
let data2 = fakeFrame({handData: [fakeHand({rotation: [[0,4,5], [1,3,7], [5,4,2]]})]})
let frame2 = createFrame(data2);
let result = frame1.hand(0).rotationAxis(frame2);
assertUtil.vectorCloseTo([-0.74278, -0.55708,-0.37139], result, 0.0001, 'rotation axis');
})

it('should return a null vector if the hand is invalid', function(){
var data1 = fakeFrame({handData: [fakeHand({rotation: [[0,4,5], [1,3,7], [5,4,2]]})]})
var frame1 = createFrame(data1);
var data2 = fakeFrame({handData: []})
var frame2 = createFrame(data2);
var result = frame1.hand(0).rotationAxis(frame2);
let data1 = fakeFrame({handData: [fakeHand({rotation: [[0,4,5], [1,3,7], [5,4,2]]})]})
let frame1 = createFrame(data1);
let data2 = fakeFrame({handData: []})
let frame2 = createFrame(data2);
let result = frame1.hand(0).rotationAxis(frame2);
assert(!frame2.hand(0).valid);
assertUtil.vectorCloseTo(result, Leap.vec3.create(), 0.0001, 'result is zero vector');
});
})

describe('#rotationAngle()', function(){
it('should return the rotationAngle', function(){
var data1 = fakeFrame({handData: [fakeHand({rotation: [[1,0,0], [0,1,0], [0,0,1]]})]})
var frame1 = createFrame(data1);
var data2 = fakeFrame({handData: [fakeHand({rotation: [[1,0,0], [0,1,0], [0.5,0,0.5]]})]})
var frame2 = createFrame(data2);
var result = frame1.hand(0).rotationAngle(frame2);
let data1 = fakeFrame({handData: [fakeHand({rotation: [[1,0,0], [0,1,0], [0,0,1]]})]})
let frame1 = createFrame(data1);
let data2 = fakeFrame({handData: [fakeHand({rotation: [[1,0,0], [0,1,0], [0.5,0,0.5]]})]})
let frame2 = createFrame(data2);
let result = frame1.hand(0).rotationAngle(frame2);
assert.closeTo(0.72273, result, 0.0001)
})
})
Expand Down