@dra2020/baseclient 1.0.162 → 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/all/all.d.ts +2 -0
- package/dist/baseclient.js +170 -10
- package/dist/baseclient.js.map +1 -1
- package/dist/control/all.d.ts +1 -0
- package/dist/control/control.d.ts +4 -0
- package/dist/poly/all.d.ts +1 -0
- package/dist/poly/mapto.d.ts +3 -2
- package/dist/poly/polyhash.d.ts +1 -0
- package/dist/util/util.d.ts +3 -0
- package/lib/all/all.ts +2 -0
- package/lib/control/all.ts +1 -0
- package/lib/control/control.ts +4 -0
- package/lib/geo/geo.ts +9 -4
- package/lib/poly/all.ts +1 -0
- package/lib/poly/mapto.ts +12 -5
- package/lib/poly/polyhash.ts +52 -0
- package/lib/util/util.ts +20 -0
- package/package.json +1 -1
- package/dist/colors/colortable-test.d.ts +0 -3
- package/dist/colors/colortable-test2.d.ts +0 -3
- package/dist/stats.json +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './control';
|
package/dist/poly/all.d.ts
CHANGED
package/dist/poly/mapto.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import * as G from '../geo/all';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
2
|
+
import { Control } from '../control/all';
|
|
3
|
+
export declare function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids: G.GeoCentroidMap, control?: Control): any;
|
|
4
|
+
export declare function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatureCollection, control?: Control): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function polyHash32(poly: any, seed?: number): number;
|
package/dist/util/util.d.ts
CHANGED
|
@@ -5,9 +5,12 @@ export declare class Elapsed {
|
|
|
5
5
|
tDur: any;
|
|
6
6
|
constructor(bStart?: boolean);
|
|
7
7
|
start(): void;
|
|
8
|
+
restart(): void;
|
|
8
9
|
end(): void;
|
|
9
10
|
ms(): number;
|
|
11
|
+
mscur(): number;
|
|
10
12
|
nano(): number;
|
|
13
|
+
nanocur(): number;
|
|
11
14
|
}
|
|
12
15
|
export declare class MultiTimer {
|
|
13
16
|
_overall: Elapsed;
|
package/lib/all/all.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './control';
|
package/lib/geo/geo.ts
CHANGED
|
@@ -11,13 +11,17 @@ export type HideMap = { [id: string]: boolean };
|
|
|
11
11
|
|
|
12
12
|
// Tracing/debugging aid
|
|
13
13
|
let metrics: { [action: string]: { count: number, total: number } } = {};
|
|
14
|
+
const MinRecordTotal = 500;
|
|
14
15
|
|
|
15
16
|
function record(action: string, total: number): void
|
|
16
17
|
{
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if (total > MinRecordTotal)
|
|
19
|
+
{
|
|
20
|
+
if (metrics[action] === undefined)
|
|
21
|
+
metrics[action] = { count: 0, total: 0 };
|
|
22
|
+
metrics[action].count++;
|
|
23
|
+
metrics[action].total += total;
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
export function dumpMetrics(): void
|
|
@@ -25,6 +29,7 @@ export function dumpMetrics(): void
|
|
|
25
29
|
Object.keys(metrics).forEach(action => {
|
|
26
30
|
console.log(`G.${action}: count: ${metrics[action].count}, total: ${metrics[action].total}`);
|
|
27
31
|
});
|
|
32
|
+
metrics = {};
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
export function hidemapConcat(...args: HideMap[]): HideMap
|
package/lib/poly/all.ts
CHANGED
package/lib/poly/mapto.ts
CHANGED
|
@@ -4,6 +4,7 @@ import * as PP from './polypack';
|
|
|
4
4
|
import * as PL from './polylabel';
|
|
5
5
|
import * as BB from './boundbox';
|
|
6
6
|
import { polyContainsPoint } from './pointinpoly';
|
|
7
|
+
import { Control } from '../control/all';
|
|
7
8
|
|
|
8
9
|
function setLabels(c: G.GeoFeatureCollection): void
|
|
9
10
|
{
|
|
@@ -33,7 +34,7 @@ function setLabels(c: G.GeoFeatureCollection): void
|
|
|
33
34
|
//
|
|
34
35
|
// The return value is an object that maps the block feature ids to the district feature id.
|
|
35
36
|
//
|
|
36
|
-
export function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids: G.GeoCentroidMap): any
|
|
37
|
+
export function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids: G.GeoCentroidMap, control?: Control): any
|
|
37
38
|
{
|
|
38
39
|
let map: any = {};
|
|
39
40
|
|
|
@@ -43,7 +44,11 @@ export function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids
|
|
|
43
44
|
let aDistricts: number[] = fs.map(f => P.polyArea(f));
|
|
44
45
|
|
|
45
46
|
// Walk over blocks, mapping centroid to district
|
|
46
|
-
|
|
47
|
+
let canceled = false;
|
|
48
|
+
let keys = Object.keys(centroids);
|
|
49
|
+
keys.forEach((blockid: string, k: number) => {
|
|
50
|
+
canceled = canceled || control?.isCanceled();
|
|
51
|
+
if (canceled) return;
|
|
47
52
|
let x = centroids[blockid].x;
|
|
48
53
|
let y = centroids[blockid].y;
|
|
49
54
|
|
|
@@ -67,12 +72,14 @@ export function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids
|
|
|
67
72
|
iLow = fIn[i];
|
|
68
73
|
map[blockid] = fs[iLow].properties.id;
|
|
69
74
|
}
|
|
75
|
+
|
|
76
|
+
if (control) control.statusUpdate(k, keys.length);
|
|
70
77
|
});
|
|
71
78
|
|
|
72
|
-
return map;
|
|
79
|
+
return canceled ? undefined : map;
|
|
73
80
|
}
|
|
74
81
|
|
|
75
|
-
export function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatureCollection): any
|
|
82
|
+
export function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatureCollection, control?: Control): any
|
|
76
83
|
{
|
|
77
84
|
// Cache labelx, labely if necessary
|
|
78
85
|
setLabels(blocks);
|
|
@@ -82,5 +89,5 @@ export function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatur
|
|
|
82
89
|
centroids[f.properties.id] = { x: f.properties.labelx, y: f.properties.labely }
|
|
83
90
|
});
|
|
84
91
|
|
|
85
|
-
return polyMapToByCentroid(districts, centroids);
|
|
92
|
+
return polyMapToByCentroid(districts, centroids, control);
|
|
86
93
|
}
|
|
@@ -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
|
+
}
|
package/lib/util/util.ts
CHANGED
|
@@ -25,6 +25,12 @@ export class Elapsed
|
|
|
25
25
|
if (this.tDur) this.tDur = undefined;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
restart(): void
|
|
29
|
+
{
|
|
30
|
+
if (this.tStart === undefined) this.start();
|
|
31
|
+
delete this.tDur;
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
end(): void
|
|
29
35
|
{
|
|
30
36
|
if (this.tStart === undefined) this.start();
|
|
@@ -43,6 +49,13 @@ export class Elapsed
|
|
|
43
49
|
return this.tDur;
|
|
44
50
|
}
|
|
45
51
|
|
|
52
|
+
mscur(): number
|
|
53
|
+
{
|
|
54
|
+
let ms = this.ms();
|
|
55
|
+
this.restart();
|
|
56
|
+
return ms;
|
|
57
|
+
}
|
|
58
|
+
|
|
46
59
|
nano(): number
|
|
47
60
|
{
|
|
48
61
|
if (this.tDur === undefined) this.end();
|
|
@@ -51,6 +64,13 @@ export class Elapsed
|
|
|
51
64
|
else
|
|
52
65
|
return this.tDur * 1000000;
|
|
53
66
|
}
|
|
67
|
+
|
|
68
|
+
nanocur(): number
|
|
69
|
+
{
|
|
70
|
+
let nano = this.nano();
|
|
71
|
+
this.restart();
|
|
72
|
+
return nano;
|
|
73
|
+
}
|
|
54
74
|
}
|
|
55
75
|
|
|
56
76
|
export class MultiTimer
|
package/package.json
CHANGED