From cf0e91c4ff1eb513bfca6743fc66a316b17fde6b Mon Sep 17 00:00:00 2001 From: Ajay Date: Sun, 11 Dec 2022 14:10:09 -0500 Subject: [PATCH] Use fast time to decimal for non display calculations --- src/js-components/previewBar.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts index f13a93cf..6e91fc0e 100644 --- a/src/js-components/previewBar.ts +++ b/src/js-components/previewBar.ts @@ -531,7 +531,7 @@ class PreviewBar { const nextSegment = segments[index + 1]; const nextTime = nextSegment ? nextSegment.segment[0] : this.videoDuration; const lastTime = result[result.length - 1]?.segment[1] || segment.segment[1]; - if (this.intervalToDecimal(lastTime, nextTime) > MIN_CHAPTER_SIZE) { + if (this.fastIntervalToDecimal(lastTime, nextTime) > MIN_CHAPTER_SIZE) { result.push({ segment: [lastTime, nextTime], originalDuration: 0, @@ -866,7 +866,7 @@ class PreviewBar { } private chapterGroupFilter(segment: SegmentContainer): boolean { - return segment.segment.length === 2 && this.intervalToDecimal(segment.segment[0], segment.segment[1]) > MIN_CHAPTER_SIZE; + return segment.segment.length === 2 && this.fastIntervalToDecimal(segment.segment[0], segment.segment[1]) > MIN_CHAPTER_SIZE; } intervalToPercentage(startTime: number, endTime: number) { @@ -877,6 +877,10 @@ class PreviewBar { return (this.timeToDecimal(endTime) - this.timeToDecimal(startTime)); } + fastIntervalToDecimal(startTime: number, endTime: number) { + return (this.fastTimeToDecimal(endTime) - this.fastTimeToDecimal(startTime)); + } + timeToPercentage(time: number): string { return `${this.timeToDecimal(time) * 100}%` } @@ -912,6 +916,10 @@ class PreviewBar { } } + return this.fastTimeToDecimal(time); + } + + fastTimeToDecimal(time: number): number { return Math.min(1, time / this.videoDuration); }