From 7b2da89e8d91fad9cdc96e18065e29decbed5da2 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Thu, 1 Sep 2022 08:49:13 +0700 Subject: [PATCH] fix(web): segment.angle spec, move-based segment recognition --- common/web/gesture-recognizer/src/constructingSegment.ts | 3 ++- common/web/gesture-recognizer/src/cumulativePathStats.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/common/web/gesture-recognizer/src/constructingSegment.ts b/common/web/gesture-recognizer/src/constructingSegment.ts index b17dd6ff7d..85aade6250 100644 --- a/common/web/gesture-recognizer/src/constructingSegment.ts +++ b/common/web/gesture-recognizer/src/constructingSegment.ts @@ -197,9 +197,10 @@ namespace com.keyman.osk { // it's time to commit to classifying the in-construction Segment. const alreadyElapsed = fullStatsWithIncoming.duration; const recognitionWaitTime = this.classifier.config.holdMinimumDuration - alreadyElapsed; + const recognitionFromMove = (this.pathSegment.distance > this.classifier.config.holdMoveTolerance); // `undefined` if and only if still unrecognized. - if(recognitionWaitTime <= 0 && !this._pathSegment.isRecognized) { + if((recognitionFromMove || recognitionWaitTime <= 0) && !this._pathSegment.isRecognized) { const classification = this.classifier.classifySegment(fullStatsWithIncoming); // Based on the specification for segment classification, there WILL be a classification diff --git a/common/web/gesture-recognizer/src/cumulativePathStats.ts b/common/web/gesture-recognizer/src/cumulativePathStats.ts index f03b92cd40..d7167ebf70 100644 --- a/common/web/gesture-recognizer/src/cumulativePathStats.ts +++ b/common/web/gesture-recognizer/src/cumulativePathStats.ts @@ -584,10 +584,10 @@ namespace com.keyman.osk { */ public get angle() { if(this.sampleCount == 1 || !this.lastSample || !this.initialSample) { - return Number.NaN; + return undefined; } else if(this.netDistance < 1) { // < 1 px, thus sub-pixel, means we have nothing relevant enough to base an angle on. - return Number.NaN; + return undefined; } const xDelta = this.lastSample.targetX - this.initialSample.targetX; @@ -618,6 +618,10 @@ namespace com.keyman.osk { return undefined; } + if(isNaN(this.angle) || this.angle === null || this.angle === undefined) { + return undefined; + } + const buckets = ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'n']; // We could be 'more efficient' and use radians here instead, but this