text: import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
  import _createClass from "@babel/runtime/helpers/esm/createClass";
  import { equals } from '../lib/common';
  
  var Polygon = function () {
    function Polygon(points) {
      _classCallCheck(this, Polygon);
  
      this.points = points;
      this.isClosed = equals(this.points[this.points.length - 1], this.points[0]);
      Object.freeze(this);
    }
  
    _createClass(Polygon, [{
      key: "getSignedArea",
      value: function getSignedArea() {
        var area = 0;
        this.forEachSegment(function (p1, p2) {
          area += (p1[0] + p2[0]) * (p1[1] - p2[1]);
        });
        return area / 2;
      }
    }, {
      key: "getArea",
      value: function getArea() {
        return Math.abs(this.getSignedArea());
      }
    }, {
      key: "getWindingDirection",
      value: function getWindingDirection() {
        return Math.sign(this.getSignedArea());
      }
    }, {
      key: "forEachSegment",
      value: function forEachSegment(visitor) {
        var length = this.points.length;
  
        for (var i = 0; i < length - 1; i++) {
          visitor(this.points[i], this.points[i + 1], i, i + 1);
        }
  
        if (this.isPolygon && !this.isClosed()) {
          visitor(this.points[length - 1], this.points[0], length - 1, 0);
        }
      }
    }]);
  
    return Polygon;
  }();
  
  export { Polygon as default };
  //# sourceMappingURL=polygon.js.map