@map-gesture-controls/core 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,7 +7,7 @@ const FAST_TUNING = {
|
|
|
7
7
|
releaseGraceMs: 0, // grace=0: idle on the SECOND frame after release
|
|
8
8
|
panDeadzonePx: 0,
|
|
9
9
|
zoomDeadzoneRatio: 0,
|
|
10
|
-
smoothingAlpha: 1, // no smoothing
|
|
10
|
+
smoothingAlpha: 1, // no smoothing, raw values pass through
|
|
11
11
|
minDetectionConfidence: 0.65,
|
|
12
12
|
minTrackingConfidence: 0.65,
|
|
13
13
|
minPresenceConfidence: 0.60,
|
|
@@ -97,9 +97,9 @@ describe('GestureStateMachine', () => {
|
|
|
97
97
|
fsm.update(makeFrame(0, makeHand('fist', lm1), null));
|
|
98
98
|
// Frame 2: transition fires → panning, but buildOutput returns from idle branch (panDelta=null)
|
|
99
99
|
fsm.update(makeFrame(0, makeHand('fist', lm1), null));
|
|
100
|
-
// Frame 3: first real panning frame
|
|
100
|
+
// Frame 3: first real panning frame, sets prevPanPos = wristPos1, no delta yet
|
|
101
101
|
fsm.update(makeFrame(1, makeHand('fist', lm1), null));
|
|
102
|
-
// Frame 4: second panning frame
|
|
102
|
+
// Frame 4: second panning frame, emits delta
|
|
103
103
|
const out = fsm.update(makeFrame(2, makeHand('fist', lm2), null));
|
|
104
104
|
expect(out.mode).toBe('panning');
|
|
105
105
|
expect(out.panDelta).not.toBeNull();
|
|
@@ -122,7 +122,7 @@ describe('GestureStateMachine', () => {
|
|
|
122
122
|
// Frame 1+2: dwell + transition (zooming entered on frame 2, but output comes from idle branch)
|
|
123
123
|
fsm.update(makeFrame(0, makeHand('openPalm', lmL1), makeHand('openPalm', lmR1)));
|
|
124
124
|
fsm.update(makeFrame(0, makeHand('openPalm', lmL1), makeHand('openPalm', lmR1)));
|
|
125
|
-
// Frame 3: first real zooming frame
|
|
125
|
+
// Frame 3: first real zooming frame, sets prevZoomDist, no delta yet
|
|
126
126
|
fsm.update(makeFrame(1, makeHand('openPalm', lmL1), makeHand('openPalm', lmR1)));
|
|
127
127
|
// Frame 4: wider spread → positive delta
|
|
128
128
|
const out = fsm.update(makeFrame(2, makeHand('openPalm', lmL2), makeHand('openPalm', lmR2)));
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { HandLandmark, GestureType } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Returns the apparent 2D size of the hand: wrist-to-middle-MCP distance
|
|
4
|
-
* in normalised screen space (0
|
|
5
|
-
* larger as it moves toward the camera.
|
|
4
|
+
* in normalised screen space (0-1). Used as a depth proxy (hand grows
|
|
5
|
+
* larger as it moves toward the camera).
|
|
6
6
|
*/
|
|
7
7
|
export declare function getHandSize(landmarks: HandLandmark[]): number;
|
|
8
8
|
/**
|
|
9
9
|
* Returns the Euclidean distance between the index fingertips of two hands
|
|
10
|
-
* in normalised screen space (0
|
|
10
|
+
* in normalised screen space (0-1). Used as the two-hand zoom metric:
|
|
11
11
|
* hands moving apart = positive delta = zoom in.
|
|
12
12
|
*/
|
|
13
13
|
export declare function getTwoHandDistance(landmarksA: HandLandmark[], landmarksB: HandLandmark[]): number;
|
|
@@ -11,7 +11,7 @@ function dist(a, b) {
|
|
|
11
11
|
* Returns true if all four fingers (index–pinky) are extended AND spread apart.
|
|
12
12
|
*
|
|
13
13
|
* "Extended": tip is farther from the wrist than its MCP joint (allows slightly
|
|
14
|
-
* bent fingers
|
|
14
|
+
* bent fingers; the 0.9 factor gives ~10% slack).
|
|
15
15
|
*
|
|
16
16
|
* "Spread": the minimum distance between any two adjacent fingertips (index–middle,
|
|
17
17
|
* middle–ring, ring–pinky) must be at least spreadThreshold × handSize. Using the
|
|
@@ -31,7 +31,7 @@ function areAllFingersExtended(landmarks) {
|
|
|
31
31
|
}
|
|
32
32
|
// Spread check: minimum pairwise distance between adjacent fingertips vs hand size.
|
|
33
33
|
// Using the minimum (not mean) catches duck/pinch shapes where adjacent fingertips
|
|
34
|
-
// touch
|
|
34
|
+
// touch: the mean can stay high because the outer pair (index↔pinky) is still far
|
|
35
35
|
// apart, but the minimum collapses to near zero when any two tips cluster together.
|
|
36
36
|
// A natural open hand has even adjacent tips ~20–35% of handSize apart.
|
|
37
37
|
// A duck has adjacent tips at ~2–8% of handSize. Threshold of 0.18 separates them.
|
|
@@ -67,8 +67,8 @@ function areAllFingersCurled(landmarks) {
|
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Returns the apparent 2D size of the hand: wrist-to-middle-MCP distance
|
|
70
|
-
* in normalised screen space (0
|
|
71
|
-
* larger as it moves toward the camera.
|
|
70
|
+
* in normalised screen space (0-1). Used as a depth proxy (hand grows
|
|
71
|
+
* larger as it moves toward the camera).
|
|
72
72
|
*/
|
|
73
73
|
export function getHandSize(landmarks) {
|
|
74
74
|
const wrist = landmarks[LANDMARKS.WRIST];
|
|
@@ -79,7 +79,7 @@ export function getHandSize(landmarks) {
|
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Returns the Euclidean distance between the index fingertips of two hands
|
|
82
|
-
* in normalised screen space (0
|
|
82
|
+
* in normalised screen space (0-1). Used as the two-hand zoom metric:
|
|
83
83
|
* hands moving apart = positive delta = zoom in.
|
|
84
84
|
*/
|
|
85
85
|
export function getTwoHandDistance(landmarksA, landmarksB) {
|
|
@@ -31,7 +31,7 @@ function makeOpenPalmLandmarks() {
|
|
|
31
31
|
lm[LANDMARKS.MIDDLE_MCP] = { x: 0.4, y: 0.5, z: 0 };
|
|
32
32
|
lm[LANDMARKS.RING_MCP] = { x: 0.5, y: 0.5, z: 0 };
|
|
33
33
|
lm[LANDMARKS.PINKY_MCP] = { x: 0.6, y: 0.5, z: 0 };
|
|
34
|
-
// Fingertips
|
|
34
|
+
// Fingertips: extended (farther from wrist than MCPs) and spread
|
|
35
35
|
lm[LANDMARKS.INDEX_TIP] = { x: 0.2, y: 0.1, z: 0 };
|
|
36
36
|
lm[LANDMARKS.MIDDLE_TIP] = { x: 0.35, y: 0.1, z: 0 };
|
|
37
37
|
lm[LANDMARKS.RING_TIP] = { x: 0.5, y: 0.1, z: 0 };
|
|
@@ -42,7 +42,7 @@ function makeOpenPalmLandmarks() {
|
|
|
42
42
|
* Build a fist hand.
|
|
43
43
|
*
|
|
44
44
|
* Strategy: wrist at (0.5, 0.8), MCP joints at (0.5, 0.5),
|
|
45
|
-
* fingertips curled back to (0.5, 0.7)
|
|
45
|
+
* fingertips curled back to (0.5, 0.7), closer to wrist than MCPs.
|
|
46
46
|
*
|
|
47
47
|
* dist(tip, wrist) ≈ 0.1 < dist(mcp, wrist) * 1.1 ≈ 0.33 ✓
|
|
48
48
|
*/
|
|
@@ -72,7 +72,7 @@ describe('classifyGesture', () => {
|
|
|
72
72
|
expect(classifyGesture(makeFistLandmarks())).toBe('fist');
|
|
73
73
|
});
|
|
74
74
|
it('returns "none" for an ambiguous / neutral hand', () => {
|
|
75
|
-
// All landmarks at the same point
|
|
75
|
+
// All landmarks at the same point, fingers neither extended nor curled
|
|
76
76
|
expect(classifyGesture(makeLandmarks())).toBe('none');
|
|
77
77
|
});
|
|
78
78
|
it('prefers "fist" over "openPalm" when both criteria match', () => {
|