@@ -37,13 +37,13 @@ def from_random(size: _FloatSequence,
37
37
Seed coordinates in 3D space.
38
38
39
39
"""
40
- size_ = _np .array (size ,float )
40
+ size_ = _np .asarray (size ,float )
41
41
rng = _np .random .default_rng (rng_seed )
42
42
if cells is None :
43
43
coords = rng .random ((N_seeds ,3 )) * size_
44
44
else :
45
45
grid_coords = _grid_filters .coordinates0_point (cells ,size ).reshape (- 1 ,3 ,order = 'F' )
46
- coords = grid_coords [rng .choice (_np .prod (cells ),N_seeds , replace = False )] \
46
+ coords = grid_coords [rng .choice (_np .prod (cells ),N_seeds ,replace = False )] \
47
47
+ _np .broadcast_to (size_ / _np .array (cells ,_np .int64 ),(N_seeds ,3 ))* (rng .random ((N_seeds ,3 ))* .5 - .25 ) # wobble w/o leaving grid
48
48
49
49
return coords
@@ -81,24 +81,23 @@ def from_Poisson_disc(size: _FloatSequence,
81
81
Seed coordinates in 3D space.
82
82
83
83
"""
84
+ size_ = _np .asarray (size ,float )
84
85
rng = _np .random .default_rng (rng_seed )
85
86
coords = _np .empty ((N_seeds ,3 ))
86
- coords [0 ] = rng .random (3 ) * _np .array (size ,float )
87
87
88
- s = 1
88
+ s = 0
89
89
i = 0
90
- progress = _util .ProgressBar (N_seeds + 1 ,'' ,50 )
90
+ progress = _util .ProgressBar (N_seeds ,'' ,50 )
91
91
while s < N_seeds :
92
92
i += 1
93
- candidates = rng .random ((N_candidates ,3 ))* _np .broadcast_to (size ,(N_candidates ,3 ))
94
- tree = _spatial .cKDTree (coords [:s ],boxsize = size ) if periodic else \
95
- _spatial .cKDTree (coords [:s ])
96
- distances = tree .query (candidates )[0 ]
93
+ candidates = rng .random ((N_candidates ,3 ))* _np .broadcast_to (size_ ,(N_candidates ,3 ))
94
+ tree = _spatial .cKDTree (coords [:s ],boxsize = size_ if periodic else None )
95
+ distances = _np .asarray (tree .query (candidates )[0 ])
97
96
if distances .max () > distance : # require minimum separation
98
- i = 0
99
97
coords [s ] = candidates [distances .argmax ()] # maximum separation to existing point cloud
100
- s += 1
101
98
progress .update (s )
99
+ s += 1
100
+ i = 0
102
101
103
102
if i >= 100 :
104
103
raise ValueError ('seeding not possible' )
0 commit comments