s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
197 lines • 6.82 kB
TypeScript
/**
* An Uint64 is a 64-bit unsigned integer that uniquely identifies a cell in the S2
* cell decomposition. Built to interface with internal wasm functions.
* The Id in this case is just the index pointing to the structure in wasm
*/
export type Uint64Ref = number;
/** An Uint64LoHi contains the low and high 32 bits of the Uint64 in two components */
export interface Uint64LoHi {
lo: number;
hi: number;
}
/** Mathematical operations that can be performed on two Uint64s */
type MathTypes = 'ADD' | 'SUB' | 'DIV' | 'MUL' | 'BIT_AND' | 'BIT_OR' | 'BIT_XOR';
/** An Uint64Comparitor compares two Uint64s and finds which is smaller */
export type WasmUint64Comparitor = (id1: Uint64Ref, id2: Uint64Ref) => -1 | 0 | 1;
/** An Uint64Arithmetic adds two Uint64s and returns the result */
export type WasmArithmetic = (id1: Uint64Ref, id2: Uint64Ref) => Uint64Ref;
/** An Uint64Arithmetic NOT inverses the bits of the Uint64 */
export type WasmNot = (id1: Uint64Ref) => Uint64Ref;
/** Shifts the bits of the Uint64 */
export type WasmShift = (id1: Uint64Ref, shift: number) => Uint64Ref;
/** Get the lower 32 bits of the Uint64 */
export type WasmLoBits = (id: Uint64Ref) => number;
/** Get the upper 32 bits of the Uint64 */
export type WasmHiBits = (id: Uint64Ref) => number;
/** Generator that builds Uint64Cells from either lon/lat or face/s/t */
export declare class Uint64CellGenerator {
#private;
instance: WebAssembly.Instance;
wasmMemory?: Uint8Array;
tmpString: string;
/** Creates an instance of Uint64CellGenerator that manages the wasm memory */
constructor();
/**
* @param type - left shift or right shift
* @param bits - number of bits
* @param input - Uint64 to shift
* @returns - shifted Uint64
*/
shift(type: 'LEFT' | 'RIGHT', bits: number, input: Uint64Cell): Uint64Cell;
/**
* @param type - `ADD` | `SUB` | `DIV` | `MUL` | `BIT_AND` | `BIT_OR` | `BIT_XOR`
* @param a - first Uint64
* @param b - second Uint64
* @returns - resultant Uint64
*/
math(type: MathTypes, a: Uint64Cell, b: Uint64Cell): Uint64Cell;
/**
* @param input - Uint64 to invert
* @returns - inverted Uint64
*/
not(input: Uint64Cell): Uint64Cell;
/**
* Convert a low/high pair to an Uint64Cell representation
* @param low - low 32 bits
* @param high - high 32 bits
* @returns - an Uint64Cell with the appropriate id and functions
*/
fromLowHigh(low: number, high: number): Uint64Cell;
}
/**
* A 64 bit unsigned integer
*/
export declare class Uint64Cell {
readonly id: Uint64Ref;
/** @param id - a number to convert */
constructor(id: Uint64Ref);
/**
* @param id - a number to convert
* @returns - an Uint64Cell with the appropriate id and functions
*/
static fromNumber(id: number): Uint64Cell;
/**
* NOTE: The whole point of this package is to avoid bigint, but for testing we need to be able
* to verify large numbers in a convenient way.
* @param id - a bigint
* @returns the Uint64Cell
*/
static fromBigint(id: bigint): Uint64Cell;
/**
* @param low - low 32 bits
* @param high - high 32 bits
* @returns - an Uint64Cell with the appropriate id and functions
*/
static fromLowHigh(low: number, high: number): Uint64Cell;
/**
* @param bits - number of bits
* @returns - shifted Uint64
*/
shiftLeft(bits: number): Uint64Cell;
/**
* @param bits - number of bits
* @returns - shifted Uint64
*/
shiftRight(bits: number): Uint64Cell;
/**
* @returns - inverted Uint64
*/
not(): Uint64Cell;
/**
* @param b - the number to compare
* @returns - the sum of `this` and `b`
*/
add(b: number | Uint64Cell): Uint64Cell;
/**
* @param b - the number to compare
* @returns - the difference of `this` and `b`
*/
sub(b: number | Uint64Cell): Uint64Cell;
/**
* @param b - the number to compare
* @returns - the product of `this` and `b`
*/
mul(b: number | Uint64Cell): Uint64Cell;
/**
* @param b - the number to compare
* @returns - the quotient of `this` and `b`
*/
div(b: number | Uint64Cell): Uint64Cell;
/**
* @param b - the number to compare
* @returns - the and of `this` and `b`
*/
bitAnd(b: number | Uint64Cell): Uint64Cell;
/**
* @param b - the number to compare
* @returns - the or of `this` and `b`
*/
bitOr(b: number | Uint64Cell): Uint64Cell;
/**
* @param b - the number to compare
* @returns - the xor of `this` and `b`
*/
bitXor(b: number | Uint64Cell): Uint64Cell;
/**
* @returns - low and high bits of `this`
*/
toLoHi(): Uint64LoHi;
/**
* Convert the Uint64Cell to a bigint.
* NOTE: The whole point of this package is to avoid bigint, but for testing we need to be able
* to verify large numbers in a convenient way.
* @returns the bigint
*/
toBigInt(): bigint;
/** @returns the number representation of the Uint64Cell. May lose precision. */
toNumber(): number;
/**
* @param b - the number to compare
* @returns - -1 if `this` is less than `b`, 0 if `this` is equal to `b`, 1 if `this` is greater than `b`
*/
compare(b: number | Uint64Cell): -1 | 0 | 1;
/**
* @param b - the number to compare
* @returns - true if `this` is equal to `b`
*/
eq(b: number | Uint64Cell): boolean;
/**
* @param b - the number to compare
* @returns - true if `this` is not equal to `b`
*/
neq(b: number | Uint64Cell): boolean;
/**
* @param b - the number to compare
* @returns - true if `this` is less than `b`
*/
lt(b: number | Uint64Cell): boolean;
/**
* @param b - the number to compare
* @returns - true if `this` is less than or equal to `b`
*/
lte(b: number | Uint64Cell): boolean;
/**
* @param b - the number to compare
* @returns - true if `this` is greater than `b`
*/
gt(b: number | Uint64Cell): boolean;
/**
* @param b - the number to compare
* @returns - true if `this` is greater than or equal to `b`
*/
gte(b: number | Uint64Cell): boolean;
}
/**
* Convenience function to convert a number to an Uint64Cell
* @param input - the number to convert
* @returns - an Uint64Cell with the appropriate id and functions
*/
export declare function Uint64(input: number | Uint64Cell): Uint64Cell;
/**
* @param lo - low 32 bits
* @param hi - high 32 bits
* @returns - an Uint64Cell with the appropriate id and functions
*/
export declare function Uint64LoHi(lo: number, hi: number): Uint64Cell;
export {};
//# sourceMappingURL=uint64.d.ts.map