@dra2020/baseclient 1.0.21 → 1.0.24

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.
@@ -0,0 +1 @@
1
+ export * from './emit';
@@ -0,0 +1,7 @@
1
+ export declare class Emit {
2
+ onList: any;
3
+ constructor();
4
+ on(eventName: string, cb: any): void;
5
+ emit(eventName: string, arg1?: any, arg2?: any, arg3?: any): void;
6
+ off(eventName: string, cb: any): void;
7
+ }
@@ -53,10 +53,12 @@ export declare type RevisionList = Revision[];
53
53
  export interface SessionUser {
54
54
  id: string;
55
55
  name: string;
56
+ twitterhandle: string;
56
57
  }
57
58
  export interface ActiveUser {
58
59
  id: string;
59
60
  name: string;
61
+ twitterhandle: string;
60
62
  active: number;
61
63
  }
62
64
  export interface SessionUserIndex {
@@ -14,3 +14,4 @@ export declare function boundbox(poly: any, bbox?: BoundBox): BoundBox;
14
14
  export declare function boundboxPoly(bb: BoundBox): any;
15
15
  export declare function boundboxArea(poly: any): number;
16
16
  export declare function boundboxIntersects(bb1: BoundBox, bb2: BoundBox): boolean;
17
+ export declare function boundboxContains(bb: BoundBox, x: number, y: number): boolean;
@@ -2,6 +2,7 @@ import * as FSM from '../fsm/all';
2
2
  import * as Poly from './poly';
3
3
  import * as BB from './boundbox';
4
4
  export interface WrappedPoly {
5
+ f: any;
5
6
  box: BB.BoundBox;
6
7
  p: any;
7
8
  }
@@ -24,11 +25,12 @@ declare class QuadLevel {
24
25
  options: QuadOptions;
25
26
  level: number;
26
27
  children: QuadLevel[];
27
- features: any[];
28
+ features: WrappedPoly[];
28
29
  box: BB.BoundBox;
29
30
  asyncUnion: any;
30
31
  constructor(options: QuadOptions, level: number, box: BB.BoundBox, features: WrappedPoly[]);
31
32
  private featureInBox;
33
+ featureUnderCoord(coord: [number, number]): any;
32
34
  union(): any;
33
35
  get isempty(): boolean;
34
36
  tickUnion(tickCounter: TickCounter): void;
@@ -69,6 +69,7 @@ export declare class BinTrie {
69
69
  constructor(coder: Coder);
70
70
  static fromBuffer(coder: Coder, ab: ArrayBuffer): BinTrie;
71
71
  get(key: string): string;
72
+ forEach(cb: (k: string, v: string) => void): void;
72
73
  }
73
74
  export interface BinTrieOptions {
74
75
  dedup?: boolean;
package/lib/all/all.ts CHANGED
@@ -19,3 +19,5 @@ import { FilterExpr } from '../filterexpr/all';
19
19
  export { FilterExpr }
20
20
  import * as G from '../geo/all';
21
21
  export { G };
22
+ import * as Emit from '../emit/all';
23
+ export { Emit };
@@ -0,0 +1 @@
1
+ export * from './emit';
@@ -0,0 +1,40 @@
1
+ export class Emit
2
+ {
3
+ onList: any;
4
+
5
+ constructor()
6
+ {
7
+ this.onList = {};
8
+ }
9
+
10
+ on(eventName: string, cb: any): void
11
+ {
12
+ let aCB: any = this.onList[eventName];
13
+ if (aCB === undefined)
14
+ {
15
+ aCB = [];
16
+ this.onList[eventName] = aCB;
17
+ }
18
+ aCB.push(cb);
19
+ }
20
+
21
+ emit(eventName: string, arg1?: any, arg2?: any, arg3?: any): void
22
+ {
23
+ let aCB: any[] = this.onList[eventName];
24
+ if (aCB !== undefined)
25
+ for (let i: number = 0; i < aCB.length; i++)
26
+ (aCB[i])(arg1, arg2, arg3);
27
+ }
28
+
29
+ off(eventName: string, cb: any): void
30
+ {
31
+ let aCB: any = this.onList[eventName];
32
+ if (aCB !== undefined)
33
+ for (let i: number = 0; i < aCB.length; i++)
34
+ if (aCB[i] === cb)
35
+ {
36
+ aCB.splice(i, 1);
37
+ break;
38
+ }
39
+ }
40
+ }
@@ -73,12 +73,14 @@ export interface SessionUser
73
73
  {
74
74
  id: string;
75
75
  name: string;
76
+ twitterhandle: string;
76
77
  }
77
78
 
78
79
  export interface ActiveUser
79
80
  {
80
81
  id: string;
81
82
  name: string;
83
+ twitterhandle: string;
82
84
  active: number;
83
85
  }
84
86
 
@@ -100,3 +100,8 @@ export function boundboxIntersects(bb1: BoundBox, bb2: BoundBox): boolean
100
100
  {
101
101
  return !(bb1.left > bb2.right || bb1.right < bb2.left || bb1.top < bb2.bottom || bb1.bottom > bb2.top);
102
102
  }
103
+
104
+ export function boundboxContains(bb: BoundBox, x: number, y: number): boolean
105
+ {
106
+ return !(bb.left >= x || bb.right < x || bb.top <= y || bb.bottom > y);
107
+ }
package/lib/poly/quad.ts CHANGED
@@ -10,6 +10,7 @@ import * as Poly from './poly';
10
10
  import * as PP from './polypack';
11
11
  import * as BB from './boundbox';
12
12
  import * as PR from './polyround';
13
+ import { polyContainsPoint } from './pointinpoly';
13
14
 
14
15
  let _union: any = undefined;
15
16
  let anyPC: any = PC;
@@ -17,7 +18,7 @@ if (anyPC.union) _union = anyPC.union;
17
18
  if (anyPC.default && anyPC.default.union) _union = anyPC.default.union;
18
19
  if (_union === undefined) throw 'Unable to load union function from polygon-clipping';
19
20
 
20
- export interface WrappedPoly { box: BB.BoundBox, p: any };
21
+ export interface WrappedPoly { f: any, box: BB.BoundBox, p: any };
21
22
 
22
23
  export interface WorkDone
23
24
  {
@@ -28,19 +29,6 @@ export interface WorkDone
28
29
 
29
30
  function featureCoords(feature: any): any
30
31
  {
31
- /*
32
- if (feature.geometry !== undefined)
33
- {
34
- if (feature.geometry.packed !== undefined)
35
- return PP.polyUnpack(feature.geometry.packed);
36
- else
37
- return feature.geometry.coordinates;
38
- }
39
- else if (feature.offset !== undefined)
40
- return PP.polyUnpack(feature);
41
- else
42
- return feature;
43
- */
44
32
  if (feature.geometry !== undefined)
45
33
  {
46
34
  if (feature.geometry.packed !== undefined)
@@ -85,7 +73,7 @@ class QuadLevel
85
73
  options: QuadOptions;
86
74
  level: number;
87
75
  children: QuadLevel[];
88
- features: any[];
76
+ features: WrappedPoly[];
89
77
  box: BB.BoundBox;
90
78
  asyncUnion: any;
91
79
 
@@ -98,7 +86,7 @@ class QuadLevel
98
86
  {
99
87
  if (this.level >= options.maxDepth)
100
88
  throw `QuadTree: maximum depth of ${options.maxDepth} exceeded`;
101
- this.features = features.map((wp: WrappedPoly) => wp.p);
89
+ this.features = features;
102
90
  this.children = null;
103
91
  }
104
92
  else
@@ -143,12 +131,33 @@ class QuadLevel
143
131
  return BB.boundboxIntersects(box, f.box);
144
132
  }
145
133
 
134
+ featureUnderCoord(coord: [ number, number ]): any
135
+ {
136
+ if (! BB.boundboxContains(this.box, coord[0], coord[1]))
137
+ return null;
138
+ if (this.features)
139
+ {
140
+ let wp = this.features.find(wp => polyContainsPoint(wp.p, coord[0], coord[1]));
141
+ return wp ? wp.f : null;
142
+ }
143
+ else
144
+ {
145
+ for (let i = 0; i < this.children.length; i++)
146
+ {
147
+ let f = this.children[i].featureUnderCoord(coord);
148
+ if (f)
149
+ return f;
150
+ }
151
+ return null;
152
+ }
153
+ }
154
+
146
155
  union(): any
147
156
  {
148
157
  if (this.asyncUnion == null)
149
158
  {
150
159
  if (this.children == null)
151
- this.asyncUnion = unionPolys(this.features);
160
+ this.asyncUnion = unionPolys(this.features.map(f => f.p));
152
161
  else
153
162
  this.asyncUnion = unionPolys(this.children.map((q: QuadLevel) => q.union()));
154
163
  }
@@ -217,7 +226,7 @@ export class FsmQuadTree extends FSM.Fsm
217
226
  this.isempty = features.length == 0;
218
227
 
219
228
  // Compute BoundBox for each feature
220
- let wrapped: WrappedPoly[] = features.map((f: any) => { return { box: BB.boundbox(f), p: featureCoords(f) } });
229
+ let wrapped: WrappedPoly[] = features.map((f: any) => { return { f: f, box: BB.boundbox(f), p: featureCoords(f) } });
221
230
 
222
231
  let box = BB.boundbox(col);
223
232
  this.quad = new QuadLevel(this.options, 0, box, wrapped);
@@ -57,6 +57,8 @@ Util.setCoder({ encoder: new u.TextEncoder(), decoder: new u.TextDecoder('utf-8'
57
57
  Util.setCoder({ encoder: new TextEncoder(), decoder: new TextDecoder('utf-8') });
58
58
  */
59
59
 
60
+ const MaxKeyLength = 128;
61
+
60
62
  export function s2u8(coder: Coder, s: string): Uint8Array
61
63
  {
62
64
  return coder.encoder.encode(s);
@@ -343,6 +345,23 @@ export class BinTrie
343
345
  }
344
346
  return undefined;
345
347
  }
348
+
349
+ forEach(cb: (k: string, v: string) => void)
350
+ {
351
+ let keybuf = new Uint8Array(MaxKeyLength);
352
+ let keylen = 0;
353
+
354
+ let processNode = (len: number, byteOffset: number) => {
355
+ let iOffset = byteOffset >> 2;
356
+ let n = this.i32[iOffset];
357
+ byteOffset += 4;
358
+ for (let j = 0; j < n; j++)
359
+ {
360
+ keybuf[keylen++] = this.u8[byteOffset+j];
361
+ }
362
+ };
363
+ processNode(0, 4);
364
+ }
346
365
  }
347
366
 
348
367
  export interface BinTrieOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.21",
3
+ "version": "1.0.24",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",