@@ -188,12 +188,15 @@ copy(c::MathTypes) = c
188
188
abs (c:: MathTypes ) = mapc (abs, c)
189
189
norm (c:: MathTypes , p:: Real = 2 ) = (cc = channels (c); norm (cc, p)/ (p == 0 ? length (cc) : length (cc)^ (1 / p)))
190
190
(⊙ )(a:: C , b:: C ) where {C<: MathTypes } = mapc (* , a, b)
191
+ (⋅ )(a:: C , b:: C ) where {C<: MathTypes } = throw (MethodError (dot, (a, b)))
192
+ (⊗ )(a:: C , b:: C ) where {C<: MathTypes } = throw (MethodError (tensor, (a, b)))
191
193
192
194
# # Mixed types
193
195
(+ )(a:: MathTypes , b:: MathTypes ) = (+ )(promote (a, b)... )
194
196
(- )(a:: MathTypes , b:: MathTypes ) = (- )(promote (a, b)... )
195
197
(⊙ )(a:: MathTypes , b:: MathTypes ) = (⊙ )(promote (a, b)... )
196
-
198
+ (⋅ )(a:: MathTypes , b:: MathTypes ) = (⋅ )(promote (a, b)... ) # not fully supported, but used for error hints
199
+ (⊗ )(a:: MathTypes , b:: MathTypes ) = (⊗ )(promote (a, b)... ) # not fully supported, but used for error hints
197
200
198
201
# Scalar RGB
199
202
(* )(f:: Real , c:: AbstractRGB ) = rettype (* , f, c)(f* red (c), f* green (c), f* blue (c))
220
223
(- )(a:: TransparentRGB , b:: TransparentRGB ) = rettype (- , a, b)(red (a)- red (b), green (a)- green (b), blue (a)- blue (b), alpha (a)- alpha (b))
221
224
222
225
# New multiplication operators
223
- (⋅ )(x:: AbstractRGB , y:: AbstractRGB ) = (T = acctype (eltype (x), eltype (y)); T (red (x))* T (red (y)) + T (green (x))* T (green (y)) + T (blue (x))* T (blue (y)))/ 3
224
- (⋅ )(x:: Union{AbstractRGB,AbstractGray} , y:: Union{AbstractRGB,AbstractGray} ) = ⋅ (promote (x, y)... )
226
+ function (⋅ )(x:: AbstractRGB , y:: AbstractRGB )
227
+ T = acctype (eltype (x), eltype (y))
228
+ (T (red (x))* T (red (y)) + T (green (x))* T (green (y)) + T (blue (x))* T (blue (y)))/ 3
229
+ end
225
230
# ⊗ defined below
226
231
227
232
@@ -384,7 +389,6 @@ function ⊗(a::AbstractRGB, b::AbstractRGB)
384
389
agbr, abbg, arbb, abbr, arbg, agbb = ag* br, ab* bg, ar* bb, ab* br, ar* bg, ag* bb
385
390
return RGBRGB (ar* br, agbr, abbr, arbg, ag* bg, abbg, arbb, agbb, ab* bb)
386
391
end
387
- ⊗ (a:: Union{AbstractRGB,AbstractGray} , b:: Union{AbstractRGB,AbstractGray} ) = ⊗ (promote (a, b)... )
388
392
389
393
"""
390
394
varmult(op, itr; corrected::Bool=true, mean=Statistics.mean(itr), dims=:)
@@ -432,6 +436,26 @@ function __init__()
432
436
# Color is not necessary, this is just to show it's possible.
433
437
A, B = argtypes
434
438
A != = B && print (io, " \n In binary operation with $A and $B , the return type is ambiguous" )
439
+ elseif exc. f === dot && length (argtypes) == 2
440
+ if any (C -> C <: Union{TransparentGray, TransparentRGB} , argtypes)
441
+ print (io, " \n `dot` (or `⋅`) for transparent colors is not supported " )
442
+ print (io, " because the normalization is designed for opaque grays and RGBs." )
443
+ print (io, " \n You can use `reducec(+, 0, mapc(float, a) ⊙ mapc(float, b))` " )
444
+ print (io, " to get the dot product without normalization." )
445
+ end
446
+ elseif exc. f === tensor && length (argtypes) == 2
447
+ if any (C -> C <: Union{TransparentGray, TransparentRGB} , argtypes)
448
+ print (io, " \n `tensor` (or `⊗`) for transparent colors is not supported " )
449
+ print (io, " due to the non-high demand." )
450
+ end
451
+ elseif exc. f === abs2 && length (argtypes) == 1
452
+ C = argtypes[1 ]
453
+ if C <: MathTypes
454
+ print (io, " \n It is ambiguous whether `abs2(::$C )` should return a real number " )
455
+ print (io, " or a color object." )
456
+ print (io, " \n You can use `_abs2(c) = mapreducec(v->float(v)^2, +, 0, c)` " )
457
+ print (io, " to get the value compatible with ColorVectorSpace v0.8 or earlier." )
458
+ end
435
459
end
436
460
end
437
461
end
0 commit comments