Skip to content

Commit 5b1ea3c

Browse files
committed
fix potentioal floating point errors before send, and snap in sliders
1 parent 81c7478 commit 5b1ea3c

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/lib/components/ControlModules/impl/CircleSlider.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@
5050
let lastFraction: number | null = null;
5151
5252
// --- helpers ---
53+
const stepDecimals = $derived((step.toString().split('.')[1] ?? '').length);
54+
5355
function snapValue(raw: number): number {
54-
return clamp(Math.round((raw - min) / step) * step + min, min, max);
56+
const steps = Math.round((raw - min) / step);
57+
const snapped = +(steps * step + min).toFixed(stepDecimals);
58+
return clamp(snapped, min, max);
5559
}
5660
5761
function fractionFromEvent(event: PointerEvent) {

src/lib/signalr/serializers/Control.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export async function serializeControlMessages(connection: HubConnection, contro
66
'ControlV2',
77
controls.map((control) => ({
88
...control,
9-
duration: control.duration * 1000,
9+
intensity: Math.round(control.intensity),
10+
duration: Math.round(control.duration * 1000),
1011
})),
1112
null
1213
);

src/routes/shares/public/[shareId=guid]/ControlView.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@
4848
}
4949
5050
function publicCtrl(id: string, type: ControlType, intensity: number, duration: number) {
51-
control({ id, type, intensity, duration: duration * 1000 });
51+
control({
52+
id,
53+
type,
54+
intensity: Math.round(intensity),
55+
duration: Math.round(duration * 1000),
56+
});
5257
}
5358
5459
const shareId = $derived(page.params.shareId);

0 commit comments

Comments
 (0)