function UICornerUtils.clampPositionToFrame(s,N,g,b)assert(g>0,"\066\097\100 \114\097\100\105\117\115")assert(b,"\066\097\100 \112\111\105\110\116")local I,D=b.x,b.y local Q,n=s.x,s.y local o,V=N.x,N.y local j=Q+g local m=(Q+o)-g local W=n+g local l=(n+V)-g local T,p if j<m then T=math.clamp(I,j,m)else T=j end if W<l then p=math.clamp(D,W,l)else p=W end local B=Vector2.new(T,p)local M=b-B if M.magnitude==0 then return nil,nil end local v=M.unit local S=B+v*g return S,v end return UICornerUtils
-- framePosition is top left corner
-- returns position, relativePosition, normal
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
