@dra2020/baseclient 1.0.163 → 1.0.164
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/baseclient.js +93 -0
- package/dist/baseclient.js.map +1 -1
- package/dist/poly/all.d.ts +1 -0
- package/dist/poly/polyhash.d.ts +1 -0
- package/lib/poly/all.ts +1 -0
- package/lib/poly/polyhash.ts +52 -0
- package/package.json +1 -1
package/dist/poly/all.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function polyHash32(poly: any, seed?: number): number;
|
package/lib/poly/all.ts
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as P from './poly';
|
|
2
|
+
import * as PP from './polypack';
|
|
3
|
+
|
|
4
|
+
// Hash coordinates to 32 bit number in order to produce a fast (and a little sloppy) equivalence test.
|
|
5
|
+
// Note that this depends on ordering, so an equivalent polygon with different coordinate ordering would
|
|
6
|
+
// not test as equivalent. As a 32 bit number, you can expect collisions when used for large numbers of
|
|
7
|
+
// polygons (e.g. a 700k block set might expect ~57 collisions - TX at 660K gets 62 collisions, e.g.).
|
|
8
|
+
//
|
|
9
|
+
export function polyHash32(poly: any, seed = 0): number
|
|
10
|
+
{
|
|
11
|
+
let pp = P.polyNormalize(poly);
|
|
12
|
+
if (!pp) return 0;
|
|
13
|
+
|
|
14
|
+
let h = (seed | 0) ^ 0x9e3779b9;
|
|
15
|
+
const buf = new ArrayBuffer(8);
|
|
16
|
+
const dv = new DataView(buf);
|
|
17
|
+
|
|
18
|
+
function mix32(x: number): number
|
|
19
|
+
{
|
|
20
|
+
x ^= x >>> 16; x = Math.imul(x, 0x7feb352d);
|
|
21
|
+
x ^= x >>> 15; x = Math.imul(x, 0x846ca68b);
|
|
22
|
+
x ^= x >>> 16;
|
|
23
|
+
return x | 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let l = 0;
|
|
27
|
+
PP.polyPackEachRing(pp, (b: Float64Array, iPoly: number, iRing: number, iOffset: number, nPoints: number) => {
|
|
28
|
+
let iEnd = iOffset + (nPoints*2);
|
|
29
|
+
for (; iOffset < iEnd; iOffset++)
|
|
30
|
+
{
|
|
31
|
+
const x = b[iOffset];
|
|
32
|
+
if (Number.isNaN(x))
|
|
33
|
+
{
|
|
34
|
+
dv.setUint32(0, 0x7ff80001, true);
|
|
35
|
+
dv.setUint32(4, 0, true);
|
|
36
|
+
}
|
|
37
|
+
else
|
|
38
|
+
dv.setFloat64(0, x, true);
|
|
39
|
+
const lo = dv.getUint32(0, true) | 0;
|
|
40
|
+
const hi = dv.getUint32(4, true) | 0;
|
|
41
|
+
|
|
42
|
+
let z = mix32(lo ^ Math.imul(hi, 0x9e3779b9) ^ Math.imul(l + 1, 0x85ebca6b));
|
|
43
|
+
h ^= z;
|
|
44
|
+
h = mix32(h);
|
|
45
|
+
l++;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
h ^= l | 0;
|
|
49
|
+
h = mix32(h);
|
|
50
|
+
// return as unsigned 32-bit in a JS number
|
|
51
|
+
return h >>> 0;
|
|
52
|
+
}
|