Inaft/Wishlist

From triplescripts.org wiki
Revision as of 14:08, 18 March 2023 by 70.115.145.22 (talk) (consider notebooks)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  • Need a trivial way to create a self-contained notebook, given small-ish repo. The point would be to obviate the need to set up a project, etc—once you have the notebook, you have everything. (Likewise, consider a way to ingest these notebooks and convert them to Inaft-style tests.) For example, consider if we wanted to demonstrate the following polyline decoding routine:
function decode(encoding) {
  let points = [];

  let latitude = 0;
  let longitude = 0;

  let ax = 1;
  let bitMargin = 0;
  for (let i = 0, n = encoding.length; i < n; ++i) {
    let bits = encoding.charCodeAt(i) - 0x40;
    ax += bits << bitMargin;
    bitMargin += 5;

    if (bits < 0x1F) {
      latitude += (ax & 1) ?
        ~(ax >> 1) :
        ax >> 1;

      ax = 1;
      bitMargin = 0;
      while (++i < n) {
        let bits = encoding.charCodeAt(i) - 0x40;
        ax += bits << bitMargin;
        bitMargin += 5;

        if (bits < 0x1F) {
          longitude += (ax & 1) ?
             ~(ax >> 1) :
             ax >> 1;
          break;
        }
      }

      points.push([ latitude * 1E-5, longitude * 1E-5 ]);

      bitMargin = 0;
      ax = 1;
    }
  }

  return points;
}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.