22 lines
694 B
JavaScript
22 lines
694 B
JavaScript
export function randomPointInCircle(origin, radiusPx) {
|
|
const angle = Math.random() * Math.PI * 2;
|
|
const distance = Math.sqrt(Math.random()) * radiusPx;
|
|
|
|
return {
|
|
x: origin.x + Math.cos(angle) * distance,
|
|
y: origin.y + Math.sin(angle) * distance
|
|
};
|
|
}
|
|
|
|
export function isWithinTeleportRadius(originCenter, candidateCenter, radiusPx) {
|
|
const dx = candidateCenter.x - originCenter.x;
|
|
const dy = candidateCenter.y - originCenter.y;
|
|
return Math.hypot(dx, dy) <= radiusPx;
|
|
}
|
|
|
|
export function sceneDistanceToPixels(distance) {
|
|
const gridSize = canvas.scene.grid.size;
|
|
const distancePerGrid = canvas.scene.grid.distance || 5;
|
|
return distance / distancePerGrid * gridSize;
|
|
}
|