Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit 3ec3e1b

Browse files
committed
Fix cluster process
1 parent 77cfe64 commit 3ec3e1b

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/processes/cluster.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,11 @@ function randsingle(rng::Random.AbstractRNG, p::ClusterProcess, g)
7171
parents = rand(rng, p.proc, g)
7272

7373
# generate offsprings
74-
offsprings = p.ofun.(parents)
74+
offsprings = filter(!isnothing, p.ofun.(parents))
7575

76-
# combine offsprings into single set
77-
points = mapreduce(vcat, offsprings) do pset
78-
isnothing(pset) ? Point{Dim,T}[] : collect(pset g)
79-
end
76+
# intersect with geometry
77+
intersects = filter(!isnothing, [o g for o in offsprings])
8078

81-
# return point pattern
82-
PointSet(points)
79+
# combine offsprings into single set
80+
isempty(intersects) ? nothing : PointSet(mapreduce(collect, vcat, intersects))
8381
end

test/processes.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,28 @@
5858
@testset "Inhibition" begin end
5959

6060
@testset "Cluster" begin
61+
binom = BinomialProcess(100)
62+
poisson = PoissonProcess(100.0)
63+
procs = [binom, poisson]
64+
6165
ofun1 = parent -> rand(BinomialProcess(10), Ball(parent, 0.2))
6266
ofun2 = parent -> rand(PoissonProcess(100), Ball(parent, 0.2))
6367
ofun3 = parent -> rand(PoissonProcess(x -> 100 * sum((x - parent).^2)), Ball(parent, 0.5))
6468
ofun4 = parent -> PointSet(sample(Sphere(parent, 0.1), RegularSampling(10)))
6569
ofuns = [ofun1, ofun2, ofun3, ofun4]
70+
71+
box = Box((0.0, 0.0), (4.0, 4.0))
72+
ball = Ball((1.0, 1.0), 2.25)
73+
tri = Triangle((0.0, 0.0), (5.65, 0.0), (5.65, 5.65))
74+
grid = CartesianGrid((0, 0), (4, 4), dims=(10, 10))
75+
geoms = [box, ball, tri, grid]
76+
6677
for p in procs, ofun in ofuns, g in geoms
6778
cp = ClusterProcess(p, ofun)
6879
pp = rand(cp, g)
69-
@test all((g), pp)
80+
if !isnothing(pp)
81+
@test all((g), pp)
82+
end
7083
end
7184
end
7285

0 commit comments

Comments
 (0)