From 5b54157bdeac06726ec200cace982e20d1e0cf81 Mon Sep 17 00:00:00 2001 From: Rohit Paul <113459757+RohitPaul12345@users.noreply.github.com> Date: Wed, 2 Aug 2023 17:35:26 +0530 Subject: [PATCH] Update frame.js --- lib/frame.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/frame.js b/lib/frame.js index bc3cda1..fb7f3e4 100644 --- a/lib/frame.js +++ b/lib/frame.js @@ -1,4 +1,4 @@ -var Hand = require("./hand") +let Hand = require("./hand") , Pointable = require("./pointable") , glMatrix = require("gl-matrix") , mat3 = glMatrix.mat3 @@ -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. * @@ -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); } @@ -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){ @@ -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)); } @@ -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); } @@ -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; } @@ -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:
"; out += this.toString(); out += "

Hands:
" - 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() + "
"; } out += "

Pointables:
"; - 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() + "
"; } out += "

Raw JSON:
";