static compare (a, b) {

    const alx = a.leftSE.point.x
    const blx = b.leftSE.point.x
    const arx = a.rightSE.point.x
    const brx = b.rightSE.point.x

    // check if they're even in the same vertical plane
    if (brx < alx) return 1
    if (arx < blx) return -1

    const aly = a.leftSE.point.y
    const bly = b.leftSE.point.y
    const ary = a.rightSE.point.y
    const bry = b.rightSE.point.y

    // is left endpoint of segment B the right-more?
    if (alx < blx) {
      // are the two segments in the same horizontal plane?
      if (bly < aly && bly < ary) return 1
      if (bly > aly && bly > ary) return -1

      // is the B left endpoint colinear to segment A?
      const aCmpBLeft = a.comparePoint(b.leftSE.point)
      if (aCmpBLeft < 0) return 1
      if (aCmpBLeft > 0) return -1

      // is the A right endpoint colinear to segment B ?
      const bCmpARight = b.comparePoint(a.rightSE.point)
      if (bCmpARight !== 0) return bCmpARight

      // colinear segments, consider the one with left-more
      // left endpoint to be first (arbitrary?)
      return -1
    }

    // is left endpoint of segment A the right-more?
    if (alx > blx) {
      if (aly < bly && aly < bry) return -1
      if (aly > bly && aly > bry) return 1

      // is the A left endpoint colinear to segment B?
      const bCmpALeft = b.comparePoint(a.leftSE.point)
      if (bCmpALeft !== 0) return bCmpALeft

      // is the B right endpoint colinear to segment A?
      const aCmpBRight = a.comparePoint(b.rightSE.point)
      if (aCmpBRight < 0) return 1
      if (aCmpBRight > 0) return -1

      // colinear segments, consider the one with left-more
      // left endpoint to be first (arbitrary?)
      return 1
    }

    // if we get here, the two left endpoints are in the same
    // vertical plane, ie alx === blx

    // consider the lower left-endpoint to come first
    if (aly < bly) return -1
    if (aly > bly) return 1

    // left endpoints are identical
    // check for colinearity by using the left-more right endpoint

    // is the A right endpoint more left-more?
    if (arx < brx) {
      const bCmpARight = b.comparePoint(a.rightSE.point)
      if (bCmpARight !== 0) return bCmpARight

      // colinear segments with matching left endpoints,
      // consider the one with more left-more right endpoint to be first
      return -1
    }

    // is the B right endpoint more left-more?
    if (arx > brx) {
      const aCmpBRight = a.comparePoint(b.rightSE.point)
      if (aCmpBRight < 0) return 1
      if (aCmpBRight > 0) return -1

      // colinear segments with matching left endpoints,
      // consider the one with more left-more right endpoint to be first
      return 1
    }

    // if we get here, two two right endpoints are in the same
    // vertical plane, ie arx === brx

    // consider the lower right-endpoint to come first
    if (ary < bry) return -1
    if (ary > bry) return 1

    // right endpoints identical as well, so the segments are idential
    // fall back on creation order as consistent tie-breaker
    if (a.id < b.id) return -1
    if (a.id > b.id) return 1

    // identical segment, ie a === b
    return 0
  }
/* This compare() function is for ordering segments in the sweep
   * line tree, and does so according to the following criteria:
   *
   * Consider the vertical line that lies an infinestimal step to the
   * right of the right-more of the two left endpoints of the input
   * segments. Imagine slowly moving a point up from negative infinity
   * in the increasing y direction. Which of the two segments will that
   * point intersect first? That segment comes 'before' the other one.
   *
   * If neither segment would be intersected by such a line, (if one
   * or more of the segments are vertical) then the line to be considered
   * is directly on the right-more of the two left inputs.
   */
This compare() function is for ordering segments in the sweep
line tree, and does so according to the following criteria.

Consider the vertical line that lies an infinestimal step to the
right of the right-more of the two left endpoints of the input
segments. Imagine slowly moving a point up from negative infinity
in the increasing y direction. Which of the two segments will that
point intersect first. That segment comes 'before' the other one.

