How to use the binary-search-bounds.le function in binary-search-bounds

To help you get started, we’ve selected a few binary-search-bounds 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 NUbots / NUsight2 / src / client / components / visual_mesh / camera / view_model.ts View on Github external
const position = ([] as number[]).concat(...indices.map(i => {
      // Which ring we are on as a value between 0 and 1
      const idx = bounds.le(cRows, i)
      const phi = idx / rows.length
      // How far around the ring we are as a value between 0 and 1
      const theta = (i - cRows[idx]) / rows[idx]
      return [phi, theta]
    }))
github googleapis / nodejs-spanner / benchmark / ycsb.js View on Github external
console.log(
      dedent`${opName}, Operations, ${ops}
      ${opName}, AverageLatency(us), ${stats.mean(lats)}
      ${opName}, LatencyVariance(us), ${stats.stdev(lats)}
      ${opName}, MinLatency(us), ${lats[0]}
      ${opName}, MaxLatency(us), ${lats[lats.length - 1]}
      ${opName}, 95thPercentileLatency(us), ${stats.percentile(lats, 0.95)}
      ${opName}, 99thPercentileLatency(us), ${stats.percentile(lats, 0.99)}
      ${opName}, 99.9thPercentileLatency(us), ${stats.percentile(lats, 0.999)}
      ${opName}, Return=OK, ${ops}`
    );

    for (let i = 0; i < numBucket; i++) {
      const hi = bounds.lt(lats, i + 1);
      const lo = bounds.le(lats, i);
      console.log(`${opName}, ${i}, ${hi - lo}`);
    }

    const lo = bounds.le(lats, numBucket);
    console.log(`${opName}, ${numBucket}, ${ops - lo}`);
  });
}
github mikolalysenko / l1-path-finder / clarkson.js View on Github external
function getConnectingVerts(node, vertex) {
    if(!node) {
      return
    }
    var idx = bsearch.le(node.verts, vertex, function(a, b) {
      return a[1] - vertex[1]
    })
    if(idx < 0) {
      addEdge(node.verts[0], vertex)
    } else if(node.verts[idx][1] === vertex[1]) {
      addEdge(node.verts[idx], vertex)
    } else {
      addEdge(node.verts[idx], vertex)
      if(idx < node.verts.length - 1) {
        addEdge(node.verts[idx+1], vertex)
      }
    }
    if(vertex[0] < node.x) {
      getConnectingVerts(node.left, vertex)
    } else if(vertex[0] > node.x) {
      getConnectingVerts(node.right, vertex)
github gl-vis / gl-heatmap2d / heatmap.js View on Github external
var ptr = 0

  for (var j = 0; j < numY - 1; ++j) {
    var yc0 = ys * (y[j] - loy)
    var yc1 = ys * (y[j + 1] - loy)
    for (var i = 0; i < numX - 1; ++i) {
      var xc0 = xs * (x[i] - lox)
      var xc1 = xs * (x[i + 1] - lox)

      for (var dd = 0; dd < WEIGHTS.length; dd += 2) {
        var dx = WEIGHTS[dd]
        var dy = WEIGHTS[dd + 1]
        var offset = (j + dy) * numX + (i + dx)
        var zc = z[offset]
        var colorIdx = bsearch.le(colorLevels, zc)
        var r, g, b, a
        if (colorIdx < 0) {
          r = colorValues[0]
          g = colorValues[1]
          b = colorValues[2]
          a = colorValues[3]
        } else if (colorIdx === colorCount - 1) {
          r = colorValues[4 * colorCount - 4]
          g = colorValues[4 * colorCount - 3]
          b = colorValues[4 * colorCount - 2]
          a = colorValues[4 * colorCount - 1]
        } else {
          var t = (zc - colorLevels[colorIdx]) /
            (colorLevels[colorIdx + 1] - colorLevels[colorIdx])
          var ti = 1.0 - t
          var i0 = 4 * colorIdx
github mikolalysenko / local-perception-filter-demo / lib / trajectories.js View on Github external
function getState(trajectory, t) {
  var idx = bsearch.le(trajectory, t, testState)
  if(idx < 0) {
    return new State(trajectory[0].x.slice(), trajectory[0].v.slice(), trajectory[0].t, "create")
  }
  if(idx === trajectory.length - 1) {
    var a = trajectory[idx]
    if("destroy" === a.event) {
      return new State(trajectory[idx].x.slice(), [0,0], trajectory[0].t, "destroy")
    }
    var dt = t - a.t
    var nx = [a.x[0] + a.v[0] * dt, a.x[1] + a.v[1] * dt]
    return new State(nx, a.v.slice(), t)
  }
  var a = trajectory[idx]
  var b = trajectory[idx+1]
  var dt = (t - a.t) / (b.t - a.t)
  return new State(
github mikolalysenko / local-perception-filter-demo / bundle.js View on Github external
function getState(trajectory, t) {
  var idx = bsearch.le(trajectory, t, testState)
  if(idx < 0) {
    return new State(trajectory[0].x.slice(), trajectory[0].v.slice(), trajectory[0].t, "create")
  }
  if(idx === trajectory.length - 1) {
    var a = trajectory[idx]
    if("destroy" === a.event) {
      return new State(trajectory[idx].x.slice(), [0,0], trajectory[0].t, "destroy")
    }
    var dt = t - a.t
    var nx = [a.x[0] + a.v[0] * dt, a.x[1] + a.v[1] * dt]
    return new State(nx, a.v.slice(), t)
  }
  var a = trajectory[idx]
  var b = trajectory[idx+1]
  var dt = (t - a.t) / (b.t - a.t)
  return new State(
github mikolalysenko / cdt2d / lib / monotone.js View on Github external
function splitHulls(hulls, points, event) {
  var splitIdx = bsearch.le(hulls, event, findSplit)
  var hull = hulls[splitIdx]
  var upperIds = hull.upperIds
  var x = upperIds[upperIds.length-1]
  hull.upperIds = [x]
  hulls.splice(splitIdx+1, 0,
    new PartialHull(event.a, event.b, event.idx, [x], upperIds))
}
github mikolalysenko / filtered-vector / fvec.js View on Github external
proto.curve = function(t) {
  var time      = this._time
  var n         = time.length
  var idx       = bsearch.le(time, t)
  var result    = this._scratch[0]
  var state     = this._state
  var velocity  = this._velocity
  var d         = this.dimension
  var bounds    = this.bounds
  if(idx < 0) {
    var ptr = d-1
    for(var i=0; i= n-1) {
    var ptr = state.length-1
    var tf = t - time[n-1]
    for(var i=0; i

binary-search-bounds

Better binary searching

MIT
Latest version published 4 years ago

Package Health Score

53 / 100
Full package analysis