Skip to content

Commit

Permalink
Use correct vector space definitions
Browse files Browse the repository at this point in the history
- Undefines errorneous +, * on LCHUv
- Defines +, * on XYZ as a linear vector space
- Defines +, * on all other ColorValues using intermediate arithmetic in
  XYZ space
  • Loading branch information
jiahao committed Sep 29, 2014
1 parent 5ce3577 commit 12d14d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/colormaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ distinguishable_colors(n::Integer; kwargs...) = distinguishable_colors(n, Array(
cs::Vector{Float64},
hs::Vector{Float64}) distinguishable_colors(n, [seed], transform = transform, lchoices = ls, cchoices = cs, hchoices = hs)


# Small definitions to make color computations more clear
+(x::LCHuv, y::LCHuv) = LCHuv(x.l+y.l,x.c+y.c,x.h+y.h)
*(x::Real, y::LCHuv) = LCHuv(x*y.l,x*y.c,x*y.h)

# Sequential palette
# ----------------------
# Sequential_palette implements the color palette creation technique by
Expand Down
16 changes: 16 additions & 0 deletions src/colorspaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,19 @@ const CVconcrete = (HSV, HSL, XYZ, xyY, Lab, Luv, LCHab, LCHuv, DIN99, DIN99d, D
const CVparametric = tuple(RGB, CVconcrete...)
const CVfractional = (RGB, XYZ)
const CVfloatingpoint = (HSV, HSL, xyY, Lab, Luv, LCHab, LCHuv, DIN99, DIN99d, DIN99o, LMS)

# Vector space operations
import Base: +, *

#XYZ is a linear vector space
+{T}(a::XYZ{T}, b::XYZ{T}) = XYZ(a.x+b.x, a.y+b.y, a.z+b.z)
*{T}(c::T, a::XYZ{T}) = XYZ(c*a.x, c*a.y, c*a.z)
function *{S<:Real,T<:Real}(c::S, a::ColorValue{T})
U = promote_type(S,T)
convert(U,c) * convert(XYZ{U},a)
end

#Most of the rest aren't, so do the arithmetic in XYZ and convert back
+{T}(a::ColorValue{T}, b::ColorValue{T}) = convert(ColorValue{T}, convert(XYZ{T}, a) + convert(XYZ{T}, b))
*{T}(c::T, a::ColorValue{T}) = convert(ColorValue{T}, c * convert(XYZ{T}, a))

0 comments on commit 12d14d0

Please sign in to comment.