If neither segment would be intersected by such a line, (if one
or more of the segments are vertical) then the line to be considered
is directly on the right-more of the two left inputs.
This compare () function is for ordering segments in the sweep line tree and does so according to the following criteria . Consider the vertical line that lies an infinestimal step to the right of the right - more of the two left endpoints of the input segments . Imagine slowly moving a point up from negative infinity in the increasing y direction . Which of the two segments will that point intersect first . That segment comes ' before ' the other one . If neither segment would be intersected by such a line ( if one or more of the segments are vertical ) then the line to be considered is directly on the right - more of the two left inputs .
static compare (a, b) {
    const alx = a.leftSE.point.x
    const blx = b.leftSE.point.x
    const arx = a.rightSE.point.x
    const brx = b.rightSE.point.x
    if (brx < alx) return 1
    if (arx < blx) return -1
    const aly = a.leftSE.point.y
    const bly = b.leftSE.point.y
    const ary = a.rightSE.point.y
    const bry = b.rightSE.point.y
    if (alx < blx) {
      if (bly < aly && bly < ary) return 1
      if (bly > aly && bly > ary) return -1
      const aCmpBLeft = a.comparePoint(b.leftSE.point)
      if (aCmpBLeft < 0) return 1
      if (aCmpBLeft > 0) return -1
      const bCmpARight = b.comparePoint(a.rightSE.point)
      if (bCmpARight !== 0) return bCmpARight
      return -1
    }
    if (alx > blx) {
      if (aly < bly && aly < bry) return -1
      if (aly > bly && aly > bry) return 1
      const bCmpALeft = b.comparePoint(a.leftSE.point)
      if (bCmpALeft !== 0) return bCmpALeft
      const aCmpBRight = a.comparePoint(b.rightSE.point)
      if (aCmpBRight < 0) return 1
      if (aCmpBRight > 0) return -1
      return 1
    }
    if (aly < bly) return -1
    if (aly > bly) return 1
    if (arx < brx) {
      const bCmpARight = b.comparePoint(a.rightSE.point)
      if (bCmpARight !== 0) return bCmpARight
      return -1
    }
    if (arx > brx) {
      const aCmpBRight = a.comparePoint(b.rightSE.point)
      if (aCmpBRight < 0) return 1
      if (aCmpBRight > 0) return -1
      return 1
    }
    if (ary < bry) return -1
    if (ary > bry) return 1
    if (a.id < b.id) return -1
    if (a.id > b.id) return 1
    return 0
  }
static compare ( a , b ) { const alx = a . leftSE . point . x const blx = b . leftSE . point . x const arx = a . rightSE . point . x const brx = b . rightSE . point . x if ( brx < alx ) return 1 if ( arx < blx ) return - 1 const aly = a . leftSE . point . y const bly = b . leftSE . point . y const ary = a . rightSE . point . y const bry = b . rightSE . point . y if ( alx < blx ) { if ( bly < aly && bly < ary ) return 1 if ( bly > aly && bly > ary ) return - 1 const aCmpBLeft = a . comparePoint ( b . leftSE . point ) if ( aCmpBLeft < 0 ) return 1 if ( aCmpBLeft > 0 ) return - 1 const bCmpARight = b . comparePoint ( a . rightSE . point ) if ( bCmpARight !== 0 ) return bCmpARight return - 1 } if ( alx > blx ) { if ( aly < bly && aly < bry ) return - 1 if ( aly > bly && aly > bry ) return 1 const bCmpALeft = b . comparePoint ( a . leftSE . point ) if ( bCmpALeft !== 0 ) return bCmpALeft const aCmpBRight = a . comparePoint ( b . rightSE . point ) if ( aCmpBRight < 0 ) return 1 if ( aCmpBRight > 0 ) return - 1 return 1 } if ( aly < bly ) return - 1 if ( aly > bly ) return 1 if ( arx < brx ) { const bCmpARight = b . comparePoint ( a . rightSE . point ) if ( bCmpARight !== 0 ) return bCmpARight return - 1 } if ( arx > brx ) { const aCmpBRight = a . comparePoint ( b . rightSE . point ) if ( aCmpBRight < 0 ) return 1 if ( aCmpBRight > 0 ) return - 1 return 1 } if ( ary < bry ) return - 1 if ( ary > bry ) return 1 if ( a . id < b . id ) return - 1 if ( a . id > b . id ) return 1 return 0 }
This compare() function is for ordering segments in the sweep
 line tree, and does so according to the following criteria:
This compare () function is for ordering segments in the sweep line tree and does so according to the following criteria :
// check if they're even in the same vertical plane // is left endpoint of segment B the right-more? // are the two segments in the same horizontal plane? // is the B left endpoint colinear to segment A? // is the A right endpoint colinear to segment B ? // colinear segments, consider the one with left-more // left endpoint to be first (arbitrary?) // is left endpoint of segment A the right-more? // is the A left endpoint colinear to segment B? // is the B right endpoint colinear to segment A? // colinear segments, consider the one with left-more // left endpoint to be first (arbitrary?) // if we get here, the two left endpoints are in the same // vertical plane, ie alx === blx // consider the lower left-endpoint to come first // left endpoints are identical // check for colinearity by using the left-more right endpoint // is the A right endpoint more left-more? // colinear segments with matching left endpoints, // consider the one with more left-more right endpoint to be first // is the B right endpoint more left-more? // colinear segments with matching left endpoints, // consider the one with more left-more right endpoint to be first // if we get here, two two right endpoints are in the same // vertical plane, ie arx === brx // consider the lower right-endpoint to come first // right endpoints identical as well, so the segments are idential // fall back on creation order as consistent tie-breaker // identical segment, ie a === b