@@ -25,9 +25,9 @@ function generate_sample_grid_prs(
2525 rng= - 1
2626):: Vector{T} where {T}
2727 rng = getRNG (rng)
28- g = weighted_interaction_graph (pp; rng= rng)
2928
30- cells = initialize_cells (pp, LG. nv (g))
29+ g = weighted_interaction_graph (pp; rng= rng)
30+ cells = initialize_cells (pp)
3131 resample_indices = Set (1 : length (cells))
3232
3333 while ! isempty (resample_indices)
@@ -47,7 +47,17 @@ function weighted_interaction_graph(
4747 rng= - 1
4848):: SWG.SimpleWeightedGraph
4949 rng = getRNG (rng)
50- g = SWG. SimpleWeightedGraph (king_graph (ceil (Int, inv (pp. r))))
50+
51+ window_ = window (pp)
52+ g = SWG. SimpleWeightedGraph ()
53+ nb_cells_x = nb_cells_y = 1
54+ if allequal (window_. w)
55+ nb_cells_x = ceil (Int, window_. w[1 ] / pp. r)
56+ g = SWG. SimpleWeightedGraph (king_graph (nb_cells_x))
57+ else
58+ nb_cells_x, nb_cells_y = ceil .(Int, window_. w ./ pp. r)
59+ g = SWG. SimpleWeightedGraph (king_graph (nb_cells_x, nb_cells_y))
60+ end
5161 for e in LG. edges (g)
5262 i, j = Tuple (e)
5363 @inbounds g. weights[i, j] = g. weights[j, i] = rand (rng, weighttype (g))
@@ -144,14 +154,21 @@ end
144154
145155function initialize_cells (
146156 spp:: AbstractSpatialPointProcess{T} ,
147- size:: Integer
148157):: Vector{SpatialCellGridPRS{T}} where {T}
149- cells = Vector {SpatialCellGridPRS{T}} (undef, size)
150- k = ceil (Int, inv (spp. r))
158+ dimension (spp) != 2 && throw (DomainError (spp, " must be 2D point process for now" ))
159+ window_ = window (spp)
160+ nb_cells_x = nb_cells_y = 1
161+ if allequal (window_. w) # SquareWindow
162+ nb_cells_x = nb_cells_y = ceil (Int, window_. w[1 ] / spp. r)
163+ else
164+ nb_cells_x, nb_cells_y = ceil .(Int, window_. w ./ spp. r)
165+ end
166+
167+ cells = Vector {SpatialCellGridPRS{T}} (undef, nb_cells_x * nb_cells_y)
151168 for i in eachindex (cells)
152- c_y, c_x = divrem (i- 1 , k)
153- c = spp . window . c + spp. r .* [c_x, c_y]
154- win_i = rectangle_square_window (c, min . (spp. r, spp . window . w .- c ))
169+ c_ij = divrem (i- 1 , nb_cells_x) # coordinate (i, j) of the cell in the grid
170+ c_xy = @. window_ . c + spp. r * c_ij
171+ win_i = rectangle_square_window (c_xy, @. min (spp. r, window_ . w - c_xy ))
155172 cells[i] = SpatialCellGridPRS (win_i, T[])
156173 end
157174 return cells
0 commit comments