|
1 | | -// eslint-disable-next-line @typescript-eslint/ban-ts-comment |
2 | | -// @ts-ignore No types |
3 | 1 | import PoissonDiskSampling from 'poisson-disk-sampling' |
4 | 2 |
|
5 | 3 | export const generatePoints = (height: number, width: number, size: number) => { |
6 | 4 | const sample = new PoissonDiskSampling({ |
7 | | - shape: [height, width], |
| 5 | + shape: [Math.min(height, 2000), Math.min(width, 2000)], |
8 | 6 | minDistance: size, |
9 | 7 | maxDistance: size + (size * .5), |
10 | 8 | tries: 20, |
11 | 9 | }) |
12 | 10 |
|
13 | | - const points: [number, number][] = sample.fill() |
| 11 | + // Area to avoid in the centre |
| 12 | + const avoid = { |
| 13 | + y: sample.shape[0] / 2, |
| 14 | + x: sample.shape[1] / 2, |
| 15 | + r: size * 1.5, // radius |
| 16 | + } |
| 17 | + |
| 18 | + const points = sample.fill() |
14 | 19 |
|
15 | 20 | return points |
16 | | - .map(([y, x]) => [(y / height) * 100, (x / width) * 100] as [number, number]) |
17 | | - .filter(([y, x]) => !(y > 30 && y < 70 && x > 40 && x < 60)) |
| 21 | + // Remove points from the avoidance area |
| 22 | + .filter(([y, x]) => Math.pow(avoid.y - y, 2) + Math.pow(avoid.x - x, 2) > Math.pow(avoid.r, 2)) |
| 23 | + // Convert to percentages |
| 24 | + .map(([y, x]) => [(y / sample.shape[0]) * 100, (x / sample.shape[1]) * 100] as [number, number]) |
18 | 25 | } |
0 commit comments