mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2025-01-01 05:50:34 +01:00
Use standard int instead of uint8, int32, etc.
Much faster with NumPy.
This commit is contained in:
parent
faef1658a9
commit
40098d6be3
@ -71,8 +71,8 @@ class EvolutionModel:
|
|||||||
self.calculate_flow()
|
self.calculate_flow()
|
||||||
else:
|
else:
|
||||||
self.lakes = dem
|
self.lakes = dem
|
||||||
self.dirs = np.zeros(dem.shape, dtype='u1')
|
self.dirs = np.zeros(dem.shape, dtype=int)
|
||||||
self.rivers = np.zeros(dem.shape, dtype='u4')
|
self.rivers = np.zeros(dem.shape, dtype=int)
|
||||||
self.flow_uptodate = False
|
self.flow_uptodate = False
|
||||||
|
|
||||||
def calculate_flow(self):
|
def calculate_flow(self):
|
||||||
|
@ -14,7 +14,7 @@ neighbours_dirs = np.array([
|
|||||||
[0,1,0],
|
[0,1,0],
|
||||||
[2,0,4],
|
[2,0,4],
|
||||||
[0,3,0],
|
[0,3,0],
|
||||||
], dtype='u1')
|
], dtype=int)
|
||||||
|
|
||||||
neighbours_pattern = neighbours_dirs > 0
|
neighbours_pattern = neighbours_dirs > 0
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ def flow_dirs_lakes(dem, random=0):
|
|||||||
# Make a binary heap
|
# Make a binary heap
|
||||||
heapq.heapify(borders)
|
heapq.heapify(borders)
|
||||||
|
|
||||||
dirs = np.zeros((Y+2, X+2), dtype='u1')
|
dirs = np.zeros((Y+2, X+2), dtype=int)
|
||||||
dirs[-2:,:] = 1 # Border pixels flow outside the map
|
dirs[-2:,:] = 1 # Border pixels flow outside the map
|
||||||
dirs[:,-2:] = 2
|
dirs[:,-2:] = 2
|
||||||
dirs[ :2,:] = 3
|
dirs[ :2,:] = 3
|
||||||
@ -85,7 +85,7 @@ def accumulate(dirs, dem=None):
|
|||||||
(Y, X) = dirs.shape
|
(Y, X) = dirs.shape
|
||||||
dirs_margin = np.zeros((Y+2,X+2))-1
|
dirs_margin = np.zeros((Y+2,X+2))-1
|
||||||
dirs_margin[1:-1,1:-1] = dirs
|
dirs_margin[1:-1,1:-1] = dirs
|
||||||
quantity = np.zeros((Y, X), dtype='i4')
|
quantity = np.zeros((Y, X), dtype=int)
|
||||||
|
|
||||||
def calculate_quantity(y, x):
|
def calculate_quantity(y, x):
|
||||||
if quantity[y,x] > 0:
|
if quantity[y,x] > 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user