mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
feat: masks, properties refactor, shaders, storage migrations, and more
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { ElementWithBounds } from "./element-bounds";
|
||||
import type { ElementRef } from "@/lib/timeline/types";
|
||||
|
||||
function pointInRotatedRect({
|
||||
px,
|
||||
@@ -24,14 +25,14 @@ function pointInRotatedRect({
|
||||
const dy = py - cy;
|
||||
const localX = dx * cos - dy * sin;
|
||||
const localY = dx * sin + dy * cos;
|
||||
const halfW = width / 2;
|
||||
const halfH = height / 2;
|
||||
const halfW = Math.abs(width) / 2;
|
||||
const halfH = Math.abs(height) / 2;
|
||||
return (
|
||||
localX >= -halfW && localX <= halfW && localY >= -halfH && localY <= halfH
|
||||
);
|
||||
}
|
||||
|
||||
export function hitTest({
|
||||
export function getHitElements({
|
||||
canvasX,
|
||||
canvasY,
|
||||
elementsWithBounds,
|
||||
@@ -39,7 +40,9 @@ export function hitTest({
|
||||
canvasX: number;
|
||||
canvasY: number;
|
||||
elementsWithBounds: ElementWithBounds[];
|
||||
}): ElementWithBounds | null {
|
||||
}): ElementWithBounds[] {
|
||||
const hits: ElementWithBounds[] = [];
|
||||
|
||||
for (let i = elementsWithBounds.length - 1; i >= 0; i--) {
|
||||
const { bounds } = elementsWithBounds[i];
|
||||
if (
|
||||
@@ -53,8 +56,47 @@ export function hitTest({
|
||||
rotation: bounds.rotation,
|
||||
})
|
||||
) {
|
||||
return elementsWithBounds[i];
|
||||
hits.push(elementsWithBounds[i]);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
return hits;
|
||||
}
|
||||
|
||||
export function hitTest({
|
||||
canvasX,
|
||||
canvasY,
|
||||
elementsWithBounds,
|
||||
}: {
|
||||
canvasX: number;
|
||||
canvasY: number;
|
||||
elementsWithBounds: ElementWithBounds[];
|
||||
}): ElementWithBounds | null {
|
||||
return (
|
||||
getHitElements({
|
||||
canvasX,
|
||||
canvasY,
|
||||
elementsWithBounds,
|
||||
})[0] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
export function resolvePreferredHit({
|
||||
hits,
|
||||
preferredElements,
|
||||
}: {
|
||||
hits: ElementWithBounds[];
|
||||
preferredElements: ElementRef[];
|
||||
}): ElementWithBounds | null {
|
||||
if (preferredElements.length === 0) return null;
|
||||
|
||||
return (
|
||||
hits.find((hit) =>
|
||||
preferredElements.some(
|
||||
(preferredElement) =>
|
||||
preferredElement.trackId === hit.trackId &&
|
||||
preferredElement.elementId === hit.elementId,
|
||||
),
|
||||
) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user