text: import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
  import _createClass from "@babel/runtime/helpers/esm/createClass";
  import { Vector3, Matrix4 } from 'math.gl';
  import * as mat4 from 'gl-matrix/mat4';
  import { Intersect } from '../constants';
  var scratchVector = new Vector3();
  var scratchVector2 = new Vector3();
  
  var BoundingSphere = function () {
    function BoundingSphere() {
      var center = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 0];
      var radius = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.0;
  
      _classCallCheck(this, BoundingSphere);
  
      this.radius = -0;
      this.center = new Vector3();
      this.fromCenterRadius(center, radius);
    }
  
    _createClass(BoundingSphere, [{
      key: "fromCenterRadius",
      value: function fromCenterRadius(center, radius) {
        this.center.from(center);
        this.radius = radius;
        return this;
      }
    }, {
      key: "fromCornerPoints",
      value: function fromCornerPoints(corner, oppositeCorner) {
        oppositeCorner = scratchVector.from(oppositeCorner);
        this.center = new Vector3().from(corner).add(oppositeCorner).scale(0.5);
        this.radius = this.center.distance(oppositeCorner);
        return this;
      }
    }, {
      key: "equals",
      value: function equals(right) {
        return this === right || Boolean(right) && this.center.equals(right.center) && this.radius === right.radius;
      }
    }, {
      key: "clone",
      value: function clone() {
        return new BoundingSphere(this.center, this.radius);
      }
    }, {
      key: "union",
      value: function union(boundingSphere) {
        var leftCenter = this.center;
        var leftRadius = this.radius;
        var rightCenter = boundingSphere.center;
        var rightRadius = boundingSphere.radius;
        var toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter);
        var centerSeparation = toRightCenter.magnitude();
  
        if (leftRadius >= centerSeparation + rightRadius) {
          return this.clone();
        }
  
        if (rightRadius >= centerSeparation + leftRadius) {
          return boundingSphere.clone();
        }
  
        var halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;
        scratchVector2.copy(toRightCenter).scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation).add(leftCenter);
        this.center.copy(scratchVector2);
        this.radius = halfDistanceBetweenTangentPoints;
        return this;
      }
    }, {
      key: "expand",
      value: function expand(point) {
        point = scratchVector.from(point);
        var radius = point.subtract(this.center).magnitude();
  
        if (radius > this.radius) {
          this.radius = radius;
        }
  
        return this;
      }
    }, {
      key: "intersectPlane",
      value: function intersectPlane(plane) {
        var center = this.center;
        var radius = this.radius;
        var normal = plane.normal;
        var distanceToPlane = normal.dot(center) + plane.distance;
  
        if (distanceToPlane < -radius) {
          return Intersect.OUTSIDE;
        }
  
        if (distanceToPlane < radius) {
          return Intersect.INTERSECTING;
        }
  
        return Intersect.INSIDE;
      }
    }, {
      key: "transform",
      value: function transform(_transform) {
        this.center.transform(_transform);
        var scale = mat4.getScaling(scratchVector, _transform);
        this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;
        return this;
      }
    }, {
      key: "distanceSquaredTo",
      value: function distanceSquaredTo(point) {
        point = scratchVector.from(point);
        var delta = point.subtract(this.center);
        return delta.lengthSquared() - this.radius * this.radius;
      }
    }, {
      key: "distanceTo",
      value: function distanceTo(point) {
        return Math.sqrt(this.distanceSquaredTo(point));
      }
    }]);
  
    return BoundingSphere;
  }();
  
  export { BoundingSphere as default };
  //# sourceMappingURL=bounding-sphere.js.map