Skip to content

Commit 1a8a670

Browse files
committed
Support middle on Gray
Gray is the only one with an order, so no other colorants make sense
1 parent 0d853b0 commit 1a8a670

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/ColorVectorSpace.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Base: conj, sin, cos, tan, sinh, cosh, tanh,
2828
gamma, lfact, frexp, modf, airy, airyai,
2929
airyprime, airyaiprime, airybi, airybiprime,
3030
besselj0, besselj1, bessely0, bessely1,
31-
eta, zeta, digamma, float
31+
eta, zeta, digamma, float, middle
3232

3333
export dotc
3434

@@ -202,6 +202,9 @@ for op in unaryOps
202202
@eval ($op)(c::AbstractGray) = $op(gray(c))
203203
end
204204

205+
middle(c::AbstractGray) = base_colorant_type(c)(middle(gray(c)))
206+
middle(x::C, y::C) where {C<:AbstractGray} = C(middle(gray(x), gray(y)))
207+
205208
(*)(f::Real, c::AbstractGray) = base_colorant_type(c){multype(typeof(f),eltype(c))}(f*gray(c))
206209
(*)(f::Real, c::TransparentGray) = base_colorant_type(c){multype(typeof(f),eltype(c))}(f*gray(c), f*alpha(c))
207210
(*)(c::AbstractGray, f::Real) = (*)(f, c)

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ end
118118

119119
@test typeof(float(Gray{N0f16}(0.5))) <: AbstractFloat
120120
@test quantile( Gray{N0f16}[0.0,0.5,1.0], 0.1) 0.10000152590218968
121+
@test middle(Gray(0.2)) === Gray(0.2)
122+
@test middle(Gray(0.2), Gray(0.4)) === Gray((0.2+0.4)/2)
121123
end
122124

123125
@testset "Comparisons with Gray" begin

0 commit comments

Comments
 (0)