local Y={}Y.__index=Y Y.ClassName="\071\117\105\084\114\105\097\110\103\108\101"Y.ExtraPixels=2 function Y.new(w)local T=setmetatable({},Y)T.ta=Instance.new("\073\109\097\103\101\076\097\098\101\108")T.ta.BackgroundTransparency=1 T.ta.BorderSizePixel=0 T.tb=T.ta:Clone()T:SetParent(w)T.a=UDim2.new()T.b=UDim2.new()T.c=UDim2.new()return T end function Y.SetParent(w,Y)w.ta.Parent=Y w.tb.Parent=Y end function Y.Show(Y)Y.ta.Visible=true Y.tb.Visible=true end function Y.Set(t,Y,w,T)return((t:SetA(Y)):SetB(w)):SetC(T)end function Y.Hide(Y)Y.ta.Visible=false Y.tb.Visible=false end local function w(Y,w)return Y.x*w.x+Y.y*w.y end local function T(Y,w)local T=Y.x*math.cos(w)+Y.y*math.sin(w)local t=-Y.x*math.sin(w)+Y.y*math.cos(w)return Vector2.new(T,t)end function Y.SetA(w,Y)w.a=Y or error("\069\120\112\101\099\116\101\100 \086\101\099\116\111\114\050")return w end function Y.SetB(w,Y)w.b=Y or error("\069\120\112\101\099\116\101\100 \086\101\099\116\111\114\050")return w end function Y.SetC(w,Y)w.c=Y or error("\069\120\112\101\099\116\101\100 \086\101\099\116\111\114\050")return w end function Y.UpdateRender(Y)local t,M,p=Y.a,Y.b,Y.c local f=Y.ExtraPixels local y={{longest=p-M;other=t-M;position=M};{longest=t-p;other=M-p;position=p};{longest=M-t;other=p-t,position=t}}table.sort(y,function(Y,w)return Y.longest.Magnitude>w.longest.Magnitude end)local u=y[1]u.angle=math.acos(w(u.longest.unit,u.other.unit))u.x=u.other.Magnitude*math.cos(u.angle)u.y=u.other.Magnitude*math.sin(u.angle)local B=u.longest.unit*u.x-u.other local Z=math.atan2(B.y,B.x)-math.pi/2 local U=-u.other local X=u.longest.unit*u.x-u.other local d=U.x*X.y-U.y*X.x local z=u.position+u.other local g=d>0 and(u.position+u.longest)-X or u.position-X local h=Vector2.new((z-g).Magnitude,u.y)local L=Vector2.new(u.longest.Magnitude-h.x,u.y)local o=d<=0 and u.position+(u.longest+u.other)/2 or u.position+u.other/2 local l=d>0 and u.position+(u.longest+u.other)/2 or u.position+u.other/2 z=o+T(z-o,Z)g=l+T(g-l,Z)local P,R=Y.ta,Y.tb P.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\051\049\057\054\057\050\049\055\049"R.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\051\049\057\054\057\050\049\053\049"P.Position=UDim2.new(0,z.x,0,z.y)R.Position=UDim2.new(0,g.x,0,g.y)P.Size=UDim2.new(0,L.x+f,0,L.y+f)R.Size=UDim2.new(0,h.x+f,0,h.y+f)P.Rotation=math.deg(Z)R.Rotation=P.Rotation end function Y.Destroy(Y)setmetatable(Y,nil)Y.ta:Destroy()Y.ta=nil Y.tb:Destroy()Y.tb=nil end return Y
--- Gui triangle rendering class
-- @classmod GuiTriangle
-- http://wiki.roblox.com/index.php?title=2D_triangles

local GuiTriangle = {}
GuiTriangle.__index = GuiTriangle
GuiTriangle.ClassName = "GuiTriangle"
GuiTriangle.ExtraPixels = 2

