local E,u=table.insert,Vector3.new function GetCornerOffsets(z,o)local G={}local r=z:inverse()for z,o in pairs(o)do local f=o.CFrame local v,a,k=z.Size.X/2,z.Size.Y/2,z.Size.Z/2 E(G,r*(f*u(v,a,k)))E(G,r*(f*u(-v,a,k)))E(G,r*(f*u(v,-a,k)))E(G,r*(f*u(v,a,-k)))E(G,r*(f*u(-v,a,-k)))E(G,r*(f*u(-v,-a,k)))E(G,r*(f*u(v,-a,-k)))E(G,r*(f*u(-v,-a,-k)))end return G end function FreeDragging.InstallDragEndListener(E)Support.AddUserInputListener("\069\110\100\101\100",{"\084\111\117\099\104","\077\111\117\115\101\066\117\116\116\111\110\049"},true,function(u)E.StartScreenPoint=nil E.StartTarget=nil ContextActionService:UnbindAction("\066\084\058 \087\097\116\099\104 \102\111\114 \100\114\097\103\103\105\110\103")if E.IsDragging then E.Tool:SetAxes(E.Tool.Axes)E:FinishDragging()end end)end return FreeDragging
-- Cache common functions to avoid unnecessary table lookups
local TableInsert, NewVector3 = table.insert, Vector3.new

function GetCornerOffsets(Origin, InitialStates)
	-- Calculates and returns the offset of every corner in the initial state from the origin CFrame

	local CornerOffsets = {}

	-- Get offset for origin point
	local OriginOffset = Origin:inverse()

	-- Go through each item in the initial state
	for Item, State in pairs(InitialStates) do
		local ItemCFrame = State.CFrame
		local SizeX, SizeY, SizeZ = Item.Size.X / 2, Item.Size.Y / 2, Item.Size.Z / 2

		-- Gather each corner
		TableInsert(CornerOffsets, OriginOffset * (ItemCFrame * NewVector3(SizeX, SizeY, SizeZ)))
		TableInsert(CornerOffsets, OriginOffset * (ItemCFrame * NewVector3(-SizeX, SizeY, SizeZ)))
		TableInsert(CornerOffsets, OriginOffset * (ItemCFrame * NewVector3(SizeX, -SizeY, SizeZ)))
		TableInsert(CornerOffsets, OriginOffset * (ItemCFrame * NewVector3(SizeX, SizeY, -SizeZ)))
		TableInsert(CornerOffsets, OriginOffset * (ItemCFrame * NewVector3(-SizeX, SizeY, -SizeZ)))
		TableInsert(CornerOffsets, OriginOffset * (ItemCFrame * NewVector3(-SizeX, -SizeY, SizeZ)))
		TableInsert(CornerOffsets, OriginOffset * (ItemCFrame * NewVector3(SizeX, -SizeY, -SizeZ)))
		TableInsert(CornerOffsets, OriginOffset * (ItemCFrame * NewVector3(-SizeX, -SizeY, -SizeZ)))
	end

	-- Return the offsets
	return CornerOffsets
end

function FreeDragging:InstallDragEndListener()
	Support.AddUserInputListener("Ended", { "Touch", "MouseButton1" }, true, function(Input)
		-- Clear drag detection data
		self.StartScreenPoint = nil
		self.StartTarget = nil
		ContextActionService:UnbindAction("BT: Watch for dragging")

		-- Reset from drag mode if dragging
		if self.IsDragging then
			-- Reset axes
			self.Tool:SetAxes(self.Tool.Axes)

			-- Finalize the dragging operation
			self:FinishDragging()
		end
	end)
end

return FreeDragging
