MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / classifyTap

Function classifyTap

src/cm/touchSelectionMenu.js:21–52  ·  view source on GitHub ↗
(previousTap, tap)

Source from the content-addressed store, hash-verified

19 * @returns {{x:number,y:number,time:number,count:number}}
20 */
21export function classifyTap(previousTap, tap) {
22 if (!previousTap) {
23 return { ...tap, count: 1 };
24 }
25
26 const dt = tap.time - previousTap.time;
27 const dx = tap.x - previousTap.x;
28 const dy = tap.y - previousTap.y;
29 const distance = Math.hypot(dx, dy);
30 const sameTextZone =
31 tap.line != null &&
32 previousTap.line != null &&
33 tap.line === previousTap.line &&
34 Math.abs((tap.column ?? 0) - (previousTap.column ?? 0)) <=
35 TAP_MAX_COLUMN_DELTA;
36 const nearSamePos =
37 tap.pos != null &&
38 previousTap.pos != null &&
39 Math.abs(tap.pos - previousTap.pos) <= TAP_MAX_POS_DELTA;
40
41 if (
42 dt <= TAP_MAX_DELAY &&
43 (distance <= TAP_MAX_DISTANCE || sameTextZone || nearSamePos)
44 ) {
45 return {
46 ...tap,
47 count: Math.min(previousTap.count + 1, 3),
48 };
49 }
50
51 return { ...tap, count: 1 };
52}
53
54/**
55 * Clamp menu coordinates so it stays within the container bounds.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected