Skip to content

Instantly share code, notes, and snippets.

View morganherlocker's full-sized avatar
☠️
computing

Morgan Herlocker morganherlocker

☠️
computing
View GitHub Profile
@morganherlocker
morganherlocker / index.js
Last active August 29, 2015 14:06
requirebin sketch
var tilebelt = require('tilebelt');
var domify = require('domify');
var z = getBboxZoom([100, 0, 101, 2])
document.body.appendChild(domify('<p>z:'+z));
function getBboxZoom(bbox) {
var MAX_ZOOM = 28;
@morganherlocker
morganherlocker / index.js
Created September 17, 2014 15:12
requirebin sketch
var domify = require('domify');
document.body.appendChild(domify('<p>yep'));
@morganherlocker
morganherlocker / gist:85916a92f147add000e2
Last active August 29, 2015 14:06
cover stripe algo
  1. find max and min vertex y of polygon

  2. get tile of max vertex for max_zoom

  3. get intersections of a horizontal line at the tile's y value across the polygon

  4. add tiles from the first intersection (far left) to intersection + 1 (use tilebelt.pointToTile, which is fast)

  5. go to intersection + 2 and repeat [4] until there are no intersections left (this would skip over holes and caves)

var building = {}
building.properties = vt.layers.building.feature(i).properties;
building.geometry = vt.layers.building.feature(i).loadGeometry();
traverse(building.geometry).forEach(function(g){
if(!Array.isArray(g) && typeof g.x === 'number') {
var topLeft = tile;
while(topLeft[2] < zoomEncoding){
topLeft = tilebelt.getChildren(topLeft)[0]
}
var x = topLeft[0] + g.x
# address interpolation - noop
ok 1 should be equivalent
ok 2 should be equivalent
ok 3 should be equivalent
✓ address interpolation - noop
# address interpolation - parity: even + both
ok 4 should be equivalent
✓ address interpolation - parity: even + both
  • merge scanline refactor with master
  • explore scanline
  • explore 2 split
@morganherlocker
morganherlocker / gist:ea64d973bd5fc196323a
Last active August 29, 2015 14:07
async control flow

When you make an async request to a server, you fire it off and wait for the server to respond. The server could respond to multiple requests in any order it likes. If you are working on something that needs to be in order, there are a few things that you can do to control the flow.

counting

The most basic approach involves counting up responses outside of callbacks until the number of responses === the number of requests. This works, but can get crazy if you have a lot of complex events flying around everywhere.

var urls = [...]
var pages = []
for(var i = 0; i < urls.length; i++) {
@morganherlocker
morganherlocker / gist:d1d0b17041b67bc5d294
Last active August 29, 2015 14:07
voxel-openstreetmap spec v2

v1 spec that hit a wall due to me having my numbers of a bit (performance was impractical)

General

  • tiles are processed and put into a leveldb store

  • downloaded tiles are cached

  • each z15 vector tile's geometry is encoded as z25 tile voxel equivalents

tape 101

tape is a tiny test runner and assertion library. It outputs a text format called TAP (Test Anything Protocol). TAP is cool because it is a standardized text format that can be easily parsed in just about any programming language. Unlike many other javascript test frameworks, tape is a simple npm module, so it can be run anywhere without weird hacks.

###Installation

npm install tape --save-dev
TAP version 13
# the world
party in ===============================> AFG.geo.json
ok 1 check tile-cover
ok 2 check for empty tiles
ok 3 check for empty tiles
ok 4 check for empty tiles
ok 5 check for empty tiles
ok 6 check for empty tiles
ok 7 check for empty tiles