-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add component iterator #260
Conversation
c1a13e9
to
0fd278c
Compare
Codecov Report
@@ Coverage Diff @@
## master #260 +/- ##
==========================================
+ Coverage 83.76% 83.80% +0.04%
==========================================
Files 8 8
Lines 733 735 +2
==========================================
+ Hits 614 616 +2
Misses 119 119
Continue to review full report at Codecov.
|
0fd278c
to
faded62
Compare
Base.axes(::ComponentIterator{C}) where {N, C <: ColorantN{N}} = (Base.OneTo(N),) | ||
Base.ndims(::Type{ComponentIterator{C}}) where {C} = 1 | ||
function Base.broadcastable(itr::ComponentIterator{C}) where {T, N, C <: Colorant{T, N}} | ||
(itr...,)::NTuple{N, T} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should return the iterator itself (itr
) instead of the tuple, but I don't know how to handle that well. 😕
faded62
to
f2058d6
Compare
This adds a component iterator as a private API. This re-implements the folding functions with the iterator.
f2058d6
to
a6f4d8d
Compare
@@ -126,3 +126,6 @@ coloralpha(c::C) where {C<:Color} = coloralpha(C)(c) | |||
coloralpha(c::C,a) where {C<:Color} = coloralpha(C)(c,a) | |||
coloralpha(c::C) where {C<:TransparentColor} = coloralpha(base_color_type(C))(color(c), alpha(c)) | |||
coloralpha(c::C,a) where {C<:TransparentColor} = coloralpha(base_color_type(C))(color(c), a) | |||
|
|||
# Tuple | |||
Tuple(c::Colorant{T, N}) where {T, N} = (comps(c)...,)::NTuple{N, T} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the recommended API that people should use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking, I don't think the Tuple
constructors are a part of public APIs because they don't have docstrings.
However, I don't see a problem with ColorVectorSpace.jl etc. using it internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, some people might argue that Colorant
is never iterable.
julia> Tuple(0.5 + 0.5im) # Should `Colorant` really be like `Complex`?
(0.5 + 0.5im,)
However, since the design of tuple()
and Tuple()
are clearly different, I don't think there will be any confusion.
julia> Tuple(1:3)
(1, 2, 3)
julia> tuple(1:3)
(1:3,)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally in favor of the Tuple(::Colorant)
usage. It's kind of like CartesianIndex
, that you can't iterate it but can easily construct an iterable tuple from Tuple
or x.I
.
There is still a lot of room for discussion and improvement, but the iteration feature is useful for addressing the rest of the issues, so I will merge this first. |
This reverts commit bd4bad2.
This adds a component iterator as a "private" API.
This re-implements the folding functions with the iterator.
cf. #190, #247