@any-touch/compute
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,12 +0,5 @@ | ||
/** | ||
* 计算xy形成的夹角 | ||
* @param x x轴值 | ||
* @param y y轴值 | ||
* @returns xy形成的夹角 | ||
*/ | ||
export declare function getXYAngle(x?: number, y?: number): number; | ||
declare function ComputeDeltaXY(): (input: any) => { | ||
deltaX: number; | ||
deltaY: number; | ||
getXYAngle: (x: number, y: number) => number; | ||
deltaXYAngle: number; | ||
}; | ||
@@ -13,0 +6,0 @@ declare namespace ComputeDeltaXY { |
@@ -1,3 +0,2 @@ | ||
import type { DIRECTION } from '@any-touch/shared'; | ||
import { getDirection } from '@any-touch/vector'; | ||
import type { directionString } from '@any-touch/shared'; | ||
declare function ComputeDistance(): (input: any) => { | ||
@@ -9,3 +8,3 @@ displacementX: number; | ||
distance: number; | ||
getDirection: (x: number, y: number) => DIRECTION | void; | ||
overallDirection: any; | ||
}; | ||
@@ -12,0 +11,0 @@ declare namespace ComputeDistance { |
@@ -1,2 +0,2 @@ | ||
import { DIRECTION } from '@any-touch/shared'; | ||
import type { directionString } from '@any-touch/shared'; | ||
declare function ComputeVAndDir(): (input: any) => { | ||
@@ -3,0 +3,0 @@ speedX: number; |
import { getAngle, radianToAngle, getVLength, getDirection } from '@any-touch/vector'; | ||
import { CLIENT_X, CLIENT_Y, STAGE, round2, COMPUTE_INTERVAL } from '@any-touch/shared'; | ||
import { CLIENT_X, CLIENT_Y, INPUT_START, INPUT_MOVE, NONE, round2, COMPUTE_INTERVAL } from '@any-touch/shared'; | ||
@@ -38,13 +38,2 @@ function computeVector(input) { | ||
function getXYAngle(x, y) { | ||
if (x === void 0) { x = 0; } | ||
if (y === void 0) { y = 0; } | ||
if (0 === x) { | ||
return 0; | ||
} | ||
else { | ||
var deltaXY = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); | ||
return Math.round(radianToAngle(Math.acos(Math.abs(x) / deltaXY))); | ||
} | ||
} | ||
function ComputeDeltaXY() { | ||
@@ -55,7 +44,12 @@ return function (input) { | ||
var deltaY = 0; | ||
var deltaXYAngle = 0; | ||
if (void 0 !== prevInput) { | ||
deltaX = input.x - prevInput.x; | ||
deltaY = input.y - prevInput.y; | ||
if (0 !== deltaX || 0 !== deltaY) { | ||
var deltaXY = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)); | ||
deltaXYAngle = Math.round(radianToAngle(Math.acos(Math.abs(deltaX) / deltaXY))); | ||
} | ||
} | ||
return { deltaX: deltaX, deltaY: deltaY, getXYAngle: getXYAngle }; | ||
return { deltaX: deltaX, deltaY: deltaY, deltaXYAngle: deltaXYAngle }; | ||
}; | ||
@@ -71,5 +65,6 @@ } | ||
var distance = 0; | ||
var overallDirection = NONE; | ||
return function (input) { | ||
var stage = input.stage, startInput = input.startInput; | ||
if (STAGE.START === stage) { | ||
if (INPUT_START === stage) { | ||
displacementX = 0; | ||
@@ -80,4 +75,5 @@ displacementY = 0; | ||
distance = 0; | ||
overallDirection = NONE; | ||
} | ||
else if (STAGE.MOVE === stage) { | ||
else if (INPUT_MOVE === stage) { | ||
displacementX = Math.round(input.points[0][CLIENT_X] - startInput.points[0][CLIENT_X]); | ||
@@ -88,5 +84,6 @@ displacementY = Math.round(input.points[0][CLIENT_Y] - startInput.points[0][CLIENT_Y]); | ||
distance = Math.round(getVLength({ x: distanceX, y: distanceY })); | ||
overallDirection = getDirection(displacementX, displacementY); | ||
} | ||
return { | ||
displacementX: displacementX, displacementY: displacementY, distanceX: distanceX, distanceY: distanceY, distance: distance, getDirection: getDirection | ||
displacementX: displacementX, displacementY: displacementY, distanceX: distanceX, distanceY: distanceY, distance: distance, overallDirection: overallDirection | ||
}; | ||
@@ -101,3 +98,3 @@ }; | ||
var stage = input.stage; | ||
if (STAGE.START === stage) { | ||
if (INPUT_START === stage) { | ||
maxPointLength = input.pointLength; | ||
@@ -135,3 +132,3 @@ } | ||
var deltaTime = input.timestamp - _lastValidInput.timestamp; | ||
if (STAGE.MOVE === stage && COMPUTE_INTERVAL < deltaTime) { | ||
if (INPUT_MOVE === stage && COMPUTE_INTERVAL < deltaTime) { | ||
var deltaX = input.x - _lastValidInput.x; | ||
@@ -138,0 +135,0 @@ var deltaY = input.y - _lastValidInput.y; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@any-touch/vector"),e=require("@any-touch/shared");function n(t){return{x:t.points[1][e.CLIENT_X]-t.points[0][e.CLIENT_X],y:t.points[1][e.CLIENT_Y]-t.points[0][e.CLIENT_Y]}}function r(t){var e=t.prevInput,r=t.startMultiInput;if(void 0!==r&&void 0!==e&&t.id!==r.id&&1<e.pointLength&&1<t.pointLength)return{startV:n(r),prevV:n(e),activeV:n(t)}}function i(){return function(e){var n=(null==e?void 0:e._vs)||r(e);if(void 0!==n&&n.activeV){var i=n.prevV,a=n.startV,o=n.activeV,u=Math.round(t.getAngle(o,i));return{angle:Math.round(t.getAngle(o,a)),deltaAngle:u,_vs:n}}}}function a(e,n){if(void 0===e&&(e=0),void 0===n&&(n=0),0===e)return 0;var r=Math.sqrt(Math.pow(e,2)+Math.pow(n,2));return Math.round(t.radianToAngle(Math.acos(Math.abs(e)/r)))}function o(){return function(t){var e=t.prevInput,n=0,r=0;return void 0!==e&&(n=t.x-e.x,r=t.y-e.y),{deltaX:n,deltaY:r,getXYAngle:a}}}function u(){var n=0,r=0,i=0,a=0,o=0;return function(u){var s=u.stage,d=u.startInput;return e.STAGE.START===s?(n=0,r=0,i=0,a=0,o=0):e.STAGE.MOVE===s&&(n=Math.round(u.points[0][e.CLIENT_X]-d.points[0][e.CLIENT_X]),r=Math.round(u.points[0][e.CLIENT_Y]-d.points[0][e.CLIENT_Y]),i=Math.abs(n),a=Math.abs(r),o=Math.round(t.getVLength({x:i,y:a}))),{displacementX:n,displacementY:r,distanceX:i,distanceY:a,distance:o,getDirection:t.getDirection}}}function s(){var t=0;return function(n){var r=n.stage;return e.STAGE.START===r&&(t=n.pointLength),{maxPointLength:t}}}function d(){return function(n){var i=(null==n?void 0:n._vs)||r(n);if(void 0!==i&&i.activeV){var a=i.prevV,o=i.startV,u=i.activeV,s=e.round2(t.getVLength(u)/t.getVLength(a));return{scale:e.round2(t.getVLength(u)/t.getVLength(o)),deltaScale:s,_vs:i}}}}function v(){var n,r,i=0,a=0,o=0,u=0;return function(s){if(void 0!==s){var d=s.stage;r=r||s.startInput;var v=s.timestamp-r.timestamp;if(e.STAGE.MOVE===d&&e.COMPUTE_INTERVAL<v){var p=s.x-r.x,c=s.y-r.y;o=Math.round(p/v*100)/100,u=Math.round(c/v*100)/100,i=Math.abs(o),a=Math.abs(u),n=t.getDirection(p,c)||n,r=s}}return{velocityX:i,velocityY:a,speedX:o,speedY:u,direction:n}}}i._id="a",o._id="b",u._id="c",s._id="d",d._id="e",v._id="f",exports.ComputeAngle=i,exports.ComputeDeltaXY=o,exports.ComputeDistance=u,exports.ComputeMaxLength=s,exports.ComputeScale=d,exports.ComputeVAndDir=v; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@any-touch/vector"),e=require("@any-touch/shared");function n(t){return{x:t.points[1][e.CLIENT_X]-t.points[0][e.CLIENT_X],y:t.points[1][e.CLIENT_Y]-t.points[0][e.CLIENT_Y]}}function r(t){var e=t.prevInput,r=t.startMultiInput;if(void 0!==r&&void 0!==e&&t.id!==r.id&&1<e.pointLength&&1<t.pointLength)return{startV:n(r),prevV:n(e),activeV:n(t)}}function a(){return function(e){var n=(null==e?void 0:e._vs)||r(e);if(void 0!==n&&n.activeV){var a=n.prevV,i=n.startV,o=n.activeV,u=Math.round(t.getAngle(o,a));return{angle:Math.round(t.getAngle(o,i)),deltaAngle:u,_vs:n}}}}function i(){return function(e){var n=e.prevInput,r=0,a=0,i=0;if(void 0!==n&&(r=e.x-n.x,a=e.y-n.y,0!==r||0!==a)){var o=Math.sqrt(Math.pow(r,2)+Math.pow(a,2));i=Math.round(t.radianToAngle(Math.acos(Math.abs(r)/o)))}return{deltaX:r,deltaY:a,deltaXYAngle:i}}}function o(){var n=0,r=0,a=0,i=0,o=0,u=e.NONE;return function(s){var d=s.stage,p=s.startInput;return e.INPUT_START===d?(n=0,r=0,a=0,i=0,o=0,u=e.NONE):e.INPUT_MOVE===d&&(n=Math.round(s.points[0][e.CLIENT_X]-p.points[0][e.CLIENT_X]),r=Math.round(s.points[0][e.CLIENT_Y]-p.points[0][e.CLIENT_Y]),a=Math.abs(n),i=Math.abs(r),o=Math.round(t.getVLength({x:a,y:i})),u=t.getDirection(n,r)),{displacementX:n,displacementY:r,distanceX:a,distanceY:i,distance:o,overallDirection:u}}}function u(){var t=0;return function(n){var r=n.stage;return e.INPUT_START===r&&(t=n.pointLength),{maxPointLength:t}}}function s(){return function(n){var a=(null==n?void 0:n._vs)||r(n);if(void 0!==a&&a.activeV){var i=a.prevV,o=a.startV,u=a.activeV,s=e.round2(t.getVLength(u)/t.getVLength(i));return{scale:e.round2(t.getVLength(u)/t.getVLength(o)),deltaScale:s,_vs:a}}}}function d(){var n,r,a=0,i=0,o=0,u=0;return function(s){if(void 0!==s){var d=s.stage;r=r||s.startInput;var p=s.timestamp-r.timestamp;if(e.INPUT_MOVE===d&&e.COMPUTE_INTERVAL<p){var v=s.x-r.x,c=s.y-r.y;o=Math.round(v/p*100)/100,u=Math.round(c/p*100)/100,a=Math.abs(o),i=Math.abs(u),n=t.getDirection(v,c)||n,r=s}}return{velocityX:a,velocityY:i,speedX:o,speedY:u,direction:n}}}a._id="a",i._id="b",o._id="c",u._id="d",s._id="e",d._id="f",exports.ComputeAngle=a,exports.ComputeDeltaXY=i,exports.ComputeDistance=o,exports.ComputeMaxLength=u,exports.ComputeScale=s,exports.ComputeVAndDir=d; |
{ | ||
"name": "@any-touch/compute", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"main": "dist/index.js", | ||
@@ -14,5 +14,5 @@ "module": "dist/index.es.js", | ||
"dependencies": { | ||
"@any-touch/shared": "^1.0.4", | ||
"@any-touch/vector": "^1.0.4", | ||
"tslib": "^2.0.1" | ||
"@any-touch/shared": "^1.0.5", | ||
"@any-touch/vector": "^1.0.5", | ||
"tslib": "^1.9.3" | ||
}, | ||
@@ -22,3 +22,3 @@ "author": "any86", | ||
"sideEffects": false, | ||
"gitHead": "bf4837c370cf89353eff7911b7d2c772198fa301" | ||
"gitHead": "bf4d9191714dd0852ca76a335d5a232af36a691e" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11955
228
+ Addedtslib@1.14.1(transitive)
- Removedtslib@2.8.1(transitive)
Updated@any-touch/shared@^1.0.5
Updated@any-touch/vector@^1.0.5
Updatedtslib@^1.9.3