-
Notifications
You must be signed in to change notification settings - Fork 23
Closed
Description
The color_rettype has been around since the initial working commit of ColorVectorSpace, but now, I'm not sure what the point of it is.
ColorVectorSpace.jl/src/ColorVectorSpace.jl
Lines 76 to 82 in 85b8759
| # Scalar binary RGB operations require the same RGB type for each element, | |
| # otherwise we don't know which to return | |
| color_rettype(::Type{A}, ::Type{B}) where {A<:AbstractRGB,B<:AbstractRGB} = _color_rettype(base_colorant_type(A), base_colorant_type(B)) | |
| color_rettype(::Type{A}, ::Type{B}) where {A<:AbstractGray,B<:AbstractGray} = _color_rettype(base_colorant_type(A), base_colorant_type(B)) | |
| color_rettype(::Type{A}, ::Type{B}) where {A<:TransparentRGB,B<:TransparentRGB} = _color_rettype(base_colorant_type(A), base_colorant_type(B)) | |
| color_rettype(::Type{A}, ::Type{B}) where {A<:TransparentGray,B<:TransparentGray} = _color_rettype(base_colorant_type(A), base_colorant_type(B)) | |
| _color_rettype(::Type{C}, ::Type{C}) where {C<:Colorant} = C |
The revamp of the color promotion rules is relatively recent (i.e. it was in ColorTypes v0.10.0), but I think there is less ambiguity now. As you know, ColorVectorSpace v0.9 requires ColorTypes v0.10.
julia> RGB24(0.1, 0.2, 0.3) + RGB{Float32}(0.4, 0.5, 0.6)
ERROR: MethodError: no method matching _color_rettype(::Type{RGB24}, ::Type{RGB})
In binary operation with Type{RGB24} and Type{RGB}, the return type is ambiguous
julia> BGR(0.1, 0.2, 0.3) + RGB{N0f8}(0.4, 0.5, 0.6)
ERROR: MethodError: no method matching _color_rettype(::Type{BGR}, ::Type{RGB})
In binary operation with Type{BGR} and Type{RGB}, the return type is ambiguousjulia> promote_type(RGB24, RGB)
RGB
julia> promote_type(BGR, RGB)
RGBMetadata
Metadata
Assignees
Labels
No labels