okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221apps/host: the owner's UI and the Node App Host0b3299a01

main
696 B16 linesraw
1/** Pointer geometry is independent of pixel size and does not wrap at the gap. */
2export function dialAngle(x: number, y: number) {
3  return Math.atan2(x, -y) * 180 / Math.PI;
4}
5export function unwrapAngle(next: number, previous: number) {
6  let delta = next - previous;
7  while (delta > 180) delta -= 360;
8  while (delta < -180) delta += 360;
9  return previous + delta;
10}
11export function dialIndex(angle: number, count: number) {
12  return (Math.max(-135, Math.min(135, angle)) + 135) / 270 * Math.max(0, count - 1);
13}
14export function closestStop(value: number, stops: number[]) {
15  return stops.reduce((best, stop) => Math.abs(stop - value) < Math.abs(best - value) ? stop : best, stops[0]);
16}