@dra2020/baseclient 1.0.59 → 1.0.62

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.
@@ -223,6 +223,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
223
223
  return result;
224
224
  };
225
225
  Object.defineProperty(exports, "__esModule", ({ value: true }));
226
+ exports.ParseOne = void 0;
226
227
  const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
227
228
  // Parse CSV.
228
229
  // Fields are separated by commas or pipe symbol (census uses pipe separators.
@@ -248,6 +249,8 @@ class ParseOne {
248
249
  this.coder = coder;
249
250
  if (line)
250
251
  this.set(line);
252
+ else
253
+ this.fields = [];
251
254
  }
252
255
  set(line) {
253
256
  this.fields = [];
@@ -258,31 +261,37 @@ class ParseOne {
258
261
  this.infield = false;
259
262
  this.nwhite = 0;
260
263
  this.quote = 0;
264
+ this.force = false;
261
265
  this.parse();
262
266
  }
263
267
  get length() { return this.fields.length; }
264
- pushtok(force) {
268
+ pushtok() {
265
269
  // Trim trailing whitespace
266
- if (!force)
267
- this.toklen -= this.nwhite;
268
- if (this.toklen || force) {
270
+ this.toklen -= this.nwhite;
271
+ if (this.toklen || this.force) {
269
272
  this.fields.push(Util.u82s(this.coder, this.tok, 0, this.toklen));
270
273
  this.toklen = 0;
271
274
  }
272
275
  this.infield = false;
273
276
  this.nwhite = 0;
274
277
  this.quote = 0;
278
+ this.force = false;
275
279
  }
276
280
  parse() {
277
281
  while (this.n < this.buf.length) {
278
282
  let c = this.buf[this.n++];
279
- if (this.quote && c === this.quote)
280
- this.pushtok(true);
281
- else if (c === Comma || c === Pipe)
282
- this.pushtok(true);
283
+ if (this.quote && c === this.quote) {
284
+ this.quote = 0;
285
+ this.nwhite = 0;
286
+ }
287
+ else if (c === Comma || c === Pipe) {
288
+ this.force = true;
289
+ this.pushtok();
290
+ this.force = true;
291
+ }
283
292
  else if (this.infield) {
284
293
  this.tok[this.toklen++] = c;
285
- if (isWhite(c))
294
+ if (!this.quote && isWhite(c))
286
295
  this.nwhite++;
287
296
  else
288
297
  this.nwhite = 0;
@@ -292,15 +301,18 @@ class ParseOne {
292
301
  else if (c === SingleQuote || c === DoubleQuote) {
293
302
  this.quote = c;
294
303
  this.infield = true;
304
+ this.force = true;
295
305
  }
296
306
  else {
297
307
  this.infield = true;
298
308
  this.tok[this.toklen++] = c;
309
+ this.force = true;
299
310
  }
300
311
  }
301
- this.pushtok(false);
312
+ this.pushtok();
302
313
  }
303
314
  }
315
+ exports.ParseOne = ParseOne;
304
316
 
305
317
 
306
318
  /***/ }),
@@ -6230,7 +6242,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
6230
6242
  return result;
6231
6243
  };
6232
6244
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6233
- exports.polyBadCoordinates = exports.polyRewindRings = exports.featureRewind = exports.polyTransform = exports.npoints = exports.polyDescribe = exports.polyCompactness = exports.makeConvexHullMonotoneChain2D = exports.polyConvexHull = exports.polyToExteriorPoints = exports.polyFromCircle = exports.polyToPolsbyPopperCircle = exports.polyToCircle = exports.Circle = exports.polyPerimeter = exports.polyDiameter = exports.polyArea = exports.polyNull = exports.polyNormalize = exports.polySimpleArea = exports.DefaultOptions = exports.EARTH_RADIUS = exports.DefaultTickOptions = void 0;
6245
+ exports.polyBadCoordinates = exports.polyRewindRings = exports.featureRewind = exports.polyRingWindings = exports.polyTransform = exports.npoints = exports.polyDescribe = exports.polyCompactness = exports.makeConvexHullMonotoneChain2D = exports.polyConvexHull = exports.polyToExteriorPoints = exports.polyFromCircle = exports.polyToPolsbyPopperCircle = exports.polyToCircle = exports.Circle = exports.polyPerimeter = exports.polyDiameter = exports.polyArea = exports.polyNull = exports.polyNormalize = exports.polySimpleArea = exports.DefaultOptions = exports.EARTH_RADIUS = exports.DefaultTickOptions = void 0;
6234
6246
  const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
6235
6247
  const PP = __importStar(__webpack_require__(/*! ./polypack */ "./lib/poly/polypack.ts"));
6236
6248
  const graham_scan_1 = __webpack_require__(/*! ./graham-scan */ "./lib/poly/graham-scan.ts");
@@ -6750,30 +6762,119 @@ function closePoly(poly) {
6750
6762
  poly.forEach(closeRing);
6751
6763
  return poly;
6752
6764
  }
6765
+ function closeFeature(f) {
6766
+ let d = Util.depthof(f.geometry.coordinates);
6767
+ if (d === 4)
6768
+ closePoly(f.geometry.coordinates);
6769
+ if (d === 5)
6770
+ f.geometry.coordinates.forEach(closePoly);
6771
+ }
6772
+ function canonicalPoint(f, options) {
6773
+ if (options.canonical)
6774
+ if (f && f.geometry && f.geometry.type === 'Point' && f.geometry.coordinates)
6775
+ while (Array.isArray(f.geometry.coordinates[0]))
6776
+ f.geometry.coordinates = f.geometry.coordinates[0];
6777
+ return f;
6778
+ }
6779
+ ;
6780
+ function misWound(w) {
6781
+ return (((w.iRing == 0) && (w.direction > 0)) || ((w.iRing > 0) && (w.direction < 0)));
6782
+ }
6783
+ function polyRingWindings(poly) {
6784
+ let windings = [];
6785
+ let pp = polyNormalize(poly);
6786
+ if (pp == null || pp.buffer == null)
6787
+ return windings;
6788
+ PP.polyPackEachRing(pp, (b, iPoly, iRing, iOffset, nPoints) => {
6789
+ const iStart = iOffset;
6790
+ const iEnd = iStart + (nPoints * 2) - 2;
6791
+ // Determine the winding order of the ring
6792
+ let direction = 0;
6793
+ // Start at the second point
6794
+ iOffset += 2;
6795
+ for (; iOffset <= iEnd; iOffset += 2) {
6796
+ // The previous point
6797
+ let jOffset = iOffset - 2;
6798
+ // Sum over the edges
6799
+ direction += twoTimesArea(b[iOffset], b[jOffset], b[iOffset + 1], b[jOffset + 1]);
6800
+ }
6801
+ // Implicitly close the ring, if necessary
6802
+ if (nPoints > 2 && (b[iStart] != b[iEnd] || b[iStart + 1] != b[iEnd + 1]))
6803
+ direction += twoTimesArea(b[iStart], b[iEnd], b[iStart + 1], b[iEnd + 1]);
6804
+ windings.push({ iPoly: iPoly, iRing: iRing, direction: direction });
6805
+ });
6806
+ return windings;
6807
+ }
6808
+ exports.polyRingWindings = polyRingWindings;
6753
6809
  // This mutates the passed in feature to ensure it is correctly wound
6754
6810
  // For convenience, passed back the value provided.
6755
- function featureRewind(poly) {
6756
- let pp = polyNormalize(poly);
6757
- if (pp == null)
6811
+ //
6812
+ function featureRewind(f, options) {
6813
+ options = Util.shallowAssignImmutable({ validateHoles: true, validateClose: true, canonical: true }, options);
6814
+ if (!f)
6758
6815
  return null;
6759
- polyRewindRings(pp);
6760
- if (poly.type === 'Feature') {
6761
- if (poly.geometry.packed !== pp) {
6762
- poly.geometry.coordinates = PP.polyUnpack(pp);
6763
- // Also make sure first === last coordinate
6764
- let d = Util.depthof(poly.geometry.coordinates);
6765
- if (d === 4)
6766
- closePoly(poly.geometry.coordinates);
6767
- else if (d === 5)
6768
- poly.geometry.coordinates.forEach(closePoly);
6769
- poly.geometry.type = d === 4 ? 'Polygon' : 'MultiPolygon';
6770
- }
6771
- return poly;
6772
- }
6773
- else if (poly === pp)
6774
- return pp;
6775
- else
6776
- return PP.polyUnpack(pp);
6816
+ // Has to be an unpacked feature
6817
+ if (f.type !== 'Feature')
6818
+ throw 'featureRewind: must be a valid GeoJSON feature';
6819
+ if (!f.geometry || f.geometry.packed)
6820
+ throw 'featureRewind: only valid on unpacked features';
6821
+ // Non polygons are simpler
6822
+ if (f.geometry.type !== 'Polygon' && f.geometry.type !== 'MultiPolygon')
6823
+ return canonicalPoint(f, options);
6824
+ // Make sure polygon is closed (first === last)
6825
+ if (options.validateClose)
6826
+ closeFeature(f);
6827
+ // Check if multi-polygon is really polygon with holes
6828
+ // Only applies to multi-polygons with no holes
6829
+ let d = Util.depthof(f.geometry.coordinates);
6830
+ let windings = polyRingWindings(f);
6831
+ if (options.validateHoles && d === 5 && windings.length) {
6832
+ // If there are explicit holes, don't look for implicit ones
6833
+ let nHoles = 0;
6834
+ windings.forEach(w => { if (w.iRing)
6835
+ nHoles++; });
6836
+ if (nHoles == 0 && !misWound(windings[0])) {
6837
+ // Looking for pattern: of (G (B*))*
6838
+ // To convert to ((GH*))*
6839
+ let iWinding = 0;
6840
+ let polys = f.geometry.coordinates;
6841
+ let iPoly;
6842
+ for (; iWinding < windings.length; iWinding++) {
6843
+ let good = !misWound(windings[iWinding]);
6844
+ if (!good && iWinding == 0) // First is miswound - no good
6845
+ break;
6846
+ if (good)
6847
+ iPoly = iWinding;
6848
+ else {
6849
+ polys[iPoly].push(polys[iWinding][0]);
6850
+ polys[iWinding] = null;
6851
+ }
6852
+ }
6853
+ f.geometry.coordinates = polys.filter((p) => p != null);
6854
+ }
6855
+ // Degenerate multi-polygon
6856
+ if (f.geometry.coordinates.length == 1) {
6857
+ f.geometry.type = 'Polygon';
6858
+ f.geometry.coordinates = f.geometry.coordinates[0];
6859
+ }
6860
+ }
6861
+ // OK, now go through each ring
6862
+ let polys = f.geometry.coordinates;
6863
+ windings = polyRingWindings(f);
6864
+ windings.forEach((w) => {
6865
+ let good = !misWound(w);
6866
+ if (!good) {
6867
+ let ring = polys[w.iPoly][w.iRing];
6868
+ let iFront = 0;
6869
+ let iBack = ring.length - 1;
6870
+ for (; iFront < iBack; iFront++, iBack--) {
6871
+ let tmp = ring[iFront];
6872
+ ring[iFront] = ring[iBack];
6873
+ ring[iBack] = tmp;
6874
+ }
6875
+ }
6876
+ });
6877
+ return f;
6777
6878
  }
6778
6879
  exports.featureRewind = featureRewind;
6779
6880
  //
@@ -8699,7 +8800,7 @@ function correctGeometry(f) {
8699
8800
  }
8700
8801
  else
8701
8802
  // TopoJSON does not guarantee proper winding order which messes up later processing. Fix it.
8702
- P.featureRewind(f);
8803
+ P.featureRewind(f, { validateHoles: false });
8703
8804
  return f;
8704
8805
  }
8705
8806
  function topoContiguity(topo) {