well-known-parser
Version:
A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer
11 lines (10 loc) • 310 B
text/typescript
/**
* ZigZag encoding and decoding for efficient integer compression
* Used in the TWKB format to compress coordinate values
*/
export function encode(value: number): number {
return (value << 1) ^ (value >> 31);
}
export function decode(value: number): number {
return (value >> 1) ^ (-(value & 1));
}