From 02361bc6d44b2ee0d8fa661a5923c7f01bf5c4b9 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Wed, 29 Oct 2025 09:15:14 -0500 Subject: [PATCH] fix for half segment fractional seconds when using zooming --- web/src/hooks/use-motion-segment-utils.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/web/src/hooks/use-motion-segment-utils.ts b/web/src/hooks/use-motion-segment-utils.ts index 0482e776e..91391c550 100644 --- a/web/src/hooks/use-motion-segment-utils.ts +++ b/web/src/hooks/use-motion-segment-utils.ts @@ -43,9 +43,14 @@ export const useMotionSegmentUtils = ( const segmentStart = getSegmentStart(time); const segmentEnd = getSegmentEnd(time); const matchingEvents = motion_events.filter((event) => { - return ( - event.start_time >= segmentStart && event.start_time < segmentEnd - ); + // Use integer ms math to avoid floating point rounding issues + // when halfSegmentDuration is not an integer + // (eg, 2.5 seconds from timeline zooming) + const eventMs = Math.round(event.start_time * 1000); + const halfMs = Math.round(halfSegmentDuration * 1000); + const eventBucketMs = Math.round(eventMs / halfMs) * halfMs; + const eventRounded = eventBucketMs / 1000; + return eventRounded >= segmentStart && eventRounded < segmentEnd; }); const totalMotion = matchingEvents.reduce( @@ -55,7 +60,7 @@ export const useMotionSegmentUtils = ( return totalMotion; }, - [motion_events, getSegmentStart, getSegmentEnd], + [motion_events, getSegmentStart, getSegmentEnd, halfSegmentDuration], ); const getAudioSegmentValue = useCallback(