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 frame.js #309

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
36 changes: 18 additions & 18 deletions lib/frame.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Hand = require("./hand")
let Hand = require("./hand")
, Pointable = require("./pointable")
, glMatrix = require("gl-matrix")
, mat3 = glMatrix.mat3
Expand All @@ -24,7 +24,7 @@ var Hand = require("./hand")
*
* Access Frame objects using the [Controller.frame]{@link Leap.Controller#frame}() function.
*/
var Frame = module.exports = function(data) {
let Frame = module.exports = function(data) {
/**
* Reports whether this Frame instance is valid.
*
Expand Down Expand Up @@ -123,22 +123,22 @@ Frame.prototype.postprocessData = function(data){
data = this.data;
}

for (var handIdx = 0, handCount = data.hands.length; handIdx != handCount; handIdx++) {
var hand = new Hand(data.hands[handIdx]);
for (let handIdx = 0, handCount = data.hands.length; handIdx != handCount; handIdx++) {
let hand = new Hand(data.hands[handIdx]);
hand.frame = this;
this.hands.push(hand);
this.handsMap[hand.id] = hand;
}

var sortBy = function(key) {
let sortBy = function(key) {
return function (a, b) { return (a[key] > b[key]) ? 1 : ((b[key] > a[key]) ? -1 : 0) };
};

data.pointables.sort(sortBy("id"));

for (var pointableIdx = 0, pointableCount = data.pointables.length; pointableIdx != pointableCount; pointableIdx++) {
var pointableData = data.pointables[pointableIdx];
var pointable = pointableData.dipPosition ? new Finger(pointableData) : new Pointable(pointableData);
for (let pointableIdx = 0, pointableCount = data.pointables.length; pointableIdx != pointableCount; pointableIdx++) {
let pointableData = data.pointables[pointableIdx];
let pointable = pointableData.dipPosition ? new Finger(pointableData) : new Pointable(pointableData);
pointable.frame = this;
this.addPointable(pointable);
}
Expand All @@ -156,7 +156,7 @@ Frame.prototype.addPointable = function (pointable) {
this.pointablesMap[pointable.id] = pointable;
(this.fingers).push(pointable);
if (pointable.handId !== undefined && this.handsMap.hasOwnProperty(pointable.handId)) {
var hand = this.handsMap[pointable.handId];
let hand = this.handsMap[pointable.handId];
hand.pointables.push(pointable);
(hand.fingers).push(pointable);
switch (pointable.type){
Expand Down Expand Up @@ -274,13 +274,13 @@ Frame.prototype.hand = function(id) {
Frame.prototype.rotationAngle = function(sinceFrame, axis) {
if (!this.valid || !sinceFrame.valid) return 0.0;

var rot = this.rotationMatrix(sinceFrame);
var cs = (rot[0] + rot[4] + rot[8] - 1.0)*0.5;
var angle = Math.acos(cs);
let rot = this.rotationMatrix(sinceFrame);
let cs = (rot[0] + rot[4] + rot[8] - 1.0)*0.5;
let angle = Math.acos(cs);
angle = isNaN(angle) ? 0.0 : angle;

if (axis !== undefined) {
var rotAxis = this.rotationAxis(sinceFrame);
let rotAxis = this.rotationAxis(sinceFrame);
angle *= vec3.dot(rotAxis, vec3.normalize(vec3.create(), axis));
}

Expand Down Expand Up @@ -332,7 +332,7 @@ Frame.prototype.rotationAxis = function(sinceFrame) {
*/
Frame.prototype.rotationMatrix = function(sinceFrame) {
if (!this.valid || !sinceFrame.valid) return mat3.create();
var transpose = mat3.transpose(mat3.create(), this._rotation)
let transpose = mat3.transpose(mat3.create(), this._rotation)
return mat3.multiply(mat3.create(), sinceFrame._rotation, transpose);
}

Expand Down Expand Up @@ -390,7 +390,7 @@ Frame.prototype.translation = function(sinceFrame) {
* @returns {String} A brief description of this frame.
*/
Frame.prototype.toString = function() {
var str = "Frame [ id:"+this.id+" | timestamp:"+this.timestamp+" | Hand count:("+this.hands.length+") | Pointable count:("+this.pointables.length+")";
let str = "Frame [ id:"+this.id+" | timestamp:"+this.timestamp+" | Hand count:("+this.hands.length+") | Pointable count:("+this.pointables.length+")";
str += " ]";
return str;
}
Expand All @@ -404,15 +404,15 @@ Frame.prototype.toString = function() {
* @returns {String} A JSON-formatted string.
*/
Frame.prototype.dump = function() {
var out = '';
let out = '';
out += "Frame Info:<br/>";
out += this.toString();
out += "<br/><br/>Hands:<br/>"
for (var handIdx = 0, handCount = this.hands.length; handIdx != handCount; handIdx++) {
for (let handIdx = 0, handCount = this.hands.length; handIdx != handCount; handIdx++) {
out += " "+ this.hands[handIdx].toString() + "<br/>";
}
out += "<br/><br/>Pointables:<br/>";
for (var pointableIdx = 0, pointableCount = this.pointables.length; pointableIdx != pointableCount; pointableIdx++) {
for (let pointableIdx = 0, pointableCount = this.pointables.length; pointableIdx != pointableCount; pointableIdx++) {
out += " "+ this.pointables[pointableIdx].toString() + "<br/>";
}
out += "<br/><br/>Raw JSON:<br/>";
Expand Down