How would I clamp a position to an irregular shape?

Im trying to make a camera system that follows the player in a top down view, and I want it to clamp to the boundaries of the room shape, and it won’t be a rectangle or smthn like that, it could be an L shape or any other shape.

local RS = game:GetService("RunService")

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local root = char:FindFirstChild("HumanoidRootPart")

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {workspace.Zones}

local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable

local size = Vector3.new(20, 10, 13)

RS.RenderStepped:Connect(function()
	local xcast = workspace:Raycast(root.Position, Vector3.new(size.X, 0, 0), params)
	local ycast = workspace:Raycast(root.Position, Vector3.new(0, size.Y, 0), params)
	local zcast = workspace:Raycast(root.Position, Vector3.new(0, 0, size.Z), params)
	local nxcast = workspace:Raycast(root.Position, Vector3.new(-size.X, 0, 0), params)
	local nzcast = workspace:Raycast(root.Position, Vector3.new(0, 0, -size.Z), params)
	
	local angle = CFrame.Angles(math.rad(-45), 0, 0)
	local pos = Vector3.new(((xcast and xcast.Position.X or root.Position.X+size.X)+(nxcast and nxcast.Position.X or root.Position.X-size.X))/2, ycast and ycast-size.Y or root.Position.Y, ((zcast and zcast.Position.Z or root.Position.Z+size.Z)+(nzcast and nzcast.Position.Z or root.Position.Z-size.Z))/2)
	local cf = CFrame.new(pos+angle.LookVector*-15)
	local new = CFrame.new(math.clamp(cf.X, nxcast and nxcast.Position.X or root.Position.X-size.X, xcast and xcast.Position.X or root.Position.X+size.X), math.clamp(cf.Y, 0, ycast and ycast.Position.Y or root.Position.Y+size.Y), math.clamp(cf.Z, nzcast and nzcast.Position.Z or root.Position.Z-size.Z, zcast and zcast.Position.Z or root.Position.Z+size.Z))
	cam.CFrame = new*angle
end)

This is the closest thing I was able to get
pls help :pray: