/** @internal NOTE: Internal APIs. Subject to change. Use of these APIs in production applications is not supported. */ /** */

import { BimTransform } from '../loader/bim-format-types';
import { GeometryTransform, TransformType } from '@twinfinity/geometry';
import { Vertex3 } from './index';

export { TransformType } from '@twinfinity/geometry';

export class FastTransform extends GeometryTransform {
    public constructor(transform: BimTransform) {
        super(transform);
    }

    public static override identity(): FastTransform {
        return new FastTransform({
            x: 0,
            y: 0,
            z: 0,
            sx: 1,
            sy: 1,
            sz: 1,
            qw: 1,
            qx: 0,
            qy: 0,
            qz: 0
        });
    }

    public override translateToRef(center: Vertex3, dst: FastTransform): FastTransform;
    public override translateToRef(cx: number, cy: number, cz: number, dst: GeometryTransform): GeometryTransform;
    public override translateToRef(
        centerOrCx: Vertex3 | number,
        dstOrCy: FastTransform | number,
        cz?: number,
        dst?: GeometryTransform
    ): FastTransform | GeometryTransform {
        if (typeof centerOrCx === 'number') {
            return super.translateToRef(centerOrCx, dstOrCy as number, cz!, dst!);
        }
        return super.translateToRef(centerOrCx.x, centerOrCx.y, centerOrCx.z, dstOrCy as FastTransform);
    }

    public rotatePackedNormalInPlace(packedNormal: number, dst: Float32Array, dstOffset: number): void {
        if (this.type & TransformType.Rotation) {
            dst[dstOffset] = this.rotatePackedNormal(packedNormal);
        } else {
            dst[dstOffset] = packedNormal;
        }
    }

    public transformInPlaceVector3(x: number, y: number, z: number, dst: Vertex3): void {
        this.transformToVertex3(x, y, z, dst);
    }

    public static override transformToMatrixArray(t: BimTransform, dst: Float64Array, offset: number): void {
        GeometryTransform.transformToMatrixArray(t, dst, offset);
    }
}
