update spirit
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
applySafeArea,
|
||||
classifyDirection,
|
||||
hitTest,
|
||||
isInsideCircle,
|
||||
isInsideRect,
|
||||
joystickDirection,
|
||||
ZERO_DIRECTION,
|
||||
@@ -21,8 +22,33 @@ describe('InputModel — layout geometry', () => {
|
||||
const r = { cx: 100, cy: 100, w: 40, h: 40 };
|
||||
expect(isInsideRect(r, 100, 100)).toBe(true);
|
||||
expect(isInsideRect(r, 120, 120)).toBe(true);
|
||||
expect(isInsideRect(r, 121, 100)).toBe(false);
|
||||
expect(isInsideRect(r, 100, 79)).toBe(false);
|
||||
// With HIT_TOLERANCE=15, the effective boundary is ±35 (=halfW/halfH + tolerance).
|
||||
// 121 is outside the visual box (120) but within tolerance (135).
|
||||
expect(isInsideRect(r, 121, 100)).toBe(true);
|
||||
// 79 is below the visual bottom (80) but within tolerance (65).
|
||||
expect(isInsideRect(r, 100, 79)).toBe(true);
|
||||
// Far outside even the tolerance range.
|
||||
expect(isInsideRect(r, 136, 100)).toBe(false);
|
||||
expect(isInsideRect(r, 100, 64)).toBe(false);
|
||||
});
|
||||
|
||||
it('isInsideCircle matches circular button shape', () => {
|
||||
const r = { cx: 765, cy: 100, w: 90, h: 90 }; // shuriken button
|
||||
// Centre — always a hit.
|
||||
expect(isInsideCircle(r, 765, 100)).toBe(true);
|
||||
// On the circle edge (radius = 45).
|
||||
expect(isInsideCircle(r, 765 + 45, 100)).toBe(true); // right edge
|
||||
expect(isInsideCircle(r, 765, 100 + 45)).toBe(true); // top edge (upper semicircle)
|
||||
expect(isInsideCircle(r, 765 - 45, 100)).toBe(true); // left edge
|
||||
expect(isInsideCircle(r, 765, 100 - 45)).toBe(true); // bottom edge
|
||||
// Within HIT_TOLERANCE (15) outside the circle.
|
||||
expect(isInsideCircle(r, 765 + 60, 100)).toBe(true); // right + tolerance
|
||||
expect(isInsideCircle(r, 765, 100 + 60)).toBe(true); // top + tolerance (upper arc)
|
||||
// Corner of the bounding rect but OUTSIDE the circle — should miss.
|
||||
// Distance from centre to (765+45, 100+45) = sqrt(45²+45²) ≈ 63.6 > 45+15=60
|
||||
expect(isInsideCircle(r, 765 + 45, 100 + 45)).toBe(false);
|
||||
// Well outside.
|
||||
expect(isInsideCircle(r, 765 + 70, 100)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user