function GuiTriangle.new(parent)
	local self = setmetatable({}, GuiTriangle)

	self.ta = Instance.new("ImageLabel")
	self.ta.BackgroundTransparency = 1
	self.ta.BorderSizePixel = 0

	self.tb = self.ta:Clone()

	self:SetParent(parent)
	self.a = UDim2.new()
	self.b = UDim2.new()
	self.c = UDim2.new()

	return self
end

function GuiTriangle:SetParent(parent)
	self.ta.Parent = parent
	self.tb.Parent = parent
end

function GuiTriangle:Show()
	self.ta.Visible = true
	self.tb.Visible = true
end

function GuiTriangle:Set(a, b, c)
	return self:SetA(a)
		:SetB(b)
		:SetC(c)
end

function GuiTriangle:Hide()
	self.ta.Visible = false
	self.tb.Visible = false
end

local function dotv2(a, b)
	return a.x * b.x + a.y * b.y
end

local function rotateV2(vec, angle)
	local x = vec.x * math.cos(angle) + vec.y * math.sin(angle)
	local y = -vec.x * math.sin(angle) + vec.y * math.cos(angle)
	return Vector2.new(x, y)
end

function GuiTriangle:SetA(a)
	self.a = a or error("Expected Vector2")
	return self
end

function GuiTriangle:SetB(b)
	self.b = b or error("Expected Vector2")
	return self
end

function GuiTriangle:SetC(c)
	self.c = c or error("Expected Vector2")
	return self
end

function GuiTriangle:UpdateRender()
	local a, b, c = self.a, self.b, self.c

	local extra = self.ExtraPixels

	local edges = {
		{longest = (c - b), other = (a - b), position = b};
		{longest = (a - c), other = (b - c), position = c};
		{longest = (b - a), other = (c - a), position = a};
	}

	table.sort(edges, function(a, b) return a.longest.Magnitude > b.longest.Magnitude end)

	local edge = edges[1]
	edge.angle = math.acos(dotv2(edge.longest.unit, edge.other.unit))
	edge.x = edge.other.Magnitude * math.cos(edge.angle)
	edge.y = edge.other.Magnitude * math.sin(edge.angle)

	local r = edge.longest.unit * edge.x - edge.other
	local rotation = math.atan2(r.y, r.x) - math.pi/2

	local tp = -edge.other
	local tx = (edge.longest.unit * edge.x) - edge.other
	local nz = tp.x * tx.y - tp.y * tx.x

	local tlc1 = edge.position + edge.other
	local tlc2 = nz > 0 and edge.position + edge.longest - tx or edge.position - tx

	local tasize = Vector2.new((tlc1 - tlc2).Magnitude, edge.y)
	local tbsize = Vector2.new(edge.longest.Magnitude - tasize.x, edge.y)

	local center1 = nz <= 0 and edge.position + ((edge.longest + edge.other)/2) or (edge.position + edge.other/2)
	local center2 = nz > 0 and edge.position + ((edge.longest + edge.other)/2) or (edge.position + edge.other/2)

	tlc1 = center1 + rotateV2(tlc1 - center1, rotation)
	tlc2 = center2 + rotateV2(tlc2 - center2, rotation)

	local ta, tb = self.ta, self.tb
	ta.Image = "rbxassetid://319692171"
	tb.Image = "rbxassetid://319692151"
	ta.Position = UDim2.new(0, tlc1.x, 0, tlc1.y)
	tb.Position = UDim2.new(0, tlc2.x, 0, tlc2.y)
	ta.Size = UDim2.new(0, tbsize.x + extra, 0, tbsize.y + extra)
	tb.Size = UDim2.new(0, tasize.x + extra, 0, tasize.y + extra)
	ta.Rotation = math.deg(rotation)
	tb.Rotation = ta.Rotation
end

function GuiTriangle:Destroy()
	setmetatable(self, nil)

	self.ta:Destroy()
	self.ta = nil

	self.tb:Destroy()
	self.tb = nil
end

return GuiTriangle