Imported from https://github.com/MathPhysSim/PER-NAF