ucs: Lch: Expand lightness, chroma, and hue field names
diff --git a/src/commonMain/kotlin/dev/kdrag0n/colorkt/cam/Zcam.kt b/src/commonMain/kotlin/dev/kdrag0n/colorkt/cam/Zcam.kt
index de3135b..2f3dd5c 100644
--- a/src/commonMain/kotlin/dev/kdrag0n/colorkt/cam/Zcam.kt
+++ b/src/commonMain/kotlin/dev/kdrag0n/colorkt/cam/Zcam.kt
@@ -30,13 +30,13 @@
/** Absolute brightness. **/
val brightness: Double = Double.NaN,
/** Brightness relative to the reference white, from 0 to 100. **/
- val lightness: Double = Double.NaN,
+ override val lightness: Double = Double.NaN,
/** Absolute colorfulness. **/
val colorfulness: Double = Double.NaN,
/** Colorfulness relative to the reference white. **/
- val chroma: Double = Double.NaN,
+ override val chroma: Double = Double.NaN,
/** Hue from 0 to 360 degrees. **/
- val hue: Double,
+ override val hue: Double,
/* hue composition is not supported */
// 2D
@@ -72,14 +72,6 @@
/** Alias for [whiteness]. **/
val Wz: Double get() = whiteness
- // Aliases for Lch interface
- /** Alias for [lightness]. **/
- override val L: Double get() = lightness
- /** Alias for [chroma]. **/
- override val C: Double get() = chroma
- /** Alias for [hue]. **/
- override val h: Double get() = hue
-
/**
* Convert this color to the CIE XYZ color space, with absolute luminance.
*
diff --git a/src/commonMain/kotlin/dev/kdrag0n/colorkt/gamut/LchGamut.kt b/src/commonMain/kotlin/dev/kdrag0n/colorkt/gamut/LchGamut.kt
index 6380901..b19fb40 100644
--- a/src/commonMain/kotlin/dev/kdrag0n/colorkt/gamut/LchGamut.kt
+++ b/src/commonMain/kotlin/dev/kdrag0n/colorkt/gamut/LchGamut.kt
@@ -124,19 +124,19 @@
alpha: Double = 0.05,
): LinearSrgb {
val l0 = when (method) {
- ClipMethod.PRESERVE_LIGHTNESS -> lightness
+ ClipMethod.PRESERVE_LIGHTNESS -> this.lightness
ClipMethod.PROJECT_TO_MID -> 50.0
ClipMethod.ADAPTIVE_TOWARDS_MID -> OklabGamut.calcAdaptiveMidL(
- L = lightness / 100.0,
- C = chroma / 100.0,
+ L = this.lightness / 100.0,
+ C = this.chroma / 100.0,
alpha = alpha,
) * 100.0
}
return clip(
- l1 = lightness,
- c1 = chroma,
- hue = hue,
+ l1 = this.lightness,
+ c1 = this.chroma,
+ hue = this.hue,
l0 = l0,
epsilon = EPSILON_100,
maxLightness = 100.0
diff --git a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/CieLch.kt b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/CieLch.kt
index c4a7f65..3da8c00 100644
--- a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/CieLch.kt
+++ b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/CieLch.kt
@@ -15,9 +15,9 @@
* @see dev.kdrag0n.colorkt.ucs.lch.Lch
*/
public data class CieLch @JvmOverloads constructor(
- override val L: Double,
- override val C: Double,
- override val h: Double,
+ override val lightness: Double,
+ override val chroma: Double,
+ override val hue: Double,
/**
* Reference white for CIELAB calculations. This affects the converted color.
@@ -31,7 +31,7 @@
* @return Color represented as CIELAB
*/
public fun toCieLab(): CieLab = CieLab(
- L = L,
+ L = lightness,
a = calcLabA(),
b = calcLabB(),
referenceWhite = referenceWhite,
@@ -53,9 +53,9 @@
@JvmStatic
@JvmName("fromCieLab")
public fun CieLab.toCieLch(): CieLch = CieLch(
- L = L,
- C = calcLchC(),
- h = calcLchH(),
+ lightness = L,
+ chroma = calcLchC(),
+ hue = calcLchH(),
referenceWhite = referenceWhite,
)
}
diff --git a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Lch.kt b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Lch.kt
index 49869b7..d247172 100644
--- a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Lch.kt
+++ b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Lch.kt
@@ -22,17 +22,17 @@
/**
* Perceived lightness component.
*/
- public val L: Double
+ public val lightness: Double
/**
* Chroma component (amount of color).
*/
- public val C: Double
+ public val chroma: Double
/**
* Hue angle component in degrees (which color, e.g. green/blue).
*/
- public val h: Double
+ public val hue: Double
}
@JvmSynthetic
@@ -44,6 +44,6 @@
}
@JvmSynthetic
-internal fun Lch.calcLabA() = C * cos(h.toRadians())
+internal fun Lch.calcLabA() = chroma * cos(hue.toRadians())
@JvmSynthetic
-internal fun Lch.calcLabB() = C * sin(h.toRadians())
+internal fun Lch.calcLabB() = chroma * sin(hue.toRadians())
diff --git a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Oklch.kt b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Oklch.kt
index 96adf35..8425b4f 100644
--- a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Oklch.kt
+++ b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Oklch.kt
@@ -12,9 +12,9 @@
* @see dev.kdrag0n.colorkt.ucs.lch.Lch
*/
public data class Oklch(
- override val L: Double,
- override val C: Double,
- override val h: Double,
+ override val lightness: Double,
+ override val chroma: Double,
+ override val hue: Double,
) : Lch {
/**
* Convert this color to the Cartesian (Lab) representation of Oklab.
@@ -23,7 +23,7 @@
* @return Color represented as Oklab
*/
public fun toOklab(): Oklab = Oklab(
- L = L,
+ L = lightness,
a = calcLabA(),
b = calcLabB(),
)
@@ -44,9 +44,9 @@
@JvmStatic
@JvmName("fromOklab")
public fun Oklab.toOklch(): Oklch = Oklch(
- L = L,
- C = calcLchC(),
- h = calcLchH(),
+ lightness = L,
+ chroma = calcLchC(),
+ hue = calcLchH(),
)
}
}
diff --git a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Srlch2.kt b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Srlch2.kt
index 6f667ef..67e19e3 100644
--- a/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Srlch2.kt
+++ b/src/commonMain/kotlin/dev/kdrag0n/colorkt/ucs/lch/Srlch2.kt
@@ -12,9 +12,9 @@
* @see dev.kdrag0n.colorkt.ucs.lch.Lch
*/
public data class Srlch2(
- override val L: Double,
- override val C: Double,
- override val h: Double,
+ override val lightness: Double,
+ override val chroma: Double,
+ override val hue: Double,
) : Lch {
/**
* Convert this color to the Cartesian (Lab) representation of SRLAB2.
@@ -23,7 +23,7 @@
* @return Color represented as SRLAB2
*/
public fun toSrlab2(): Srlab2 = Srlab2(
- L = L,
+ L = lightness,
a = calcLabA(),
b = calcLabB(),
)
@@ -44,9 +44,9 @@
@JvmStatic
@JvmName("fromSrlab2")
public fun Srlab2.toSrlch2(): Srlch2 = Srlch2(
- L = L,
- C = calcLchC(),
- h = calcLchH(),
+ lightness = L,
+ chroma = calcLchC(),
+ hue = calcLchH(),
)
}
}
diff --git a/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/GamutTests.kt b/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/GamutTests.kt
index bdc74c0..b441b3f 100644
--- a/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/GamutTests.kt
+++ b/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/GamutTests.kt
@@ -33,7 +33,7 @@
val lch = src.convert<Oklch>()
// Boost the chroma
- val clipped = lch.copy(C = lch.C * 5).toOklab().clipToLinearSrgb()
+ val clipped = lch.copy(chroma = lch.chroma * 5).toOklab().clipToLinearSrgb()
// Now check
assertApprox(clipped.r, srcLinear.r)
diff --git a/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/XyzTests.kt b/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/XyzTests.kt
index 25ee55f..1dd775d 100644
--- a/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/XyzTests.kt
+++ b/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/XyzTests.kt
@@ -17,9 +17,9 @@
val lch = Srgb(v, v, v).toLinear().toXyz().toCieLab().toCieLch()
println(lch)
- avgChroma += lch.C
- if (lch.C > maxChroma) {
- maxChroma = lch.C
+ avgChroma += lch.chroma
+ if (lch.chroma > maxChroma) {
+ maxChroma = lch.chroma
}
}
avgChroma /= 256