"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrangeOffset = exports.prunePose = exports.getPositionFromAccessor = exports.checkValidPose = void 0;
const utils_1 = require("@things-factory/utils");
function checkValidPose(name, position) {
    var sum = 0;
    for (var idx in position) {
        sum += position[idx];
    }
    if (isNaN(sum)) {
        throw new Error(`correct value position is not given for ${name} : ${position}`);
    }
}
exports.checkValidPose = checkValidPose;
function getPositionFromAccessor(name, accessor, data, logger) {
    var position = accessor ? (0, utils_1.access)(accessor, data) : {};
    logger.info(`${name}: ${accessor}, result: ${position}`);
    if (!position || typeof position !== 'object') {
        throw new Error(`correct type position is not given : ${position}`);
    }
    if (position instanceof Array) {
        position = {
            x: Number(position[0]),
            y: Number(position[1]),
            z: Number(position[2]),
            u: Number(position[3]),
            v: Number(position[4]),
            w: Number(position[5])
        };
    }
    return position;
}
exports.getPositionFromAccessor = getPositionFromAccessor;
function prunePose(name, position, logger) {
    var pruned = Object.assign({}, position);
    for (let k in pruned) {
        let v = pruned[k];
        if (isNaN(v) || v === null || v === '') {
            delete pruned[k];
        }
        else {
            pruned[k] = Number(pruned[k]);
        }
    }
    return pruned;
}
exports.prunePose = prunePose;
function arrangeOffset(offsetPose, logger) {
    var offsetResult = Object.assign({}, offsetPose);
    console.log('offsetResult: ', offsetResult);
    for (let k in offsetPose) {
        let v = offsetResult[k];
        if (isNaN(v) || v === null || v === '') {
            offsetResult[k] = 0;
        }
        else {
            offsetResult[k] = Number(offsetResult[k]);
        }
    }
    return offsetResult;
}
exports.arrangeOffset = arrangeOffset;
//# sourceMappingURL=util.js.map