Misc: Use the ^ operator instead of math.pow (#9550)

And some minor code simplifications, thanks to @zwim ;).
This commit is contained in:
NiLuJe
2022-09-28 01:11:34 +02:00
committed by GitHub
parent 62059f8d68
commit 4d48b6e2fe
4 changed files with 15 additions and 17 deletions

View File

@@ -91,14 +91,12 @@ function SysfsLight:setNaturalBrightness(brightness, warmth)
if brightness > 0 then
-- On Nickel, the values for white/red/green are roughly linearly dependent
-- on the 4th root of brightness and warmth.
white = math.min(self.white_gain * math.pow(brightness, self.exponent) *
math.pow(100 - warmth, self.exponent) + self.white_offset, 255)
white = math.min(self.white_gain * (brightness * (100 - warmth))^self.exponent + self.white_offset, 255)
end
if warmth > 0 then
red = math.min(self.red_gain * math.pow(brightness, self.exponent) *
math.pow(warmth, self.exponent) + self.red_offset, 255)
green = math.min(self.green_gain * math.pow(brightness, self.exponent) *
math.pow(warmth, self.exponent) + self.green_offset, 255)
local brightness_warmth_exp = (brightness * warmth)^self.exponent
red = math.min(self.red_gain * brightness_warmth_exp + self.red_offset, 255)
green = math.min(self.green_gain * brightness_warmth_exp + self.green_offset, 255)
end
white = math.max(white, 0)