How to use splaytree - 9 common examples

To help you get started, we’ve selected a few splaytree examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mfogel / polygon-clipping / dist / polygon-clipping.esm.js View on Github external
if (operation.type === 'intersection') {
        // TODO: this is O(n^2) in number of polygons. By sorting the bboxes,
        //       it could be optimized to O(n * ln(n))
        for (var _i2 = 0, _iMax = multipolys.length; _i2 < _iMax; _i2++) {
          var mpA = multipolys[_i2];

          for (var j = _i2 + 1, jMax = multipolys.length; j < jMax; j++) {
            if (getBboxOverlap(mpA.bbox, multipolys[j].bbox) === null) return [];
          }
        }
      }
      /* Put segment endpoints in a priority queue */


      var queue = new SplayTree(SweepEvent.compare);

      for (var _i3 = 0, _iMax2 = multipolys.length; _i3 < _iMax2; _i3++) {
        var sweepEvents = multipolys[_i3].getSweepEvents();

        for (var _j = 0, _jMax = sweepEvents.length; _j < _jMax; _j++) {
          queue.insert(sweepEvents[_j]);
        }
      }
      /* Pass the sweep line over those endpoints */


      var sweepLine = new SweepLine(queue);
      var prevQueueSize = queue.size;
      var node = queue.pop();

      while (node) {
github mfogel / polygon-clipping / src / rounder.js View on Github external
constructor () {
    this.tree = new SplayTree()
    // preseed with 0 so we don't end up with values < Number.EPSILON
    this.round(0)
  }
github mfogel / polygon-clipping / src / operation.js View on Github external
/* BBox optimization for intersection operation
     * If we can find any pair of multipolygons whose bbox does not overlap,
     * then the result will be empty. */
    if (operation.type === 'intersection') {
      // TODO: this is O(n^2) in number of polygons. By sorting the bboxes,
      //       it could be optimized to O(n * ln(n))
      for (let i = 0, iMax = multipolys.length; i < iMax; i++) {
        const mpA = multipolys[i]
        for (let j = i + 1, jMax = multipolys.length; j < jMax; j++) {
          if (getBboxOverlap(mpA.bbox, multipolys[j].bbox) === null) return []
        }
      }
    }

    /* Put segment endpoints in a priority queue */
    const queue = new SplayTree(SweepEvent.compare)
    for (let i = 0, iMax = multipolys.length; i < iMax; i++) {
      const sweepEvents = multipolys[i].getSweepEvents()
      for (let j = 0, jMax = sweepEvents.length; j < jMax; j++) {
        queue.insert(sweepEvents[j])
      }
    }

    /* Pass the sweep line over those endpoints */
    const sweepLine = new SweepLine(queue)
    let prevQueueSize = queue.size
    let node = queue.pop()
    while (node) {
      const evt = node.key
      if (queue.size === prevQueueSize) {
        // prevents an infinite loop, an otherwise common manifestation of bugs
        const seg = evt.segment
github mfogel / polygon-clipping / dist / polygon-clipping.esm.js View on Github external
function CoordRounder() {
    _classCallCheck(this, CoordRounder);

    this.tree = new SplayTree(); // preseed with 0 so we don't end up with values < Number.EPSILON

    this.round(0);
  } // Note: this can rounds input values backwards or forwards.
  //       You might ask, why not restrict this to just rounding
github anvaka / playground / sweep-line / sweep / src / sweepStatus.js View on Github external
export default function createSweepStatus(onError, EPS) {
  var lastPointY, prevY;
  var lastPointX, prevX;
  var useBelow = false;
  var status = new SplayTree(compareSegments);

  // To save on GC we return mutable object.
  var currentBoundary = {
    beforeLeft: null,
    left: null,
    right: null,
    afterRight: null,
  }

  var currentLeftRight = {left: null, right: null};

  return {
    /**
     * Add new segments into the status tree.
     */
    insertSegments,
github rowanwins / shamos-hoey / src / Sweepline.js View on Github external
constructor () {
        this.tree = new SplayTree(compareSegments)
    }
github mfogel / polygon-clipping / dist / polygon-clipping.esm.js View on Github external
function SweepLine(queue) {
    var comparator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Segment.compare;

    _classCallCheck(this, SweepLine);

    this.queue = queue;
    this.tree = new SplayTree(comparator);
    this.segments = [];
  }
github anvaka / playground / sweep-line / sweep / src / createEventQueue.js View on Github external
export default function createEventQueue(byY) {
  const q = new SplayTree(byY);

  return {
    isEmpty: isEmpty,
    size: size,
    pop: pop,
    find: find,
    insert: insert
  }

  function find(p) {
    return q.find(p);
  }

  function size() {
    return q.size;
  }
github mfogel / polygon-clipping / src / sweep-line.js View on Github external
constructor (queue, comparator = Segment.compare) {
    this.queue = queue
    this.tree = new SplayTree(comparator)
    this.segments = []
  }

splaytree

Fast Splay tree for Node and browser

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis

Popular splaytree functions