@hscmap/inertial-wheel
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -11,3 +11,2 @@ import { Physics } from "./physics"; | ||
private cb; | ||
baseInterval: number; | ||
readonly physics: Physics; | ||
@@ -14,0 +13,0 @@ private lastNativeEvent; |
@@ -10,3 +10,2 @@ "use strict"; | ||
this.cb = cb; | ||
this.baseInterval = 1000 / 60; | ||
this.physics = new physics_1.Physics(); | ||
@@ -35,5 +34,5 @@ this.magicTrackpadDetector = new magic_trackpad_detector_1.MagicTrackpadDetector(); | ||
var _this = this; | ||
var _a = this.physics.tick(performance.now()), v = _a.v, dt = _a.dt, wheelstart = _a.wheelstart, wheelend = _a.wheelend; | ||
var _a = this.physics.tick(performance.now()), v = _a.v, wheelstart = _a.wheelstart, wheelend = _a.wheelend; | ||
wheelstart && this.cb.wheelstart && this.cb.wheelstart(new InertialWheelStartEvent()); | ||
this.cb.wheel && this.cb.wheel(new InertialWheelEvent(dt * v / this.baseInterval, this.lastNativeEvent)); | ||
this.cb.wheel && this.cb.wheel(new InertialWheelEvent(v, this.lastNativeEvent)); | ||
wheelend && this.cb.wheelend && this.cb.wheelend(new InertialWheelEndEvent()); | ||
@@ -40,0 +39,0 @@ wheelend || this.cb.setNextTick(function () { return _this.tick(); }); |
@@ -15,2 +15,3 @@ export declare class Physics { | ||
t2: number; | ||
maxDT: number; | ||
stop(): void; | ||
@@ -20,3 +21,2 @@ kick(a: number, t: number): void; | ||
v: number; | ||
dt: number; | ||
wheelstart: boolean; | ||
@@ -23,0 +23,0 @@ wheelend: boolean; |
@@ -15,2 +15,3 @@ "use strict"; | ||
this.t2 = defaults.t2; | ||
this.maxDT = 3 * 1000 / 60; | ||
} | ||
@@ -32,7 +33,11 @@ Physics.prototype.stop = function () { | ||
this.a = 0; | ||
var dt = t - this.t; | ||
this.v += dt * (this.a == 0 ? | ||
-1. / this.t2 * this.v : | ||
this.a / this.t1); | ||
this.v = clamp(this.v, -1, 1); | ||
var DT = t - this.t; | ||
while (DT > 0) { | ||
var dt = Math.min(DT, this.maxDT); | ||
DT -= this.maxDT; | ||
this.v += dt * (this.a == 0 ? | ||
-1. / this.t2 * this.v : | ||
this.a / this.t1); | ||
this.v = clamp(this.v, -1, 1); | ||
} | ||
this.t = t; | ||
@@ -42,3 +47,2 @@ this.moving = this.willMove(); | ||
v: this.v, | ||
dt: dt, | ||
wheelstart: !moving0, | ||
@@ -45,0 +49,0 @@ wheelend: !this.moving |
{ | ||
"name": "@hscmap/inertial-wheel", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"main": "./lib/index.js", | ||
@@ -5,0 +5,0 @@ "types": "./lib/index.d.ts", |
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
159723
4939