@@ -20,7 +20,7 @@ import type { Table } from "components/canvas/elements/Table.tsx";
2020import type { KonvaEventObject } from "konva/lib/Node" ;
2121import type { Wall } from "components/canvas/elements/Wall.tsx" ;
2222import type { SelectionRectangleType } from "components/canvas/elements/SelectionRectangle.tsx" ;
23- import { findStageCenterCoordinates , validateCanvasElementDeletion } from "components/canvas/utils/functions.tsx" ;
23+ import { validateCanvasElementDeletion } from "components/canvas/utils/functions.tsx" ;
2424import toast from "react-hot-toast" ;
2525
2626
@@ -260,7 +260,7 @@ export const handleMouseDown = (
260260 const y2 = ( pointer . y - stage . y ( ) ) / scale ;
261261 const { x1, y1 } = quickWallCoordinates ;
262262
263- const stageCenter = findStageCenterCoordinates ( stageRef ) ;
263+ const stageCenter = { x : 0 , y : 0 } ;
264264 let element = shapeFactory ( "wall" , stageCenter ) as Wall ;
265265 element = { ...element , x1, y1, x2, y2 } as Wall ;
266266
@@ -352,14 +352,48 @@ export const handleDragEnd = (e: Konva.KonvaEventObject<DragEvent>, el: ElementP
352352 angle : angle ,
353353 } ;
354354 } else {
355- if ( Math . abs ( table . rotation ) < 1 ) {
356- const { radius : padding } = el ;
357- const { width, height, x : tableX , y : tableY } = table ;
355+ let normalizedRotation = table . rotation % 360 ;
356+ if ( normalizedRotation < 0 ) normalizedRotation += 360 ;
357+
358+ if ( normalizedRotation < 1 ||
359+ ( 89 < normalizedRotation && normalizedRotation < 91 ) ||
360+ ( 179 < normalizedRotation && normalizedRotation < 181 ) ||
361+ ( 269 < normalizedRotation && normalizedRotation < 271 ) ||
362+ normalizedRotation > 359 ) {
358363
359- const centerX = tableX + width ! / 2 ;
360- const centerY = tableY + height ! / 2 ;
364+ const { radius : padding } = el ;
365+ const tableX = table . x ;
366+ const tableY = table . y ;
367+ let { width, height } = table ;
368+
369+ let centerX = 0 ;
370+ let centerY = 0 ;
371+
372+ if ( normalizedRotation < 1 || normalizedRotation > 359 ) {
373+ // 0 degrees - normal case
374+ centerX = tableX + width ! / 2 ;
375+ centerY = tableY + height ! / 2 ;
376+ } else if ( 89 < normalizedRotation && normalizedRotation < 91 ) {
377+ // 90 degrees - width becomes height, height becomes width
378+ const tempWidth = width ;
379+ width = height ;
380+ height = tempWidth ;
381+ centerX = tableX - width ! / 2 ;
382+ centerY = tableY + height ! / 2 ;
383+ } else if ( 179 < normalizedRotation && normalizedRotation < 181 ) {
384+ // 180 degrees - table is flipped
385+ centerX = tableX - width ! / 2 ;
386+ centerY = tableY - height ! / 2 ;
387+ } else if ( 269 < normalizedRotation && normalizedRotation < 271 ) {
388+ // 270 degrees - width becomes height, height becomes width
389+ const tempWidth = width ;
390+ width = height ;
391+ height = tempWidth ;
392+ centerX = tableX + width ! / 2 ;
393+ centerY = tableY - height ! / 2 ;
394+ }
361395
362- // Coordinates relative to table center
396+ // Coordinates relative to table center (using chair position, not table position)
363397 const dx = x - centerX ;
364398 const dy = y - centerY ;
365399
0 commit comments