mirror of
https://github.com/Findus23/rebound-collisions.git
synced 2024-09-19 15:53:48 +02:00
29 lines
788 B
Python
29 lines
788 B
Python
|
from ctypes import c_uint32
|
||
|
from pathlib import Path
|
||
|
from random import randint
|
||
|
from sys import argv
|
||
|
|
||
|
|
||
|
def unique_hash() -> c_uint32:
|
||
|
"""
|
||
|
returns a (hopefully) unique 32 bit integer to be used as a particle hash
|
||
|
|
||
|
when a collision occurs and ruins the output data, please complain to the universe
|
||
|
"""
|
||
|
return c_uint32(randint(0, 2 ** 32 - 1))
|
||
|
|
||
|
|
||
|
def clamp(n: float, smallest: float, largest: float) -> float:
|
||
|
assert smallest < largest
|
||
|
return max(smallest, min(n, largest))
|
||
|
|
||
|
|
||
|
def filename_from_argv() -> Path:
|
||
|
if len(argv) < 2:
|
||
|
raise ValueError("specify filename")
|
||
|
fn = argv[1]
|
||
|
fn = fn.replace(".bin", "").replace(".meta.json", "")
|
||
|
if fn.endswith("."):
|
||
|
fn = fn[:-1]
|
||
|
return Path(fn.replace(".bin", "").replace(".meta.json", ""))
|