/** @internal NOTE: Internal APIs. Subject to change. Use of these APIs in production applications is not supported. */ /** */
import { Camera } from '../loader/babylonjs-import';
/**
 * Calculates icon size. Used by {@link IconHandler} to calculate the size
 * a icon shall be rendered with.
 */
export class IconSizeCalculator {
    _atFovK;
    options;
    constructor(o) {
        this.options = {
            resolution: o?.resolution ?? 1000,
            atFov: o?.atFov ?? 0.8
        };
        this._atFovK = Math.tan(this.options.atFov / 2);
    }
    /**
     * Get icon size
     * @param iconLength side of the icon
     * @param camera camera the icon will be rendered with
     * @param renderTargetSize size of the render target that the icon will be rendered to.
     * @returns Size of icon to use when rendering.
     */
    get(iconLength, camera, renderTargetSize) {
        if (camera.mode === Camera.ORTHOGRAPHIC_CAMERA) {
            const orthoSize = camera.twinfinity.getOrthoFrustumSizeToRef({ x: 0, y: 0 });
            const size = {
                width: this.calcOrthoCamera(iconLength, renderTargetSize.width, orthoSize.x),
                height: this.calcOrthoCamera(iconLength, renderTargetSize.height, orthoSize.y)
            };
            const magicNumber = 70;
            return Math.round(Math.min(size.width, size.height)) / magicNumber;
        }
        else {
            const size = {
                width: this.calcPerspectiveCamera(iconLength, renderTargetSize.width, camera.fov),
                height: this.calcPerspectiveCamera(iconLength, renderTargetSize.height, camera.fov)
            };
            const magicNumber = 16;
            return Math.round(Math.min(size.width, size.height)) * magicNumber;
        }
    }
    calcOrthoCamera(iconLength, renderTargetLen, orthoLen) {
        return (renderTargetLen * iconLength) / orthoLen;
    }
    calcPerspectiveCamera(iconLength, renderTargetLen, fov) {
        return ((renderTargetLen / this.options.resolution) * iconLength * this._atFovK) / Math.tan(fov / 2);
    }
}
//# sourceMappingURL=IconSizeCalculator.js.map