Best JavaScript code snippet using wpt
panner-formulas.js
Source:panner-formulas.js
...57 cross[2] = u[0] * v[1] - u[1] * v[0];58 return cross;59}60// Dot product61function vec3Dot(x, y) {62 return x[0] * y[0] + x[1] * y[1] + x[2] * y[2];63}64// a*x, for scalar a65function vec3Scale(a, x) {66 return x.map(function(c) {67 return a * c;68 });69}70function calculateAzimuth(source, listener, listenerForward, listenerUp) {71 let sourceListener = vec3Sub(source, listener);72 if (vec3IsZero(sourceListener))73 return 0;74 sourceListener = vec3Normalize(sourceListener);75 let listenerRight = vec3Normalize(vec3Cross(listenerForward, listenerUp));76 let listenerForwardNorm = vec3Normalize(listenerForward);77 let up = vec3Cross(listenerRight, listenerForwardNorm);78 let upProjection = vec3Dot(sourceListener, up);79 let projectedSource =80 vec3Normalize(vec3Sub(sourceListener, vec3Scale(upProjection, up)));81 let azimuth =82 180 / Math.PI * Math.acos(vec3Dot(projectedSource, listenerRight));83 // Source in front or behind the listener84 let frontBack = vec3Dot(projectedSource, listenerForwardNorm);85 if (frontBack < 0)86 azimuth = 360 - azimuth;87 // Make azimuth relative to "front" and not "right" listener vector.88 if (azimuth >= 0 && azimuth <= 270)89 azimuth = 90 - azimuth;90 else91 azimuth = 450 - azimuth;92 // We don't need elevation, so we're skipping that computation.93 return azimuth;94}95// Map our position angle to the azimuth angle (in degrees).96//97// An angle of 0 corresponds to an azimuth of 90 deg; pi, to -90 deg.98function angleToAzimuth(angle) {...
jac2.js
Source:jac2.js
1import { vec3, mat2 } from 'math';2const vec3dot = vec3.dot;3const tmp1 = new Float32Array(3);4export default class Jac2 {5 v11 = new Float32Array(3);6 w11 = new Float32Array(3);7 v21 = new Float32Array(3);8 w21 = new Float32Array(3);9 v11a = new Float32Array(3);10 w11a = new Float32Array(3);11 v21a = new Float32Array(3);12 w21a = new Float32Array(3);13 v12 = new Float32Array(3);14 w12 = new Float32Array(3);15 v22 = new Float32Array(3);16 w22 = new Float32Array(3);17 v12a = new Float32Array(3);18 w12a = new Float32Array(3);19 v22a = new Float32Array(3);20 w22a = new Float32Array(3);21 mass = new Float32Array(4);22 constructor(body1, body2) {23 this.body1 = body1;24 this.body2 = body2;25 }26 apply(t1, t2) {27 const v1 = this.body1.velocity, w1 = this.body1.angVelocity,28 v2 = this.body2.velocity, w2 = this.body2.angVelocity;29 const v11a = this.v11a, w11a = this.w11a, v21a = this.v21a, w21a = this.w21a,30 v12a = this.v12a, w12a = this.w12a, v22a = this.v22a, w22a = this.w22a;31 v1[0] += v11a[0] * t1 + v12a[0] * t2; v1[1] += v11a[1] * t1 + v12a[1] * t2; v1[2] += v11a[2] * t1 + v12a[2] * t2;32 w1[0] += w11a[0] * t1 + w12a[0] * t2; w1[1] += w11a[1] * t1 + w12a[1] * t2; w1[2] += w11a[2] * t1 + w12a[2] * t2;33 v2[0] += v21a[0] * t1 + v22a[0] * t2; v2[1] += v21a[1] * t1 + v22a[1] * t2; v2[2] += v21a[2] * t1 + v22a[2] * t2;34 w2[0] += w21a[0] * t1 + w22a[0] * t2; w2[1] += w21a[1] * t1 + w22a[1] * t2; w2[2] += w21a[2] * t1 + w22a[2] * t2;35 }36 force(out) {37 vec3.scale(out, this.v11a, this.lambda1 * this.body1.mass);38 vec3.scaleAndAdd(out, out, this.v12a, this.lambda2 * this.body1.mass);39 }40 linear(pos1, pos2, axis1, axis2) {41 vec3.copy(this.v11, axis1);42 vec3.copy(this.v12, axis2);43 vec3.subtract(tmp1, pos1, this.body1.position);44 vec3.cross(this.w11, tmp1, axis1);45 vec3.cross(this.w12, tmp1, axis2);46 vec3.negate(this.v21, axis1);47 vec3.negate(this.v22, axis2);48 vec3.subtract(tmp1, pos2, this.body2.position);49 vec3.cross(this.w21, axis1, tmp1);50 vec3.cross(this.w22, axis2, tmp1);51 vec3.transformMat3(this.v11a, this.v11, this.body1.invMass);52 vec3.transformMat3(this.v12a, this.v12, this.body1.invMass);53 vec3.transformMat3(this.w11a, this.w11, this.body1.invInertia);54 vec3.transformMat3(this.w12a, this.w12, this.body1.invInertia);55 vec3.transformMat3(this.v21a, this.v21, this.body2.invMass);56 vec3.transformMat3(this.v22a, this.v22, this.body2.invMass);57 vec3.transformMat3(this.w21a, this.w21, this.body2.invInertia);58 vec3.transformMat3(this.w22a, this.w22, this.body2.invInertia);59 this.mass[0] = vec3dot(this.v11a, this.v11) + vec3dot(this.w11a, this.w11) +60 vec3dot(this.v21a, this.v21) + vec3dot(this.w21a, this.w21);61 this.mass[1] = vec3dot(this.v11a, this.v12) + vec3dot(this.w11a, this.w12) +62 vec3dot(this.v21a, this.v22) + vec3dot(this.w21a, this.w22);63 this.mass[2] = vec3dot(this.v12a, this.v11) + vec3dot(this.w12a, this.w11) +64 vec3dot(this.v22a, this.v21) + vec3dot(this.w22a, this.w21);65 this.mass[3] = vec3dot(this.v12a, this.v12) + vec3dot(this.w12a, this.w12) +66 vec3dot(this.v22a, this.v22) + vec3dot(this.w22a, this.w22);67 mat2.invert(this.mass, this.mass);68 if (this.lambda1 !== undefined) {69 this.apply(this.lambda1, this.lambda2);70 } else {71 this.lambda1 = 0;72 this.lambda2 = 0;73 }74 }75 resolve(limit) {76 const c1 = vec3dot(this.v11, this.body1.velocity) + vec3dot(this.w11, this.body1.angVelocity) +77 vec3dot(this.v21, this.body2.velocity) + vec3dot(this.w21, this.body2.angVelocity);78 const c2 = vec3dot(this.v12, this.body1.velocity) + vec3dot(this.w12, this.body1.angVelocity) +79 vec3dot(this.v22, this.body2.velocity) + vec3dot(this.w22, this.body2.angVelocity);80 const prev1 = this.lambda1, prev2 = this.lambda2;81 this.lambda1 -= this.mass[0] * c1 + this.mass[1] * c2;82 this.lambda2 -= this.mass[2] * c1 + this.mass[3] * c2;83 let len = Math.sqrt(this.lambda1 * this.lambda1 + this.lambda2 * this.lambda2);84 if (len > 1e-4 && len > limit) {85 len = limit / len;86 this.lambda1 *= len;87 this.lambda2 *= len;88 }89 this.apply(this.lambda1 - prev1, this.lambda2 - prev2);90 }...
jac1.js
Source:jac1.js
1import { vec3 } from 'math';2const vec3dot = vec3.dot;3const tmp1 = new Float32Array(3);4export default class Jac1 {5 v1 = new Float32Array(3);6 w1 = new Float32Array(3);7 v2 = new Float32Array(3);8 w2 = new Float32Array(3);9 v1a = new Float32Array(3);10 w1a = new Float32Array(3);11 v2a = new Float32Array(3);12 w2a = new Float32Array(3);13 bias = 0;14 restitution = 0;15 lower = -1e+9;16 upper = 1e+9;17 ok = true;18 constructor(body1, body2) {19 this.body1 = body1;20 this.body2 = body2;21 }22 apply(t) {23 //t *= 1 + this.restitution;24 const v1 = this.body1.velocity, w1 = this.body1.angVelocity,25 v2 = this.body2.velocity, w2 = this.body2.angVelocity;26 const v1a = this.v1a, w1a = this.w1a, v2a = this.v2a, w2a = this.w2a;27 v1[0] += v1a[0] * t; v1[1] += v1a[1] * t; v1[2] += v1a[2] * t;28 w1[0] += w1a[0] * t; w1[1] += w1a[1] * t; w1[2] += w1a[2] * t;29 v2[0] += v2a[0] * t; v2[1] += v2a[1] * t; v2[2] += v2a[2] * t;30 w2[0] += w2a[0] * t; w2[1] += w2a[1] * t; w2[2] += w2a[2] * t;31 }32 force(out) {33 vec3.scale(out, this.v1a, this.lambda * this.body1.mass);34 }35 linear(pos1, pos2, axis) {36 vec3.copy(this.v1, axis);37 vec3.subtract(tmp1, pos1, this.body1.position);38 vec3.cross(this.w1, tmp1, axis);39 vec3.negate(this.v2, axis);40 vec3.subtract(tmp1, pos2, this.body2.position);41 vec3.cross(this.w2, axis, tmp1);42 vec3.transformMat3(this.v1a, this.v1, this.body1.invMass);43 vec3.transformMat3(this.w1a, this.w1, this.body1.invInertia);44 vec3.transformMat3(this.v2a, this.v2, this.body2.invMass);45 vec3.transformMat3(this.w2a, this.w2, this.body2.invInertia);46 const invMass = vec3dot(this.v1a, this.v1) + vec3dot(this.w1a, this.w1) + vec3dot(this.v2a, this.v2) + vec3dot(this.w2a, this.w2);47 if (invMass < 1e-6) {48 this.ok = false;49 }50 this.mass = 1.0 / invMass;51 if (this.lambda !== undefined) {52 this.apply(this.lambda);53 } else {54 this.lambda = 0;55 }56 }57 angular(axis) {58 vec3.copy(this.w1, axis);59 vec3.negate(this.w2, axis);60 vec3.transformMat3(this.w1a, this.w1, this.body1.invInertia);61 vec3.transformMat3(this.w2a, this.w2, this.body2.invInertia);62 this.mass = 1 / (vec3dot(this.w1a, this.w1) + vec3dot(this.w2a, this.w2));63 if (this.lambda !== undefined) {64 this.apply(this.lambda);65 } else {66 this.lambda = 0;67 }68 }69 resolve() {70 if (!this.ok) {71 return;72 }73 const jv = vec3dot(this.v1, this.body1.velocity) + vec3dot(this.w1, this.body1.angVelocity) +74 vec3dot(this.v2, this.body2.velocity) + vec3dot(this.w2, this.body2.angVelocity);75 const c = jv/* - Math.max(0, -jv * this.restitution)*/ + this.bias;76 const prev = this.lambda;77 this.lambda -= this.mass * c;78 if (this.lambda < this.lower) this.lambda = this.lower;79 if (this.lambda > this.upper) this.lambda = this.upper;80 this.apply(this.lambda - prev);81 }...
Using AI Code Generation
1var wptools = require('wptools');2var vec3Dot = wptools.vec3Dot;3var v1 = [1, 2, 3];4var v2 = [4, 5, 6];5var wptools = require('wptools');6var vec3Cross = wptools.vec3Cross;7var v1 = [1, 2, 3];8var v2 = [4, 5, 6];9var wptools = require('wptools');10var vec3Norm = wptools.vec3Norm;11var v1 = [1, 2, 3];12var wptools = require('wptools');13var vec3Normalize = wptools.vec3Normalize;14var v1 = [1, 2, 3];15var wptools = require('wptools');16var vec3Angle = wptools.vec3Angle;17var v1 = [1, 2, 3];18var v2 = [4, 5, 6];19var wptools = require('wptools');20var vec3Rotate = wptools.vec3Rotate;21var v1 = [1, 2, 3];22var v2 = [4, 5, 6];23var angle = 0.2257261285527342;24console.log(vec3Rotate
Using AI Code Generation
1var wpt = require('./wpt.js');2var v1 = new wpt.vec3(1,2,3);3var v2 = new wpt.vec3(4,5,6);4console.log(wpt.vec3Dot(v1, v2));5var vec3 = function(x,y,z){6 this.x = x;7 this.y = y;8 this.z = z;9};10vec3.prototype = {11 dot: function(v){12 return this.x*v.x + this.y*v.y + this.z*v.z;13 }14};15module.exports = {16 vec3Dot: function(v1,v2){17 return v1.dot(v2);18 }19};20var wpt = require('./wpt.js');21var v1 = new wpt.vec3(1,2,3);22var v2 = new wpt.vec3(4,5,6);23console.log(wpt.vec3Cross(v1, v2));24var vec3 = function(x,y,z){25 this.x = x;26 this.y = y;27 this.z = z;28};29vec3.prototype = {30 dot: function(v){31 return this.x*v.x + this.y*v.y + this.z*v.z;32 },33 cross: function(v){34 return new vec3(35 );36 }37};38module.exports = {39 vec3Dot: function(v1,v2){40 return v1.dot(v2);41 },42 vec3Cross: function(v1,v2){43 return v1.cross(v2);44 }45};46 at Object.exports.vec3Cross (/Users/brad/Programming/Node/wpt.js:20:7)47 at Object.<anonymous> (/Users/brad/Programming/Node/test.js:8:16)48 at Module._compile (
Using AI Code Generation
1var wpt = require('./wpt.js');2var vec3Dot = wpt.vec3Dot;3var v1 = [1, 2, 3];4var v2 = [4, 5, 6];5var result = vec3Dot(v1, v2);6console.log(result);7module.exports = {8 vec3Dot: function (v1, v2) {9 var result = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];10 return result;11 }12};
Using AI Code Generation
1var wptools = require("wptools");2var v1 = [1,2,3];3var v2 = [4,5,6];4var dotProduct = wptools.vec3Dot(v1,v2);5console.log(dotProduct);6var wptools = require("wptools");7var v1 = [1,2,3];8var v2 = [4,5,6];9var crossProduct = wptools.vec3Cross(v1,v2);10console.log(crossProduct);11var wptools = require("wptools");12var v1 = [1,2,3];13var v2 = [4,5,6];14var sum = wptools.vec3Add(v1,v2);15console.log(sum);16var wptools = require("wptools");17var v1 = [1,2,3];18var v2 = [4,5,6];19var difference = wptools.vec3Sub(v1,v2);20console.log(difference);21var wptools = require("wptools");22var v = [1,2,3];23var s = 4;24var product = wptools.vec3Mult(v,s);25console.log(product);26var wptools = require("wptools");27var v = [4,8,12];28var s = 4;29var quotient = wptools.vec3Div(v,s);30console.log(quotient);31var wptools = require("wptools");32var v = [1,2,3];
Using AI Code Generation
1var wpt = require('wpt');2var vec3Dot = wpt.vec3Dot;3var v1 = [1, 2, 3];4var v2 = [4, 5, 6];5var wpt = require('wpt');6var vec3Dot = wpt.vec3Dot;7var v1 = [1, 2, 3];8var v2 = [4, 5, 6];9var wpt = require('wpt');10var vec3Dot = wpt.vec3Dot;11var v1 = [1, 2, 3];12var v2 = [4, 5, 6];13var wpt = require('wpt');14var vec3Dot = wpt.vec3Dot;15var v1 = [1, 2, 3];16var v2 = [4, 5, 6];17var wpt = require('wpt');18var vec3Dot = wpt.vec3Dot;19var v1 = [1, 2, 3];20var v2 = [4, 5, 6];21var wpt = require('wpt');22var vec3Dot = wpt.vec3Dot;23var v1 = [1, 2, 3];24var v2 = [4, 5, 6];25var wpt = require('wpt');26var vec3Dot = wpt.vec3Dot;27var v1 = [1, 2, 3];28var v2 = [4, 5, 6];29var dot = vec3Dot(v1
Using AI Code Generation
1var wpt = require('wpt');2var vec3Dot = wpt.vec3Dot;3var vec = [1,2,3];4var vec2 = [4,5,6];5var dot = vec3Dot(vec, vec2);6console.log(dot);7 var vec = [1,2,3];8 var vec2 = [4,5,6];9 var dot = wpt.vec3Dot(vec, vec2);10 console.log(dot);
Using AI Code Generation
1var wptools = require('wptools');2var vec3 = wptools.vec3;3var vec3Dot = vec3.dot;4var v1 = vec3(1,2,3);5var v2 = vec3(1,2,3);6var dot = vec3Dot(v1,v2);7console.log(dot);8var vec3 = require('wptools').vec3;9var vec3Dot = vec3.dot;10var v1 = vec3(1,2,3);11var v2 = vec3(1,2,3);12var dot = vec3Dot(v1,v2);13console.log(dot);14var vec3 = require('wptools').vec3;15var v1 = vec3(1,2,3);16var v2 = vec3(1,2,3);17var dot = vec3.dot(v1,v2);18console.log(dot);19var vec3 = require('wptools').vec3;20var v1 = vec3(1,2,3);21var v2 = vec3(1,2,3);22var dot = vec3.dot(v1,v2);23console.log(dot);24var vec3 = require('wptools').vec3;25var v1 = vec3(1,2,3);26var v2 = vec3(1,2,3);27var dot = vec3.dot(v1,v2);28console.log(dot);29var vec3 = require('wptools').vec3;30var v1 = vec3(1,2,3);31var v2 = vec3(1,2,3);32var dot = vec3.dot(v1,v2);33console.log(dot);34var vec3 = require('wptools').vec3;35var v1 = vec3(1,2,3);36var v2 = vec3(1,2,3);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!