<commit_before>/******************************************************************************\
  Color support
\******************************************************************************/

local Clamp = math.Clamp
local floor = math.floor
local Round = math.Round

local function RGBClamp(r,g,b)
	return Clamp(r,0,255), Clamp(g,0,255), Clamp(b,0,255)
end

/******************************************************************************/

__e2setcost(2)

e2function vector entity:getColor()
	if not IsValid(this) then return self:throw("Invalid entity!", {0, 0, 0}) end

	local c = this:GetColor()
	return { c.r, c.g, c.b }
end

e2function vector4 entity:getColor4()
	if not IsValid(this) then return self:throw("Invalid entity!", {0, 0, 0, 0}) end
	local c = this:GetColor()
	return {c.r, c.g, c.b, c.a}
end

e2function number entity:getAlpha()
	if not IsValid(this) then return self:throw("Invalid entity!", 0) end
	return this:GetColor().a
end

e2function void entity:setColor(r,g,b)
	if not IsValid(this) then return self:throw("Invalid entity!", 0) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	WireLib.SetColor(this, Color(r, g, b, this:GetColor().a))
end

e2function void entity:setColor(r,g,b,a)
	if not IsValid(this) then return self:throw("Invalid entity!", 0) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	WireLib.SetColor(this, Color(r, g, b, a))
end

e2function void entity:setColor(vector c)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	WireLib.SetColor(this, Color(c[1], c[2], c[3], this:GetColor().a))
end

e2function void entity:setColor(vector c, a)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	WireLib.SetColor(this, Color(c[1], c[2], c[3], a))
end

e2function void entity:setColor(vector4 c)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	WireLib.SetColor(this, Color(c[1], c[2], c[3], c[4]))
end

e2function void entity:setAlpha(a)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	if this:IsPlayer() then return self:throw("You cannot set the alpha of a player!", nil) end

	local c = this:GetColor()
	WireLib.SetColor(this, Color(c.r, c.g, c.b, a))
end

e2function void entity:setRenderMode(mode)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end
	if this:IsPlayer() then return self:throw("You cannot set the render mode of a player!", nil) end

	this:SetRenderMode(mode)
	duplicator.StoreEntityModifier(this, "colour", { RenderMode = mode })
end

e2function vector entity:getPlayerColor()
	if not IsValid(this) then return self:throw("Invalid entity!", {0, 0, 0}) end
	if not this:IsPlayer() then return self:throw("Expected player but got an entity", {0, 0, 0}) end

	local c = this:GetPlayerColor()

	return { RGBClamp(Round(c.r * 255), Round(c.g * 255), Round(c.b * 255)) }
end

e2function vector entity:getWeaponColor()
	if not IsValid(this) then return self:throw("Invalid entity!", {0, 0, 0}) end
	if not this:IsPlayer() then return self:throw("Expected player but got an entity", {0, 0, 0}) end

	local c = this:GetWeaponColor()

	return { RGBClamp(Round(c.r * 255), Round(c.g * 255), Round(c.b * 255)) }
end

--- HSV

