local M,Z=table.insert,Vector3.new function GetCornerOffsets(U,v)local u={}local y=U:inverse()for U,v in pairs(v)do local A=v.CFrame local C,l,H=U.Size.X/2,U.Size.Y/2,U.Size.Z/2 M(u,y*(A*Z(C,l,H)))M(u,y*(A*Z(-C,l,H)))M(u,y*(A*Z(C,-l,H)))M(u,y*(A*Z(C,l,-H)))M(u,y*(A*Z(-C,l,-H)))M(u,y*(A*Z(-C,-l,H)))M(u,y*(A*Z(C,-l,-H)))M(u,y*(A*Z(-C,-l,-H)))end return u end function FreeDragging.InstallDragEndListener(M)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(Z)M.StartScreenPoint=nil M.StartTarget=nil ContextActionService:UnbindAction("\066\084\058 \087\097\116\099\104 \102\111\114 \100\114\097\103\103\105\110\103")if M.IsDragging then M.Tool:SetAxes(M.Tool.Axes)M:FinishDragging()end end)end return FreeDragging

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
