diff --git a/common/web/gesture-recognizer/package.json b/common/web/gesture-recognizer/package.json index 48e4d34606..40fa25468a 100644 --- a/common/web/gesture-recognizer/package.json +++ b/common/web/gesture-recognizer/package.json @@ -26,6 +26,9 @@ "ts-node": "^10.9.1", "typescript": "^4.9.5" }, + "imports": { + "#tools": "./build/tools/obj/index.js" + }, "scripts": { "build": "gosh ./build.sh", "test": "gosh ./test.sh" diff --git a/common/web/gesture-recognizer/src/engine/headless/cumulativePathStats.ts b/common/web/gesture-recognizer/src/engine/headless/cumulativePathStats.ts index c2021fb16d..a22957c2a3 100644 --- a/common/web/gesture-recognizer/src/engine/headless/cumulativePathStats.ts +++ b/common/web/gesture-recognizer/src/engine/headless/cumulativePathStats.ts @@ -45,7 +45,7 @@ export function sigMinus(operand1: number, operand2: number) { * * Instances of this class are immutable. */ -export class CumulativePathStats { +export class CumulativePathStats { /** * Provides linear-regression statistics & fitting values based on the underlying `CumulativePathStats` * object used to generate it. All operations are O(1). @@ -204,8 +204,8 @@ export class CumulativePathStats { constructor(); constructor(sample: InputSample); - constructor(instance: CumulativePathStats); - constructor(obj?: InputSample | CumulativePathStats) { + constructor(instance: CumulativePathStats); + constructor(obj?: InputSample | CumulativePathStats) { if(!obj) { return; } @@ -232,7 +232,7 @@ export class CumulativePathStats { * @returns A new, separate instance for the cumulative properties up to the * newly-sampled point. */ - public extend(sample: InputSample): CumulativePathStats { + public extend(sample: InputSample): CumulativePathStats { if(!this._initialSample) { this._initialSample = sample; this.baseSample = sample; @@ -301,7 +301,7 @@ export class CumulativePathStats { * from this instance's current accumulation. * @returns */ - public deaccumulate(subsetStats?: CumulativePathStats): CumulativePathStats { + public deaccumulate(subsetStats?: CumulativePathStats): CumulativePathStats { // Possible addition: use `this.buildRenormalized` on the returned version // if catastrophic cancellation effects (random, small floating point errors) // are not sufficiently mitigated & handled by the measures currently in place. @@ -509,7 +509,7 @@ export class CumulativePathStats { * errors than the old instance whenever they do occur. * @returns */ - public buildRenormalized(): CumulativePathStats { + public buildRenormalized(): CumulativePathStats { // Other (internal) notes: the internal mapping of the new instance will not // match that of the old instance. This should not affect the practical // results of any mapping to and from the external coordinate space, however. diff --git a/common/web/gesture-recognizer/src/engine/headless/gesturePath.ts b/common/web/gesture-recognizer/src/engine/headless/gesturePath.ts index 71525bb30a..62220a6a95 100644 --- a/common/web/gesture-recognizer/src/engine/headless/gesturePath.ts +++ b/common/web/gesture-recognizer/src/engine/headless/gesturePath.ts @@ -48,7 +48,7 @@ export class GesturePath extends EventEmitter> { private _isComplete: boolean = false; private _wasCancelled?: boolean; - private _stats: CumulativePathStats; + private _stats: CumulativePathStats; public get stats() { // Is (practically) immutable, so it's safe to expose the instance directly. @@ -75,7 +75,7 @@ export class GesturePath extends EventEmitter> { instance._isComplete = true; instance._wasCancelled = jsonObj.wasCancelled; - let stats = instance.samples.reduce((stats: CumulativePathStats, sample) => stats.extend(sample), new CumulativePathStats()); + let stats = instance.samples.reduce((stats: CumulativePathStats, sample) => stats.extend(sample), new CumulativePathStats()); instance._stats = stats; return instance; diff --git a/common/web/gesture-recognizer/src/test/auto/headless/gesturePath.js b/common/web/gesture-recognizer/src/test/auto/headless/gesturePath.js index 3c1690eb28..67590e4c73 100644 --- a/common/web/gesture-recognizer/src/test/auto/headless/gesturePath.js +++ b/common/web/gesture-recognizer/src/test/auto/headless/gesturePath.js @@ -6,7 +6,7 @@ import fs from 'fs'; import { GesturePath } from '@keymanapp/gesture-recognizer'; import { timedPromise } from '@keymanapp/web-utils'; -import { TouchpathTurtle } from '../../../../build/tools/obj/index.js'; +import { TouchpathTurtle } from '#tools'; // Ensures that the resources are resolved relative to this script, not to the cwd when the test // runner was launched. diff --git a/common/web/gesture-recognizer/src/test/auto/headless/pathStats.ts b/common/web/gesture-recognizer/src/test/auto/headless/pathStats.ts index f9535ecd96..ffea495a97 100644 --- a/common/web/gesture-recognizer/src/test/auto/headless/pathStats.ts +++ b/common/web/gesture-recognizer/src/test/auto/headless/pathStats.ts @@ -1,7 +1,7 @@ import { assert } from 'chai'; import { CumulativePathStats, InputSample } from '@keymanapp/gesture-recognizer'; -import { TouchpathTurtle } from '../../../../build/tools/obj/index.js'; +import { TouchpathTurtle } from '#tools'; describe("CumulativePathStats", function() { it("Sample count = 0", function() { diff --git a/common/web/gesture-recognizer/src/test/auto/headless/recordedSegmentations.js b/common/web/gesture-recognizer/src/test/auto/headless/recordedSegmentations.js index cb87813879..b457167113 100644 --- a/common/web/gesture-recognizer/src/test/auto/headless/recordedSegmentations.js +++ b/common/web/gesture-recognizer/src/test/auto/headless/recordedSegmentations.js @@ -10,7 +10,7 @@ const PromiseStatuses = PromiseStatusModule.PromiseStatuses; import { PathSegmenter } from '@keymanapp/gesture-recognizer'; -import { HeadlessInputEngine } from '../../../../build/tools/obj/index.js'; +import { HeadlessInputEngine } from '#tools'; // Ensures that the resources are resolved relative to this script, not to the cwd when the test // runner was launched. diff --git a/common/web/gesture-recognizer/src/test/auto/tsconfig.json b/common/web/gesture-recognizer/src/test/auto/tsconfig.json new file mode 100644 index 0000000000..ae2302aa52 --- /dev/null +++ b/common/web/gesture-recognizer/src/test/auto/tsconfig.json @@ -0,0 +1,11 @@ +/* + * VS Code Intellisense needs this helper in order to properly use subpath imports in the + * test specs found under the `headless` subfolder. Otherwise, it'll report errors while + * editing - even if the tests themselves actually work. + */ +{ + "extends": "../../../../tsconfig.kmw-main-base.json", + "compilerOptions": { + "moduleResolution": "Node16", + } +} diff --git a/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts b/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts index 065245c9c3..9f97970ca4 100644 --- a/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts +++ b/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts @@ -76,6 +76,7 @@ export class TouchpathTurtle extends EventEmitter) { @@ -102,23 +103,20 @@ export class TouchpathTurtle extends EventEmitter 0!"); } const startSample = this.location; + const timeDelta = totalTime / sampleCount; // Base sample always exists in advance. - for(let timeDelta = 0; timeDelta < totalTime; timeDelta += repeatInterval) { + for(let i = 1; i <= sampleCount; i++) { let sample = {...startSample}; - sample.t += timeDelta; + sample.t += timeDelta * i; this.trackSample(sample); } - - let currentSample = {...startSample}; - currentSample.t += totalTime; - this.trackSample(currentSample); } move(angleInDegrees: number, distance: number, time: number, sampleCount: number) {