"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._treeComplexityByPath = exports.getSpecRadius = exports.getSpecComplexity = exports.UNIT_MIN_RADIUS = void 0;
const complexity_1 = require("../spec/complexity");
const spec_1 = require("./spec");
exports.UNIT_MIN_RADIUS = 14;
const _specComplexityCache = {};
const getSpecComplexity = (specs, classes, id, useCache = true) => {
    let c;
    if (useCache) {
        if (!_specComplexityCache[id]) {
            c = (0, exports.getSpecComplexity)(specs, classes, id, false);
        }
        c = _specComplexityCache[id];
    }
    else {
        c = (0, exports._treeComplexityByPath)(specs, classes, id);
    }
    _specComplexityCache[id] = c;
    return c;
};
exports.getSpecComplexity = getSpecComplexity;
const getSpecRadius = (specs, classes, id, useCache = true) => {
    const c = (0, exports.getSpecComplexity)(specs, classes, id, useCache);
    const R = exports.UNIT_MIN_RADIUS + Math.log2(c) / 3;
    const _R = Math.round(R); // important to return an integer
    return _R;
};
exports.getSpecRadius = getSpecRadius;
const _treeComplexityByPath = (specs, classes, path) => {
    const spec = (0, spec_1.getSpec)(specs, path);
    let c = spec.metadata && spec.metadata.complexity;
    if (c === undefined) {
        c = (0, complexity_1.treeComplexityById)(specs, classes, path);
    }
    return c;
};
exports._treeComplexityByPath = _treeComplexityByPath;
//# sourceMappingURL=complexity.js.map