JuliaAttic / Color.jl

Basic color manipulation utilities.
Other
47 stars 21 forks source link

Strange behavior trying to convert between colors #88

Closed habemus-papadum closed 9 years ago

habemus-papadum commented 9 years ago

Hi -- Here's a session that shows some weird behavior:

julia> using Color

#create a simple rgb
julia> r = RGB(.2, .3, .4)
RGB{Float64}(0.2,0.3,0.4)

#convert it to LCHAB
julia> l = convert(LCHab{Float64},r)
LCHab{Float64}(31.579833005156537,17.947883521730418,264.03896335685187)

#rotate LCHAB
julia> LCHab{Float64}(l.l,l.c,mod(l.h+180,360.0))
LCHab{Float64}(31.579833005156537,17.947883521730418,84.03896335685187)

##package above steps as a function
julia> function rotateColor(r)
           l = convert(LCHab{Float64},r)
           LCHab{Float64}(l.l,l.c,mod(l.h+180,360.0))
       end
rotateColor (generic function with 1 method)

## get very different results...
julia> rotateColor(r)
LCHab{Float64}(84.03896335685187,360.0,NaN)

Basically,if I perform things by hand everything works fine, but when I package everything into a function it breaks in a bizarre way...

As far as I can tell, this seems like a Julia issue that has nothing to do with Color.jl in particular, but I'm not positive. I might post an issue report there, but I figured I would start here....

thanks!

habemus-papadum commented 9 years ago

For whatever reason, changing the definition to

function rotateColor(r)
    l = convert(LCHab{Float64},r)
    convert(RGB,LCHab{Float64}(l.l,l.c,mod(l.h+180,360.0))) ## force conversion back to RGB
end

seems to fix the issue. Perhaps there is a broken compiler optimization somewhere....

jiahao commented 9 years ago

I can reproduce on 0.3.6 but not on 0.4-dev. Appears to be fixed in 0.4.

habemus-papadum commented 9 years ago

Thanks for looking into this -- Since I found a work around in v0.3.6 I'm good for now, but please let me know what I should do (close the issue and move on, raise it elsewhere so that others can investigate the root cause in case there might related issues not fully resolved in 0.4, etc) But in any case, thanks!

jiahao commented 9 years ago

Let's close this for now and we can revisit the issue if we find more odd behavior.