text: 'use strict';
  
  //var signedArea = require('./signed_area');
  var EdgeType   = require('./edge_type');
  
  /**
   * Sweepline event
   *
   * @class {SweepEvent}
   * @param {Array.<Number>}  point
   * @param {Boolean}         left
   * @param {SweepEvent=}     otherEvent
   * @param {Boolean}         isSubject
   * @param {Number}          edgeType
   */
  function SweepEvent(point, left, otherEvent, isSubject, edgeType) {
  
    /**
     * Is left endpoint?
     * @type {Boolean}
     */
    this.left = left;
  
    /**
     * @type {Array.<Number>}
     */
    this.point = point;
  
    /**
     * Other edge reference
     * @type {SweepEvent}
     */
    this.otherEvent = otherEvent;
  
    /**
     * Belongs to source or clipping polygon
     * @type {Boolean}
     */
    this.isSubject = isSubject;
  
    /**
     * Edge contribution type
     * @type {Number}
     */
    this.type = edgeType || EdgeType.NORMAL;
  
  
    /**
     * In-out transition for the sweepline crossing polygon
     * @type {Boolean}
     */
    this.inOut = false;
  
  
    /**
     * @type {Boolean}
     */
    this.otherInOut = false;
  
    /**
     * Previous event in result?
     * @type {SweepEvent}
     */
    this.prevInResult = null;
  
    /**
     * Does event belong to result?
     * @type {Boolean}
     */
    this.inResult = false;
  
  
    // connection step
  
    /**
     * @type {Boolean}
     */
    this.resultInOut = false;
  
    this.isExteriorRing = true;
  }
  
  
  SweepEvent.prototype = {
  
    /**
     * @param  {Array.<Number>}  p
     * @return {Boolean}
     */
    isBelow: function (p) {
      var p0 = this.point, p1 = this.otherEvent.point;
      return this.left ?
        (p0[0] - p[0]) * (p1[1] - p[1]) - (p1[0] - p[0]) * (p0[1] - p[1]) > 0 :
        // signedArea(this.point, this.otherEvent.point, p) > 0 :
        (p1[0] - p[0]) * (p0[1] - p[1]) - (p0[0] - p[0]) * (p1[1] - p[1]) > 0;
        //signedArea(this.otherEvent.point, this.point, p) > 0;
    },
  
  
    /**
     * @param  {Array.<Number>}  p
     * @return {Boolean}
     */
    isAbove: function (p) {
      return !this.isBelow(p);
    },
  
  
    /**
     * @return {Boolean}
     */
    isVertical: function () {
      return this.point[0] === this.otherEvent.point[0];
    },
  
  
    clone: function () {
      var copy = new SweepEvent(
        this.point, this.left, this.otherEvent, this.isSubject, this.type);
  
      copy.inResult       = this.inResult;
      copy.prevInResult   = this.prevInResult;
      copy.isExteriorRing = this.isExteriorRing;
      copy.inOut          = this.inOut;
      copy.otherInOut     = this.otherInOut;
  
      return copy;
    }
  };
  
  module.exports = SweepEvent;
  