--- Converts <hsv> from the [http://en.wikipedia.org/wiki/HSV_color_space HSV color space] to the [http://en.wikipedia.org/wiki/RGB_color_space RGB color space]
e2function vector hsv2rgb(vector hsv)
	local col = HSVToColor(math.Clamp(hsv[1] % 360, 0, 360), hsv[2], hsv[3])
	return { col.r, col.g, col.b }
end

e2function vector hsv2rgb(h, s, v)
	local col = HSVToColor(math.Clamp(h % 360, 0, 360), s, v)
	return { col.r, col.g, col.b }
end

--- Converts <rgb> from the [http://en.wikipedia.org/wiki/RGB_color_space RGB color space] to the [http://en.wikipedia.org/wiki/HSV_color_space HSV color space]<commit_msg>Added e:setWeaponColor and e:setPlayerColor (#2378)<commit_after>/******************************************************************************\
  Color support
\******************************************************************************/

local Clamp = math.Clamp
local floor = math.floor
local Round = math.Round

local function RGBClamp(r,g,b)
	return Clamp(r,0,255), Clamp(g,0,255), Clamp(b,0,255)
end

/******************************************************************************/

__e2setcost(2)

e2function vector entity:getColor()
	if not IsValid(this) then return self:throw("Invalid entity!", {0, 0, 0}) end

	local c = this:GetColor()
	return { c.r, c.g, c.b }
end

e2function vector4 entity:getColor4()
	if not IsValid(this) then return self:throw("Invalid entity!", {0, 0, 0, 0}) end
	local c = this:GetColor()
	return {c.r, c.g, c.b, c.a}
end

e2function number entity:getAlpha()
	if not IsValid(this) then return self:throw("Invalid entity!", 0) end
	return this:GetColor().a
end

e2function void entity:setColor(r,g,b)
	if not IsValid(this) then return self:throw("Invalid entity!", 0) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	WireLib.SetColor(this, Color(r, g, b, this:GetColor().a))
end

e2function void entity:setColor(r,g,b,a)
	if not IsValid(this) then return self:throw("Invalid entity!", 0) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	WireLib.SetColor(this, Color(r, g, b, a))
end

e2function void entity:setColor(vector c)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	WireLib.SetColor(this, Color(c[1], c[2], c[3], this:GetColor().a))
end

e2function void entity:setColor(vector c, a)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	WireLib.SetColor(this, Color(c[1], c[2], c[3], a))
end

e2function void entity:setColor(vector4 c)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	WireLib.SetColor(this, Color(c[1], c[2], c[3], c[4]))
end

e2function void entity:setAlpha(a)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end

	if this:IsPlayer() then return self:throw("You cannot set the alpha of a player!", nil) end

	local c = this:GetColor()
	WireLib.SetColor(this, Color(c.r, c.g, c.b, a))
end

e2function void entity:setRenderMode(mode)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You do not own this entity!", nil) end
	if this:IsPlayer() then return self:throw("You cannot set the render mode of a player!", nil) end

	this:SetRenderMode(mode)
	duplicator.StoreEntityModifier(this, "colour", { RenderMode = mode })
end

e2function vector entity:getPlayerColor()
	if not IsValid(this) then return self:throw("Invalid entity!", {0, 0, 0}) end
	if not this:IsPlayer() then return self:throw("Expected player but got an entity", {0, 0, 0}) end

	local c = this:GetPlayerColor()

	return { RGBClamp(Round(c.r * 255), Round(c.g * 255), Round(c.b * 255)) }
end

e2function vector entity:getWeaponColor()
	if not IsValid(this) then return self:throw("Invalid entity!", {0, 0, 0}) end
	if not this:IsPlayer() then return self:throw("Expected player but got an entity", {0, 0, 0}) end

	local c = this:GetWeaponColor()
	return { RGBClamp(Round(c.r * 255), Round(c.g * 255), Round(c.b * 255)) }
end

e2function void entity:setWeaponColor(vector c)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You cannot set other player's weapon colors!", nil) end
	if not this:IsPlayer() then return self:throw("You cannot set the weapon color of non-players!", nil) end

	local r, g, b = RGBClamp(c[1], c[2], c[3])
	this:SetWeaponColor( Vector(r / 255, g / 255, b / 255) )
end

e2function void entity:setPlayerColor(vector c)
	if not IsValid(this) then return self:throw("Invalid entity!", nil) end
	if not isOwner(self, this) then return self:throw("You cannot set other player's colors!", nil) end
 	if not this:IsPlayer() then return self:throw("You cannot set the player color of non-players!", nil) end

	 local r, g, b = RGBClamp(c[1], c[2], c[3])
	this:SetPlayerColor( Vector(r / 255, g / 255, b / 255) )
end

--- HSV

--- Converts <hsv> from the [http://en.wikipedia.org/wiki/HSV_color_space HSV color space] to the [http://en.wikipedia.org/wiki/RGB_color_space RGB color space]
e2function vector hsv2rgb(vector hsv)
	local col = HSVToColor(math.Clamp(hsv[1] % 360, 0, 360), hsv[2], hsv[3])
	return { col.r, col.g, col.b }
end

e2function vector hsv2rgb(h, s, v)
	local col = HSVToColor(math.Clamp(h % 360, 0, 360), s, v)
	return { col.r, col.g, col.b }
end

--- Converts <rgb> from the [http://en.wikipedia.org/wiki/RGB_color_space RGB color space] to the [http://en.wikipedia.org/wiki/HSV_color_space HSV color space]
{'fraction_non_alphanumeric': 0.18305330844223192, 'fraction_numerical': 0.023853972204936735, 'mean_word_length': 5.390324718356528, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '365038', 'n_tokens_mistral': 3498, 'n_tokens_neox': 3286, 'n_words': 1098}