|
1 | 1 | @testset "Processes" begin |
| 2 | + # geometries and domains |
2 | 3 | seg = Segment((0.0, 0.0), (11.3, 11.3)) |
3 | 4 | tri = Triangle((0.0, 0.0), (5.65, 0.0), (5.65, 5.65)) |
4 | 5 | quad = Quadrangle((0.0, 0.0), (0.0, 4.0), (4.0, 4.0), (4.0, 0.0)) |
5 | 6 | box = Box((0.0, 0.0), (4.0, 4.0)) |
6 | 7 | ball = Ball((1.0, 1.0), 2.25) |
7 | | - outer = Point2[(0, -4), (4, -1), (4, 1.5), (0, 3)] |
8 | | - hole1 = Point2[(0.2, -0.2), (1.4, -0.2), (1.4, 0.6), (0.2, 0.6)] |
9 | | - hole2 = Point2[(2, -0.2), (3, -0.2), (3, 0.4), (2, 0.4)] |
| 8 | + outer = [(0, -4), (4, -1), (4, 1.5), (0, 3)] |
| 9 | + hole1 = [(0.2, -0.2), (1.4, -0.2), (1.4, 0.6), (0.2, 0.6)] |
| 10 | + hole2 = [(2, -0.2), (3, -0.2), (3, 0.4), (2, 0.4)] |
10 | 11 | poly = PolyArea(outer, [hole1, hole2]) |
11 | 12 | grid = CartesianGrid((0, 0), (4, 4), dims=(10, 10)) |
12 | 13 | points = Point2[(0, 0), (4.5, 0), (0, 4.2), (4, 4.3), (1.5, 1.5)] |
13 | 14 | connec = connect.([(1, 2, 5), (2, 4, 5), (4, 3, 5), (3, 1, 5)], Triangle) |
14 | 15 | mesh = SimpleMesh(points, connec) |
| 16 | + geoms = [seg, tri, quad, box, ball, poly, grid, mesh] |
| 17 | + |
| 18 | + # point processes |
| 19 | + λ(s) = sum(coordinates(s) .^ 2) |
| 20 | + binom = BinomialProcess(100) |
| 21 | + poisson1 = PoissonProcess(100.0) |
| 22 | + poisson2 = PoissonProcess(λ) |
| 23 | + procs = [binom, poisson1, poisson2] |
15 | 24 |
|
16 | 25 | @testset "Basic" begin |
17 | | - for p in [BinomialProcess(100), PoissonProcess(100.0)] |
18 | | - b = Box((0.0, 1.0), (1.0, 2.0)) |
19 | | - pp = rand(p, b) |
20 | | - xs = coordinates.(pp) |
21 | | - @test all(0 .≤ first.(xs) .≤ 1) |
22 | | - @test all(1 .≤ last.(xs) .≤ 2) |
| 26 | + for p in procs, g in geoms |
| 27 | + pp = rand(p, g) |
| 28 | + @test all(∈(g), pp) |
23 | 29 | end |
24 | 30 | end |
25 | 31 |
|
26 | 32 | @testset "Binomial" begin |
27 | 33 | p = BinomialProcess(10) |
28 | | - for g in [seg, tri, quad, box, ball, poly, grid, mesh] |
| 34 | + for g in geoms |
29 | 35 | pp = rand(p, g) |
30 | 36 | @test nelements(pp) == 10 |
31 | | - @test all(∈(g), pp) |
32 | 37 | end |
33 | 38 | end |
34 | 39 |
|
35 | 40 | @testset "Poisson" begin |
36 | | - # helper function |
37 | | - λ(s::Point2) = sum(coordinates(s) .^ 2) |
38 | | - |
39 | | - # homogeneous |
40 | | - p = PoissonProcess(10.0) |
41 | | - for g in [seg, tri, quad, box, ball, poly, grid, mesh] |
42 | | - pp = rand(p, g) |
43 | | - @test all(∈(g), pp) |
44 | | - end |
45 | | - |
46 | | - # inhomogeneous with intensity function |
47 | | - p = PoissonProcess(λ) |
48 | | - for g in [seg, tri, quad, box, ball, poly, grid, mesh] |
49 | | - pp = rand(p, g) |
50 | | - @test all(∈(g), pp) |
51 | | - |
52 | | - pp = rand(p, g, algo=LewisShedler(λ(Point2(12.0, 12.0)))) |
53 | | - @test all(∈(g), pp) |
54 | | - |
55 | | - g = discretize(g) |
56 | | - pp = rand(p, g, algo=ConstantIntensity()) |
57 | | - @test all(∈(g), g) |
58 | | - end |
59 | | - |
60 | 41 | # inhomogeneous with piecewise constant intensity |
61 | 42 | for g in [grid, mesh] |
62 | 43 | λvec = λ.(centroid.(g)) |
63 | 44 | p = PoissonProcess(λvec) |
64 | | - # discretizedsampling by default |
65 | 45 | pp = rand(p, g) |
66 | 46 | @test all(∈(g), pp) |
67 | 47 | end |
68 | 48 |
|
69 | 49 | # empty pointsets |
70 | | - for g in [seg, tri, quad, box, ball, poly, grid, mesh] |
| 50 | + for g in geoms |
71 | 51 | @test isnothing(rand(PoissonProcess(0.0), seg)) |
72 | 52 | end |
73 | | - ps = PointSet(rand(Point2, 10)) |
74 | | - @test isnothing(rand(PoissonProcess(100.0), ps)) |
| 53 | + pp = PointSet(rand(Point2, 10)) |
| 54 | + @test isnothing(rand(PoissonProcess(100.0), pp)) |
75 | 55 | end |
76 | 56 |
|
77 | 57 | @testset "Union" begin |
|
0 commit comments