tweak
This commit is contained in:
parent
47af930e18
commit
e1bb10ff8a
12 changed files with 1336 additions and 526 deletions
17
entitySelection.js
Normal file
17
entitySelection.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { hash2 } from "./random.js";
|
||||
|
||||
export function pickEntities(candidates, { max = 99, minDistance = 5, threshold = 0, seed = 0, jitter = 0.04 } = {}) {
|
||||
const sorted = candidates
|
||||
.filter((p) => Number.isFinite(p.score) && p.score >= threshold)
|
||||
.map((p) => ({ ...p, score: p.score + hash2(p.x, p.y, seed + 54321) * jitter }))
|
||||
.sort((a, b) => b.score - a.score);
|
||||
|
||||
const out = [];
|
||||
for (const candidate of sorted) {
|
||||
if (out.every((p) => Math.hypot(p.x - candidate.x, p.y - candidate.y) >= minDistance)) {
|
||||
out.push(candidate);
|
||||
if (out.length >= max) break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue