diff --git a/pairsurrounding.jl b/pairsurrounding.jl index f2aa425..f900846 100644 --- a/pairsurrounding.jl +++ b/pairsurrounding.jl @@ -95,21 +95,20 @@ end function growcolour!(cmat::Matrix{Union{Colorant, Missing}}, metric::Colors.DifferenceMetric, refmat::Matrix{<:Colorant}, cnearest::Colorant, safethreshold::Float64, - pos::CartesianIndex{2}) - # @info "Growing $(pos.I)" - surrounding = Ref(pos) .+ CartesianIndex{2}.([(0, 1), (0, -1), (1, 0), (-1, 0)]) - filter!(s -> all((1,1) .<= s.I .<= size(refmat)), surrounding) - reseed = Vector{CartesianIndex{2}}() - for spos in surrounding - # @info " @ $(spos.I)" - if ismissing(cmat[spos]) && colordiff(cnearest, refmat[spos]; metric) < safethreshold - cmat[spos] = cnearest - push!(reseed, spos) + initalpos::CartesianIndex{2}) + seeds = [initalpos] + while !isempty(seeds) + pos = pop!(seeds) + surrounding = Ref(pos) .+ CartesianIndex{2}.([(0, 1), (0, -1), (1, 0), (-1, 0)]) + filter!(s -> all((1,1) .<= s.I .<= size(refmat)), surrounding) + for spos in surrounding + if ismissing(cmat[spos]) && + colordiff(cnearest, refmat[spos]; metric) < safethreshold + cmat[spos] = cnearest + push!(seeds, spos) + end end end - for spos in reseed - growcolour!(cmat, metric, refmat, cnearest, safethreshold, spos) - end end function colour_grid_hsl(xs, ys, saturation=1)