"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ig_gfx_core_1 = require("@intelligentgraphics/ig.gfx.core");
var roundToMM = function (value) { return Math.round(value * 1000) / 1000; };
/**
 * Provides the dimensions of elements inside of the graphical scene
 *
 * @export
 * @class SceneDimensionsProvider
 * @implements {IMeasurementDimensionsProvider}
 */
var MeasurementSceneDimensionsProvider = /** @class */ (function () {
    function MeasurementSceneDimensionsProvider(api) {
        this.api = api;
    }
    MeasurementSceneDimensionsProvider.prototype.getGroupDimensions = function (articles) {
        var e_1, _a;
        var bounds = ig_gfx_core_1.createBounds();
        try {
            for (var articles_1 = tslib_1.__values(articles), articles_1_1 = articles_1.next(); !articles_1_1.done; articles_1_1 = articles_1.next()) {
                var gfxId = articles_1_1.value.gfxId;
                var articleBounds = this.api.GetBounds(gfxId, "World");
                ig_gfx_core_1.extendBounds(bounds, articleBounds.min);
                ig_gfx_core_1.extendBounds(bounds, articleBounds.max);
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (articles_1_1 && !articles_1_1.done && (_a = articles_1.return)) _a.call(articles_1);
            }
            finally { if (e_1) throw e_1.error; }
        }
        return this.createDimensions(bounds);
    };
    MeasurementSceneDimensionsProvider.prototype.getArticleDimensions = function (article) {
        var bounds = this.api.GetBounds(article.gfxId, "World");
        return this.createDimensions(bounds);
    };
    MeasurementSceneDimensionsProvider.prototype.createDimensions = function (bounds) {
        return {
            width: roundToMM(bounds.max.x - bounds.min.x),
            height: roundToMM(bounds.max.y - bounds.min.y),
            depth: roundToMM(bounds.max.z - bounds.min.z),
        };
    };
    return MeasurementSceneDimensionsProvider;
}());
exports.MeasurementSceneDimensionsProvider = MeasurementSceneDimensionsProvider;
