Skip to content

Commit 69a8169

Browse files
committed
fix: preserve numeric range contracts
1 parent b7bf068 commit 69a8169

3 files changed

Lines changed: 8 additions & 14 deletions

File tree

src/contracts/scroll-gesture.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ test('clampGestureCoordinate rounds values and clamps them into the safe gesture
222222
assert.equal(clampGestureCoordinate(97.6, 8, 100), 92);
223223
});
224224

225-
test('clampGestureCoordinate returns the lower bound for missing or non-finite coordinates', () => {
226-
assert.equal(clampGestureCoordinate(undefined, 8, 100), 8);
225+
test('clampGestureCoordinate returns the lower bound for non-finite coordinates', () => {
227226
assert.equal(clampGestureCoordinate(Number.POSITIVE_INFINITY, 8, 100), 8);
228-
assert.equal(clampGestureCoordinate(10, Number.POSITIVE_INFINITY, 100), 0);
229227
});

src/contracts/scroll-gesture.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,13 @@ function pointFromPercent(
244244
const x = Math.trunc((frame.referenceWidth * xPercent) / 100);
245245
const y = Math.trunc((frame.referenceHeight * yPercent) / 100);
246246
return {
247-
x,
248-
y,
247+
x: Number.isFinite(x) ? x : 0,
248+
y: Number.isFinite(y) ? y : 0,
249249
};
250250
}
251251

252252
function clampGesturePoint(
253-
point: { x: number | undefined; y: number | undefined },
253+
point: GesturePoint,
254254
frame: GestureReferenceFrame,
255255
marginPx: number,
256256
): GesturePoint {
@@ -308,16 +308,12 @@ function normalizeRequestedPixels(pixels: number): number {
308308
return Math.max(1, Math.round(pixels));
309309
}
310310

311-
export function clampGestureCoordinate(
312-
value: number | undefined,
313-
marginPx: number,
314-
size: number,
315-
): number {
311+
export function clampGestureCoordinate(value: number, marginPx: number, size: number): number {
316312
const min = Math.round(marginPx);
317313
if (!Number.isFinite(min)) return 0;
318314

319315
const max = Math.max(min, Math.round(size - marginPx));
320-
if (!Number.isFinite(max) || value === undefined || !Number.isFinite(value)) return min;
316+
if (!Number.isFinite(max) || !Number.isFinite(value)) return min;
321317

322318
return Math.min(max, Math.max(min, Math.round(value)));
323319
}

src/screenshot-diff/screenshot-diff-region-overlay.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function setPixel(
5050
diff.data[index + 3] = color[3];
5151
}
5252

53-
function clamp(value: number | undefined, min: number, max: number): number {
54-
if (value === undefined || !Number.isFinite(value)) return min;
53+
function clamp(value: number, min: number, max: number): number {
54+
if (!Number.isFinite(value)) return min;
5555
return Math.min(Math.max(value, min), max);
5656
}

0 commit comments

Comments
 (0)