How to keep a frame proportional when scaling with rotation

Hi, currently in the process of remaking studio’s UI editor into a more user friendly and smooth plugin, however im running into issues when scaling frames which are rotated as show:


While I don’t believe its very relevant here is my current resizing code:

function ResizingFunctions._RightSize(Frame, Distance, BaseSize, BasePosition, AspectRatioLocked, AspectRatio, CommandKeyIsDown)
	if CommandKeyIsDown then Distance *= 2 end
	
	local Inverse = Distance * -1
	local X = BaseSize.X + Inverse
	local Y = BaseSize.Y
	
	local ImportantCheck = (AspectRatio > 0) and (AspectRatio < 100000)

	if AspectRatioLocked and ImportantCheck then Y = X * AspectRatio end
	if AspectRatioLocked and ImportantCheck then X = Y / AspectRatio end

	if Settings.ClampResizingAtZero then Y = math.max(Y, 1) end
	if Settings.ClampResizingAtZero then X = math.max(X, 1) end
	
	Frame.Size = UDim2.new(0, X, 0, Y)
end

Where:
Frame is the Frame
Distance is the distance the mouse has traveled from starting point
BaseSize is the starting size of the frame
BasePosition is the starting position of the frame
And the others are not relevant since im not holding shift / alt

Id appreciate if someone could state how to factor in rotation here without the frame deciding to drift off into oblivion.

When you expand the frame, it extends in both directions, you need to move the frame to the side that is being extended the same distance it is being extended to cancel out the movement to the other side.