fix resize group for Triangle:

:
This commit is contained in:
hamid zarghami
2026-01-07 12:27:06 +03:30
parent abcc34c1cb
commit 9e1dd09097
2 changed files with 96 additions and 20 deletions
+35 -8
View File
@@ -771,18 +771,30 @@ export const useEditorStore = create<EditorStoreType>((set, get) => {
return;
}
// برای مثلث و abstract، x و y مرکز است
// برای مثلث و abstract، x و y در store گوشه بالا-چپ است اما در render مرکز استفاده می‌شود
if (obj.type === "rectangle" && (obj.shapeType === "triangle" || obj.shapeType === "abstract")) {
const cx = obj.x || 0;
const cy = obj.y || 0;
// محاسبه مرکز از گوشه بالا-چپ
const cx = (obj.x || 0) + w / 2;
const cy = (obj.y || 0) + h / 2;
const rot = ((obj.rotation || 0) * Math.PI) / 180;
// محاسبه چهار گوشه rectangle با rotation
// برای abstract، از radius واقعی استفاده کن (0.85 * baseRadius)
// برای triangle، از radius واقعی استفاده کن (min(width, height) / 2)
let actualRadius: number;
if (obj.shapeType === "abstract") {
const baseRadius = Math.min(w / 2, h / 2);
actualRadius = baseRadius * 0.85;
} else {
// triangle
actualRadius = Math.min(w / 2, h / 2);
}
// محاسبه چهار گوشه با استفاده از radius واقعی
const corners = [
{ x: -w / 2, y: -h / 2 },
{ x: w / 2, y: -h / 2 },
{ x: w / 2, y: h / 2 },
{ x: -w / 2, y: h / 2 },
{ x: -actualRadius, y: -actualRadius },
{ x: actualRadius, y: -actualRadius },
{ x: actualRadius, y: actualRadius },
{ x: -actualRadius, y: actualRadius },
];
corners.forEach((corner) => {
@@ -798,6 +810,21 @@ export const useEditorStore = create<EditorStoreType>((set, get) => {
return;
}
// برای arrow، x و y نقطه شروع است و width/height نقطه پایان است
if (obj.type === "arrow" || obj.type === "line") {
const startX = obj.x || 0;
const startY = obj.y || 0;
const endX = obj.width || 0;
const endY = obj.height || 0;
// برای arrow و line، bounding box از نقطه شروع تا نقطه پایان است
minX = Math.min(minX, startX, endX);
minY = Math.min(minY, startY, endY);
maxX = Math.max(maxX, startX, endX);
maxY = Math.max(maxY, startY, endY);
return;
}
// برای سایر اشکال، x و y گوشه بالا-چپ است
const cx = (obj.x || 0) + w / 2;
const cy = (obj.y || 0) + h / 2;