import { max3 } from "../../../math/max3.js";

/**
 * NOTE: The result is not a signed distance, any degree of penetration will produce 0 distance as a result
 * @param {number} x0
 * @param {number} y0
 * @param {number} x1
 * @param {number} y1
 * @param {number} px
 * @param {number} py
 * @returns {number}
 */
export function aabb2_distance_sqr_to_point(x0, y0, x1, y1, px, py) {

    const dx0 = x0 - px;
    const dx1 = px - x1;

    const dy0 = y0 - py;
    const dy1 = py - y1;

    const dx = max3(0, dx0, dx1);
    const dy = max3(0, dy0, dy1);

    return dx * dx + dy * dy;
}
