function UICornerUtils.clampPositionToFrame(n,P,x,r)assert(x>0,"\066\097\100 \114\097\100\105\117\115")assert(r,"\066\097\100 \112\111\105\110\116")local N,l=r.x,r.y local e,z=n.x,n.y local h,t=P.x,P.y local p=e+x local T=(e+h)-x local X=z+x local u=(z+t)-x local O,G if p<T then O=math.clamp(N,p,T)else O=p end if X<u then G=math.clamp(l,X,u)else G=X end local a=Vector2.new(O,G)local Z=r-a if Z.magnitude==0 then return nil,nil end local v=Z.unit local S=a+v*x return S,v end return UICornerUtils

function UICornerUtils.clampPositionToFrame(framePosition, frameSize, radius, point)
	assert(radius > 0, "Bad radius")
	assert(point, "Bad point")

	local px, py = point.x, point.y

	local fpx, fpy = framePosition.x, framePosition.y
	local fsx, fsy = frameSize.x, frameSize.y

	local minx = fpx + radius
	local maxx = fpx + fsx - radius

	local miny = fpy + radius
	local maxy = fpy + fsy - radius

	-- relative position to inner box
	local rpx, rpy

	if minx < maxx then
		rpx = math.clamp(px, minx, maxx)
	else
		rpx = minx
	end

	if miny < maxy then
		rpy = math.clamp(py, miny, maxy)
	else
		rpy = miny
	end

	local position = Vector2.new(rpx, rpy)

	-- project in direction of offset
	local direction = point - position
	if direction.magnitude == 0 then
		-- Shouldn't happen!
		return nil, nil
	end

	local normal = direction.unit
	local outsidePosition = position + normal*radius
	return outsidePosition, normal
end

return UICornerUtils
