mapbox / tile-cover

Generate the minimum number of tiles to cover a geojson geometry
MIT License
189 stars 40 forks source link

improved line cover algo #40

Closed morganherlocker closed 9 years ago

morganherlocker commented 9 years ago

Trading a bit of performance, we can get better accuracy and cover more edge cases.

given segment: x0, y0, x1, y1

  1. get the tile at x0, y0
  2. get the tile at x1, y1

//get intersections with verticals

  1. while i <= tile2[0]
  2. get the intersection of the right vertical edge of a tile at x+i
  3. foreach intersection add tile [x+i-1, Math.floor(y), max_zoom] and tile [x+i, Math.floor(y), max_zoom]

//get intersections with horizontals

  1. while i <= tile2[1]
  2. get the intersection of the right bottom edge of a tile at y+i
  3. foreach intersection add tile [Math.floor(x), y+i-1, max_zoom] and tile [Math.floor(x), y+i, max_zoom]
morganherlocker commented 9 years ago

done https://github.com/mapbox/tile-cover/commit/10f18436518900879b7684221e6f7b476b8a1445