/**
 *
 * @param {number} a0_x
 * @param {number} a0_y
 * @param {number} a1_x
 * @param {number} a1_y
 * @param {number} b0_x
 * @param {number} b0_y
 * @param {number} b1_x
 * @param {number} b1_y
 * @returns {boolean} True if segments intersect, False otherwise
 * @public
 */
export function line_segment_line_segment_intersection_exists_2d(a0_x, a0_y, a1_x, a1_y, b0_x, b0_y, b1_x, b1_y) {
    const s1_x = a1_x - a0_x;
    const s1_y = a1_y - a0_y;
    const s2_x = b1_x - b0_x;
    const s2_y = b1_y - b0_y;

    const dy_02 = a0_y - b0_y;
    const dx_02 = a0_x - b0_x;

    const inv_denom = 1 / (-s2_x * s1_y + s1_x * s2_y);

    const s = (-s1_y * dx_02 + s1_x * dy_02) * inv_denom;
    const t = (s2_x * dy_02 - s2_y * dx_02) * inv_denom;

    return s >= 0 && s <= 1 && t >= 0 && t <= 1;
}
