import { euclidean_modulo } from "./euclidean_modulo.js";

/**
 *
 * @param {number} x
 * @param {number} length
 * @return {number}
 */
export function pingpong(x, length = 1) {
    return length - Math.abs(euclidean_modulo(x, length * 2) - length);
}
