import { m2_multiply } from "./m2_multiply.js";
import { m2_transpose } from "./m2_transpose.js";

/**
 * Check if m * m^T is close to the identity matrix.
 * @param {number[]} m
 * @param {number} [tolerance]
 * @returns {boolean}
 */
export function m2_is_orthogonal(m, tolerance = 1e-6) {

    const mt = m2_transpose([], m);
    const m_mt = [];

    m2_multiply(m_mt, m, mt);

    return (
        Math.abs(m_mt[0] - 1) < tolerance &&
        Math.abs(m_mt[1]) < tolerance &&
        Math.abs(m_mt[2]) < tolerance &&
        Math.abs(m_mt[3] - 1) < tolerance
    );
}