Skip to content

Commit 6b6f255

Browse files
committed
Refactor: Simplify HSLA => GUI_HSLA conversion
1 parent 3fb475e commit 6b6f255

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

typescripts/color/Representation.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,8 @@ class HSLA implements Representation, HSLLike, HasAlpha {
787787

788788
toGUI_HSLA(): GUI_HSLA {
789789

790-
const scalingFactor = 1 - ((this.saturation / 100) * 0.5)
791-
const y = 100 - (this.lightness / scalingFactor)
790+
const scalingFactor = 1 + (this.saturation / 100)
791+
const y = 100 - Math.min(100, this.lightness * scalingFactor)
792792
const h = this.hue / 360 * 100
793793

794794
return new GUI_HSLA(h, this.saturation, y, this.alpha)
@@ -967,10 +967,12 @@ class GUI_HSLA implements Representation, HasAlpha {
967967

968968
const hue = calcHueDegrees(this.hue)
969969
const saturation = this.saturation
970-
const maxL = 100 - this.lightness
971-
const minL = maxL / 2
972-
const lightness = round(minL + ((maxL - minL) * ((100 - saturation) / 100)))
973-
const alpha = this.alpha
970+
971+
const mult = 100 - this.lightness
972+
const scalingFactor = 1 + (this.saturation / 100)
973+
const lightness = mult / scalingFactor
974+
975+
const alpha = this.alpha
974976

975977
return new HSLA(hue, saturation, lightness, alpha)
976978

0 commit comments

Comments
 (0)