import { assert } from "../../assert.js";
import { max2 } from "../max2.js";
import { min2 } from "../min2.js";

/**
 * Returns a number representing overlap distance between two 1D line segments.
 * Positive number indicates overlap, negative number indicates that segments do not overlap; 0 indicates that segments are touching.
 * @param {number} a0
 * @param {number} a1
 * @param {number} b0
 * @param {number} b1
 * @returns {number}
 */
export function separation1D(a0, a1, b0, b1) {
    assert.isNumber(a0, "a0");
    assert.isNumber(a1, "a1");
    assert.isNumber(b0, "b0");
    assert.isNumber(b1, "b1");

    return min2(a1, b1) - max2(a0, b0);
}
