added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
@@ -0,0 +1,56 @@
var PRECISION = 1e5
function decode( value ) {
var points = []
var lat = 0
var lon = 0
var values = decode.integers( value, function( x, y ) {
lat += x
lon += y
points.push([ lat / PRECISION, lon / PRECISION ])
})
return points
}
decode.sign = function( value ) {
return value & 1 ? ~( value >>> 1 ) : ( value >>> 1 )
}
decode.integers = function( value, callback ) {
var values = 0
var x = 0
var y = 0
var byte = 0
var current = 0
var bits = 0
for( var i = 0; i < value.length; i++ ) {
byte = value.charCodeAt( i ) - 63
current = current | (( byte & 0x1F ) << bits )
bits = bits + 5
if( byte < 0x20 ) {
if( ++values & 1 ) {
x = decode.sign( current )
} else {
y = decode.sign( current )
callback( x, y )
}
current = 0
bits = 0
}
}
return values
}
module.exports = decode
@@ -0,0 +1,75 @@
var PRECISION = 1e5
var CHARCODE_OFFSET = 63
var CHARMAP = {}
for( var i = 0x20; i < 0x7F; i++ ) {
CHARMAP[ i ] = String.fromCharCode( i )
}
function encode( points ) {
// px, py, x and y store rounded exponentiated versions of the values
// they represent to compute the actual desired differences. This helps
// with finer than 5 decimals floating point numbers.
var px = 0, py = 0
return reduce( points, function( str, lat, lon ) {
var x = Math.round( lat * 1e5 )
var y = Math.round( lon * 1e5 )
str += chars( sign( ( x - px ) ) ) +
chars( sign( ( y - py ) ) )
px = x
py = y
return str
})
}
function reduce( points, callback ) {
var point = null
var lat = 0
var lon = 0
var str = ''
for( var i = 0; i < points.length; i++ ) {
point = points[i]
lat = point.lat || point.x || point[0]
lon = point.lng || point.y || point[1]
str = callback( str, lat, lon )
}
return str
}
function sign( value ) {
return ( value < 0 ) ? ~( value << 1 ) : ( value << 1 )
}
function charCode( value ) {
return (( value & 0x1F ) | 0x20 ) + 63
}
function chars( value ) {
var str = ''
while( value >= 0x20 ) {
str += CHARMAP[ charCode( value ) ]
value = value >> 5
}
str += CHARMAP[ value + 63 ]
return str
}
module.exports = encode
@@ -0,0 +1,4 @@
module.exports = {
encode: require( './encode' ),
decode: require( './decode' ),
}