text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  var Point = /** @class */ (function () {
      function Point(x, y) {
          this.x = 0;
          this.y = 0;
          if (Array.isArray(x)) {
              this.x = (x[0]);
              this.y = (x[1]);
          }
          else {
              this.x = x;
              this.y = (y);
          }
      }
      Point.average = function (points) {
          if (!points.length) {
              return Point.empty;
          }
          var x = 0, y = 0;
          points.forEach(function (p) {
              x += p.x;
              y += p.y;
          });
          return new Point(x / points.length, y / points.length);
      };
      Point.direction = function (from, to) {
          return ptArg(to).subtract(from).normalize();
      };
      Point.create = function (source) {
          return ptArg(source);
      };
      Point.fromBuffer = function (buffer, index) {
          if (index === void 0) { index = 0; }
          return new Point(buffer[index], buffer[index + 1]);
      };
      //region Geometry
      Point.prototype.angle = function () {
          return (this.x < 0)
              ? 360 - Math.atan2(this.x, -this.y) * Point.rad2deg * -1
              : Math.atan2(this.x, -this.y) * Point.rad2deg;
      };
      Point.prototype.angleAbout = function (val) {
          var pt = ptArg(val);
          return Math.atan2(pt.cross(this), pt.dot(this));
      };
      Point.prototype.cross = function (val) {
          var pt = ptArg(val);
          return this.x * pt.y - this.y * pt.x;
      };
      Point.prototype.distance = function (to) {
          var pt = ptArg(to);
          var a = this.x - pt.x;
          var b = this.y - pt.y;
          return Math.sqrt(a * a + b * b);
      };
      Point.prototype.dot = function (val) {
          var pt = ptArg(val);
          return this.x * pt.x + this.y * pt.y;
      };
      Point.prototype.length = function () {
          return Math.sqrt(this.x * this.x + this.y * this.y);
      };
      Point.prototype.normalize = function () {
          var len = this.length();
          if (len > 0.00001) {
              return this.multiply(1 / len);
          }
          return this.clone();
      };
      Point.prototype.perp = function () {
          return new Point(this.y * -1, this.x);
      };
      Point.prototype.rperp = function () {
          return this.reverse().perp();
      };
      Point.prototype.inverse = function () {
          return new Point(this.x * -1, this.y * -1);
      };
      Point.prototype.reverse = function () {
          return new Point(this.x * -1, this.y * -1);
      };
      Point.prototype.rotate = function (radians) {
          var cos = Math.cos(radians);
          var sin = Math.sin(radians);
          var nx = this.x * cos - this.y * sin;
          var ny = this.y * cos + this.x * sin;
          return new Point(nx, ny);
      };
      //endregion
      //region Arithmetic
      Point.prototype.add = function (val) {
          var pt = ptArg(val);
          if (!pt) {
              throw 'add: pt required.';
          }
          return new Point(this.x + pt.x, this.y + pt.y);
      };
      Point.prototype.divide = function (divisor) {
          return new Point(this.x / divisor, this.y / divisor);
      };
      Point.prototype.multiply = function (multipler) {
          return new Point(this.x * multipler, this.y * multipler);
      };
      Point.prototype.round = function () {
          return new Point(Math.round(this.x), Math.round(this.y));
      };
      Point.prototype.subtract = function (val) {
          var pt = ptArg(val);
          if (!pt) {
              throw 'subtract: pt required.';
          }
          return this.add(pt.reverse());
      };
      Point.prototype.clamp = function (lower, upper) {
          var x = this.x;
          if (x < lower.x)
              x = lower.x;
          if (x > upper.x)
              x = upper.x;
          var y = this.y;
          if (y < lower.y)
              y = lower.y;
          if (y > upper.y)
              y = upper.y;
          return new Point(x, y);
      };
      //endregion
      //region Conversion
      Point.prototype.clone = function () {
          return new Point(this.x, this.y);
      };
      Point.prototype.equals = function (another) {
          return this.x === another.x && this.y === another.y;
      };
      Point.prototype.toArray = function () {
          return [this.x, this.y];
      };
      Point.prototype.toString = function () {
          return "[" + this.x + ", " + this.y + "]";
      };
      Point.rad2deg = 360 / (Math.PI * 2);
      Point.deg2rad = (Math.PI * 2) / 360;
      Point.empty = new Point(0, 0);
      Point.max = new Point(2147483647, 2147483647);
      Point.min = new Point(-2147483647, -2147483647);
      Point.up = new Point(0, -1);
      return Point;
  }());
  exports.Point = Point;
  function ptArg(val) {
      if (val !== null || val !== undefined) {
          if (val instanceof Point) {
              return val;
          }
          if (val.x !== undefined && val.y !== undefined) {
              return new Point(val.x, val.y);
          }
          if (val.left !== undefined && val.top !== undefined) {
              return new Point(val.left, val.top);
          }
          if (Array.isArray(val)) {
              return new Point(val);
          }
          if (typeof (val) === 'string') {
              val = parseInt(val);
          }
          if (typeof (val) === 'number') {
              return new Point(val, val);
          }
      }
      return Point.empty;
  }
  //# sourceMappingURL=Point.js.map