From c5d12a8acb7b372ea8a381dfea5d175d3334cdf2 Mon Sep 17 00:00:00 2001 From: Adam Rutter Date: Tue, 18 Aug 2020 23:08:35 +0100 Subject: [PATCH] Ensure saturation/lightness between 0 and 1 --- lua/colors.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/colors.lua b/lua/colors.lua index fb526cf..2209bad 100644 --- a/lua/colors.lua +++ b/lua/colors.lua @@ -200,7 +200,10 @@ end -- @return a new instance of Color ----------------------------------------------------------------------------- function Color:desaturate_by(r) - return new(self.H, self.S*r, self.L) + local s = self.S * r + if s < 0 then s = 0 end + if s > 1 then s = 1 end + return new(self.H, s, self.L) end ----------------------------------------------------------------------------- @@ -220,7 +223,10 @@ end -- @return a new instance of Color ----------------------------------------------------------------------------- function Color:lighten_by(r) - return new(self.H, self.S, self.L*r) + local l = self.L * r + if l < 0 then l = 0 end + if l > 1 then l = 1 end + return new(self.H, self.S, l) end -----------------------------------------------------------------------------