import { vec3 } from "gl-matrix";
import { GetTexCoord } from "./GetTexCoord.js";

const t1 = vec3.create();
const t2 = vec3.create();
const t3 = vec3.create();

/**
 * returns the texture area times 2
 * @param {SMikkTSpaceContext } pContext
 * @param {number[]} indices
 * @param {number} indices_offset
 * @returns {number}
 */
export function CalcTexArea(pContext, indices, indices_offset) {

    GetTexCoord(t1, pContext, indices[indices_offset ]);
    GetTexCoord(t2, pContext, indices[indices_offset + 1]);
    GetTexCoord(t3, pContext, indices[indices_offset + 2]);

    const t21x = t2[0] - t1[0];
    const t21y = t2[1] - t1[1];

    const t31x = t3[0] - t1[0];
    const t31y = t3[1] - t1[1];

    const fSignedAreaSTx2 = t21x * t31y - t21y * t31x;

    return Math.abs(fSignedAreaSTx2);
}
