ajalt / colormath

Multiplatform Kotlin color conversion and manipulation
https://ajalt.github.io/colormath/
MIT License
308 stars 21 forks source link

IllegalArgumentException when converting RGB to LAB #2

Closed arian closed 4 years ago

arian commented 4 years ago
        RGB(255,255, 255).toLAB()

This fails with

java.lang.IllegalArgumentException: l must be in interval [0, 100] in LAB(l=100.00000386666655, a=-1.6666666158293708E-5, b=6.666666463317483E-6, alpha=1.0)

    at com.github.ajalt.colormath.LAB.<init>(LAB.kt:15)
    at com.github.ajalt.colormath.XYZ.toLAB(XYZ.kt:58)
    at com.github.ajalt.colormath.RGB.toLAB(RGB.kt:168)

It's likely because of the rounding errors of the floats. Maybe use coerceAtMost in the toLAB method?

ajalt commented 4 years ago

Thanks for the report!