"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _classPrivateFieldGet2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldGet"));
var _classPrivateFieldSet2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldSet"));
var _three = require("three");
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } } // eslint-disable-next-line no-unused-vars
/**
 * C3DTFeature is a feature of a 3DTiles
 *
 * @class      C3DTFeature
 * @param {number} tileId - tileId
 * @param {number} batchId - batch id
 * @param {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
 * @param {object} info - info in the batchTable
 * @param {object} [userData] - some userData
 * @param {Object3D} object3d - object3d in which feature is present
 * @property {number} tileId - tile id
 * @property {Object3D} object3d - object3d in which feature is present
 * @property {number} batchId - batch id
 * @property {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
 * @property {object} info - info in the batchTable
 * @property {object} [userData] - some userData
 */
var _info = /*#__PURE__*/new WeakMap();
var C3DTFeature = /*#__PURE__*/function () {
  function C3DTFeature(tileId, batchId, groups, info, userData, object3d) {
    (0, _classCallCheck2["default"])(this, C3DTFeature);
    _classPrivateFieldInitSpec(this, _info, {
      writable: true,
      value: void 0
    });
    if (!object3d) {
      console.error('BREAKING CHANGE: C3DTFeature constructor changed from (tileId, batchId, groups, info, userData) to (tileId, batchId, groups, info, userData, object3d)');
    }

    /** @type {Object3D} */
    this.object3d = object3d;

    /** @type {number} */
    this.batchId = batchId;

    /** @type {Array<{start:number,count:number}>} */
    this.groups = groups;

    /** @type {object} */
    this.userData = userData;

    /** @type {object} */
    (0, _classPrivateFieldSet2["default"])(this, _info, info);

    /** @type {number} */
    this.tileId = tileId;
  }

  /**
   * Compute world box3 of this
   *
   * @param {Box3} target - target of the result
   * @returns {Box3}
   */
  (0, _createClass2["default"])(C3DTFeature, [{
    key: "computeWorldBox3",
    value: function computeWorldBox3() {
      var _this = this;
      var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new _three.Box3();
      // reset
      target.max.x = -Infinity;
      target.max.y = -Infinity;
      target.max.z = -Infinity;
      target.min.x = Infinity;
      target.min.y = Infinity;
      target.min.z = Infinity;
      this.groups.forEach(function (group) {
        var positionIndexStart = group.start * 3;
        var positionIndexCount = (group.start + group.count) * 3;
        for (var index = positionIndexStart; index < positionIndexCount; index += 3) {
          var x = _this.object3d.geometry.attributes.position.array[index];
          var y = _this.object3d.geometry.attributes.position.array[index + 1];
          var z = _this.object3d.geometry.attributes.position.array[index + 2];
          target.max.x = Math.max(x, target.max.x);
          target.max.y = Math.max(y, target.max.y);
          target.max.z = Math.max(z, target.max.z);
          target.min.x = Math.min(x, target.min.x);
          target.min.y = Math.min(y, target.min.y);
          target.min.z = Math.min(z, target.min.z);
        }
      });
      target.applyMatrix4(this.object3d.matrixWorld);
      return target;
    }

    /**
     *
     * @returns {object} - batchTable info
     */
  }, {
    key: "getInfo",
    value: function getInfo() {
      return (0, _classPrivateFieldGet2["default"])(this, _info);
    }
  }]);
  return C3DTFeature;
}();
var _default = C3DTFeature;
exports["default"] = _default;