summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/timeline/placement/overlap.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-03-31 15:47:30 +0200
committerMaze Winther <mazewinther@gmail.com>2026-03-31 15:47:30 +0200
commit70a6d58b8432e455ab1443d45bc23dd70b363bea (patch)
treeb4bcdb88b87cbd2cd295c54cde013f38481c7f2a /apps/web/src/lib/timeline/placement/overlap.ts
parent5cc6abc3a44c9d046a1cb71a8c916f1d35827e8f (diff)
downloadopencut-70a6d58b8432e455ab1443d45bc23dd70b363bea.tar.gz
refactor: centralize track placement into its own module
Diffstat (limited to 'apps/web/src/lib/timeline/placement/overlap.ts')
-rw-r--r--apps/web/src/lib/timeline/placement/overlap.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/apps/web/src/lib/timeline/placement/overlap.ts b/apps/web/src/lib/timeline/placement/overlap.ts
new file mode 100644
index 00000000..e5f95fa9
--- /dev/null
+++ b/apps/web/src/lib/timeline/placement/overlap.ts
@@ -0,0 +1,40 @@
+import type { TimelineElement, TimelineTrack } from "@/lib/timeline";
+import type { PlacementTimeSpan } from "./types";
+
+function wouldElementOverlap({
+ elements,
+ startTime,
+ endTime,
+ excludeElementId,
+}: {
+ elements: TimelineElement[];
+ startTime: number;
+ endTime: number;
+ excludeElementId?: string;
+}): boolean {
+ return elements.some((element) => {
+ if (excludeElementId && element.id === excludeElementId) {
+ return false;
+ }
+
+ const elementEnd = element.startTime + element.duration;
+ return startTime < elementEnd && endTime > element.startTime;
+ });
+}
+
+export function canPlaceTimeSpansOnTrack({
+ track,
+ timeSpans,
+}: {
+ track: TimelineTrack;
+ timeSpans: PlacementTimeSpan[];
+}): boolean {
+ return timeSpans.every(({ startTime, duration, excludeElementId }) => {
+ return !wouldElementOverlap({
+ elements: track.elements,
+ startTime,
+ endTime: startTime + duration,
+ excludeElementId,
+ });
+ });
+}