fix for half segment fractional seconds when using zooming

This commit is contained in:
Josh Hawkins 2025-10-29 09:15:14 -05:00
parent ff27612ed8
commit 02361bc6d4

View File

@ -43,9 +43,14 @@ export const useMotionSegmentUtils = (
const segmentStart = getSegmentStart(time); const segmentStart = getSegmentStart(time);
const segmentEnd = getSegmentEnd(time); const segmentEnd = getSegmentEnd(time);
const matchingEvents = motion_events.filter((event) => { const matchingEvents = motion_events.filter((event) => {
return ( // Use integer ms math to avoid floating point rounding issues
event.start_time >= segmentStart && event.start_time < segmentEnd // 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( const totalMotion = matchingEvents.reduce(
@ -55,7 +60,7 @@ export const useMotionSegmentUtils = (
return totalMotion; return totalMotion;
}, },
[motion_events, getSegmentStart, getSegmentEnd], [motion_events, getSegmentStart, getSegmentEnd, halfSegmentDuration],
); );
const getAudioSegmentValue = useCallback( const getAudioSegmentValue = useCallback(