Flow accumulation: minor fix and simplification

This commit is contained in:
Gaël C 2024-01-22 11:44:47 +01:00
parent f350f8785c
commit 72e2f3e670
1 changed files with 10 additions and 16 deletions

View File

@ -447,31 +447,25 @@ local function accumulate(dirs, waterq)
-- This means: how many nodes will give their water to that given node, directly or indirectly?
-- This is obtained by following rivers downstream and summing up the flow of every tributary, starting with a value of 1 at the sources.
-- This will give non-zero values for every node but only large values will be considered to be rivers.
waterq = waterq or {}
local X, Y = dirs.X, dirs.Y
waterq = waterq or {X=X, Y=Y}
local ndonors = {}
local waterq = {X=X, Y=Y}
for i=1, X*Y do
ndonors[i] = 0
waterq[i] = 1
end
-- Calculate the number of direct donors
for i1=1, X*Y do
local i2
local dir = dirs[i1]
if dir == 1 then
i2 = i1+X
elseif dir == 2 then
i2 = i1+1
elseif dir == 3 then
i2 = i1-X
elseif dir == 4 then
i2 = i1-1
end
if i2 then
ndonors[i2] = ndonors[i2] + 1
for i=1, X*Y do
if dirs[i] == 1 then
ndonors[i+X] = ndonors[i+X] + 1
elseif dirs[i] == 2 then
ndonors[i+1] = ndonors[i+1] + 1
elseif dirs[i] == 3 then
ndonors[i-X] = ndonors[i-X] + 1
elseif dirs[i] == 4 then
ndonors[i-1] = ndonors[i-1] + 1
end
end