text: "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 _math = require("math.gl");
  
  var _constants = require("../constants");
  
  var _plane = _interopRequireDefault(require("./plane"));
  
  var faces = [new _math.Vector3([1, 0, 0]), new _math.Vector3([0, 1, 0]), new _math.Vector3([0, 0, 1])];
  var scratchPlaneCenter = new _math.Vector3();
  var scratchPlaneNormal = new _math.Vector3();
  var scratchPlane = new _plane["default"](new _math.Vector3(1.0, 0.0, 0.0), 0.0);
  
  var CullingVolume = function () {
    (0, _createClass2["default"])(CullingVolume, null, [{
      key: "MASK_OUTSIDE",
      get: function get() {
        return 0xffffffff;
      }
    }, {
      key: "MASK_INSIDE",
      get: function get() {
        return 0x00000000;
      }
    }, {
      key: "MASK_INDETERMINATE",
      get: function get() {
        return 0x7fffffff;
      }
    }]);
  
    function CullingVolume() {
      var planes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      (0, _classCallCheck2["default"])(this, CullingVolume);
      this.planes = planes;
      (0, _math.assert)(this.planes.every(function (plane) {
        return plane instanceof _plane["default"];
      }));
    }
  
    (0, _createClass2["default"])(CullingVolume, [{
      key: "fromBoundingSphere",
      value: function fromBoundingSphere(boundingSphere) {
        this.planes.length = 2 * faces.length;
        var center = boundingSphere.center;
        var radius = boundingSphere.radius;
        var planeIndex = 0;
        var _iteratorNormalCompletion = true;
        var _didIteratorError = false;
        var _iteratorError = undefined;
  
        try {
          for (var _iterator = faces[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
            var faceNormal = _step.value;
            var plane0 = this.planes[planeIndex];
            var plane1 = this.planes[planeIndex + 1];
  
            if (!plane0) {
              plane0 = this.planes[planeIndex] = new _plane["default"]();
            }
  
            if (!plane1) {
              plane1 = this.planes[planeIndex + 1] = new _plane["default"]();
            }
  
            var plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);
            var plane0Distance = -faceNormal.dot(plane0Center);
            plane0.fromPointNormal(plane0Center, faceNormal);
            var plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);
            var negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
            var plane1Distance = -negatedFaceNormal.dot(plane1Center);
            plane1.fromPointNormal(plane1Center, negatedFaceNormal);
            planeIndex += 2;
          }
        } catch (err) {
          _didIteratorError = true;
          _iteratorError = err;
        } finally {
          try {
            if (!_iteratorNormalCompletion && _iterator["return"] != null) {
              _iterator["return"]();
            }
          } finally {
            if (_didIteratorError) {
              throw _iteratorError;
            }
          }
        }
  
        return this;
      }
    }, {
      key: "computeVisibility",
      value: function computeVisibility(boundingVolume) {
        (0, _math.assert)(boundingVolume);
        var intersect = _constants.Intersect.INSIDE;
        var _iteratorNormalCompletion2 = true;
        var _didIteratorError2 = false;
        var _iteratorError2 = undefined;
  
        try {
          for (var _iterator2 = this.planes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
            var plane = _step2.value;
            var result = boundingVolume.intersectPlane(plane);
  
            switch (result) {
              case _constants.Intersect.OUTSIDE:
                return _constants.Intersect.OUTSIDE;
  
              case _constants.Intersect.INTERSECTING:
                intersect = _constants.Intersect.INTERSECTING;
                break;
  
              default:
            }
          }
        } catch (err) {
          _didIteratorError2 = true;
          _iteratorError2 = err;
        } finally {
          try {
            if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
              _iterator2["return"]();
            }
          } finally {
            if (_didIteratorError2) {
              throw _iteratorError2;
            }
          }
        }
  
        return intersect;
      }
    }, {
      key: "computeVisibilityWithPlaneMask",
      value: function computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
        (0, _math.assert)(boundingVolume, 'boundingVolume is required.');
        (0, _math.assert)(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');
  
        if (parentPlaneMask === CullingVolume.MASK_OUTSIDE || parentPlaneMask === CullingVolume.MASK_INSIDE) {
          return parentPlaneMask;
        }
  
        var mask = CullingVolume.MASK_INSIDE;
        var planes = this.planes;
  
        for (var k = 0; k < this.planes.length; ++k) {
          var flag = k < 31 ? 1 << k : 0;
  
          if (k < 31 && (parentPlaneMask & flag) === 0) {
            continue;
          }
  
          var plane = planes[k];
          var result = boundingVolume.intersectPlane(plane);
  
          if (result === _constants.Intersect.OUTSIDE) {
            return CullingVolume.MASK_OUTSIDE;
          } else if (result === _constants.Intersect.INTERSECTING) {
            mask |= flag;
          }
        }
  
        return mask;
      }
    }]);
    return CullingVolume;
  }();
  
  exports["default"] = CullingVolume;
  //# sourceMappingURL=culling-volume.js.map