local s=game.Players.LocalPlayer:GetMouse()local Q=require(game.ReplicatedStorage.PolyBool)local a=game.Players.LocalPlayer.PlayerGui:WaitForChild("\083\099\114\101\101\110\071\117\105")local i=(require(script:WaitForChild("\077\097\105\100"))).new()local q=require(script:WaitForChild("\068\114\097\103\103\101\114"))local U=require(script:WaitForChild("\068\114\097\119"))local z=Vector2.new(0,36)local u=U.MakeVPF(a.Background.BackgroundColor3)u.Parent=a.Render local N=nil local b=nil local Y={a.Container.Polygon1,a.Container.Polygon2}local function c(s)return Vector2.new(s[1],s[2])end local function v(s)if b then N=nil b.BackgroundColor3=b.BorderColor3 end N="\115\101\108\101\099\116"..s.Name s.BackgroundColor3=Color3.fromRGB(0,170,255)b=s end local function k()i:Sweep()local s={}for Q,q in pairs(Y)do local u=#q:GetChildren()local N={}for s=1,u,1 do local Q=q[s]local b=q[s%u+1]local Y=(Q.AbsolutePosition+Q.AbsoluteSize/2)+z local c=(b.AbsolutePosition+b.AbsoluteSize/2)+z N[s]={Y.x;Y.y}local v=U.Line(Y,c)v.BackgroundColor3=q.BackgroundColor3 v.ZIndex=2 v.Parent=a.Render i:Mark(v)end s[Q]={regions={N};inverted=false}end if N~="\115\101\108\101\099\116\078\111\110\101"then local q=Q.segments(s[1])for a=2,#s,1 do local i=Q.segments(s[a])local U=Q.combine(q,i)q=Q[N](U)end local z=Q.polygon(q)for s,Q in pairs(z.regions)do local q=N=="\115\101\108\101\099\116\088\111\114"and(BrickColor.new(s)).Color for s=1,#Q,1 do local z=c(Q[s])local u=c(Q[s%#Q+1])local N=U.Line(z,u)N.BackgroundColor3=q or N.BackgroundColor3 N.Parent=a.Result i:Mark(N)end end end end for s,Q in pairs(Y)do for s,a in pairs(Q:GetChildren())do local i=q.new(a)i.DragChanged:Connect(function(s,a,i)local q=Q.Parent.AbsoluteSize local U=Vector2.new(a.Position.x,a.Position.y)U=U-Q.Parent.AbsolutePosition U=Vector2.new(math.clamp(U.x,0,q.x),math.clamp(U.y,0,q.y))s.Position=UDim2.new(0,U.x,0,U.y)k()end)end end for s,Q in pairs(a.Options:GetChildren())do if Q:IsA("\084\101\120\116\066\117\116\116\111\110")then Q.Activated:Connect(function()v(Q)k()end)end end v(a.Options.None)k()return true
local Mouse = game.Players.LocalPlayer:GetMouse()
local PolyBool = require(game.ReplicatedStorage.PolyBool)
local Screen = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")

local Maid = require(script:WaitForChild("Maid")).new()
local Dragger = require(script:WaitForChild("Dragger"))
local Draw = require(script:WaitForChild("Draw"))

local HEIGHT = Vector2.new(0, 36)
local VPF = Draw.MakeVPF(Screen.Background.BackgroundColor3)
VPF.Parent = Screen.Render

local funcName = nil
local lastButton = nil
local polygonFrames = {Screen.Container.Polygon1, Screen.Container.Polygon2}

local function toV2(p)
	return Vector2.new(p[1], p[2])
end

local function selectButton(button)
	if lastButton then
		funcName = nil
		lastButton.BackgroundColor3 = lastButton.BorderColor3
	end
	funcName = "select" .. button.Name
	button.BackgroundColor3 = Color3.fromRGB(0, 170, 255)
	lastButton = button
end

local function render()
	Maid:Sweep()

	local polygons = {}

	for k, polyFrame in pairs(polygonFrames) do
		local n = #polyFrame:GetChildren()
		local vertices = {}
		for i = 1, n do
			local framei = polyFrame[i]
			local framej = polyFrame[i % n + 1]
			local posi = framei.AbsolutePosition + framei.AbsoluteSize / 2 + HEIGHT
			local posj = framej.AbsolutePosition + framej.AbsoluteSize / 2 + HEIGHT

			vertices[i] = {posi.x, posi.y}
			
			local line = Draw.Line(posi, posj)
			line.BackgroundColor3 = polyFrame.BackgroundColor3
			line.ZIndex = 2
			line.Parent = Screen.Render
			Maid:Mark(line)
		end

		polygons[k] = {
			regions = {vertices};
			inverted = false;
		}
	end

	if funcName ~= "selectNone" then
		local segments = PolyBool.segments(polygons[1])
		for i = 2, #polygons do
			local seg2 = PolyBool.segments(polygons[i])
			local comb = PolyBool.combine(segments, seg2)
			segments = PolyBool[funcName](comb)
		end

		local polygon = PolyBool.polygon(segments)

		for k, region in pairs(polygon.regions) do
			local color = (funcName == "selectXor" and BrickColor.new(k).Color)
			for i = 1, #region do
				local pi = toV2(region[i])
				local pj = toV2(region[i % #region + 1])
				local line = Draw.Line(pi, pj)
				line.BackgroundColor3 = color or line.BackgroundColor3
				line.Parent = Screen.Result
				Maid:Mark(line)
			end
		end
	end
end

for _, polygon in pairs(polygonFrames) do
	for _, handle in pairs(polygon:GetChildren()) do
		local drag = Dragger.new(handle)
		drag.DragChanged:Connect(function(element, input, delta)
			local size = polygon.Parent.AbsoluteSize
			local pos = Vector2.new(input.Position.x, input.Position.y)
			pos = pos - polygon.Parent.AbsolutePosition

			pos = Vector2.new(
				math.clamp(pos.x, 0, size.x),
				math.clamp(pos.y, 0, size.y)
			)

			element.Position = UDim2.new(0, pos.x, 0, pos.y)
			render()
		end)
	end
end

for _, button in pairs(Screen.Options:GetChildren()) do
	if button:IsA("TextButton") then
		button.Activated:Connect(function()
			selectButton(button)
			render()
		end)
	end
end

selectButton(Screen.Options.None)
render()

return true