♻️ refactor!: massive refactor

This commit is contained in:
2026-05-31 03:04:30 +07:00
parent c1f12c7201
commit df3c944547
86 changed files with 3691 additions and 1129 deletions
+19 -7
View File
@@ -1,6 +1,12 @@
import type { Layer } from "@pien-studio/types";
type FaceDetection = { x: number; y: number; width: number; height: number; label?: string };
type FaceDetection = {
x: number;
y: number;
width: number;
height: number;
label?: string;
};
type Viewport = { x: number; y: number; scale: number };
@@ -13,9 +19,8 @@ export function buildFaceLabelOverlays(
const layer = layers.find((item) => item.id === faceOverlayLayerId);
if (!layer) return [];
const isImage = layer.type === "raster";
const layerWidth = layer.width ?? (isImage ? Math.round(200 * layer.scale) : undefined);
const layerHeight = layer.height ?? (isImage ? Math.round(150 * layer.scale) : undefined);
const layerWidth = layer.width;
const layerHeight = layer.height;
if (!layerWidth || !layerHeight) return [];
const centerX = layer.x + layerWidth / 2;
@@ -23,7 +28,12 @@ export function buildFaceLabelOverlays(
const radians = (layer.rotation * Math.PI) / 180;
const cos = Math.cos(radians);
const sin = Math.sin(radians);
const placed: Array<{ left: number; top: number; width: number; height: number }> = [];
const placed: Array<{
left: number;
top: number;
width: number;
height: number;
}> = [];
return faceDetections.map((face, index) => {
const worldX = layer.x + face.x;
@@ -41,8 +51,10 @@ export function buildFaceLabelOverlays(
while (
placed.some((rect) => {
const intersectsX = left < rect.left + rect.width && left + estimatedWidth > rect.left;
const intersectsY = top < rect.top + rect.height && top + estimatedHeight > rect.top;
const intersectsX =
left < rect.left + rect.width && left + estimatedWidth > rect.left;
const intersectsY =
top < rect.top + rect.height && top + estimatedHeight > rect.top;
return intersectsX && intersectsY;
})
) {