@dra2020/baseclient 1.0.60 → 1.0.61

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.
@@ -6242,7 +6242,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
6242
6242
  return result;
6243
6243
  };
6244
6244
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6245
- 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;
6246
6246
  const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
6247
6247
  const PP = __importStar(__webpack_require__(/*! ./polypack */ "./lib/poly/polypack.ts"));
6248
6248
  const graham_scan_1 = __webpack_require__(/*! ./graham-scan */ "./lib/poly/graham-scan.ts");
@@ -6762,30 +6762,119 @@ function closePoly(poly) {
6762
6762
  poly.forEach(closeRing);
6763
6763
  return poly;
6764
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;
6765
6809
  // This mutates the passed in feature to ensure it is correctly wound
6766
6810
  // For convenience, passed back the value provided.
6767
- function featureRewind(poly) {
6768
- let pp = polyNormalize(poly);
6769
- if (pp == null)
6811
+ //
6812
+ function featureRewind(f, options) {
6813
+ options = Util.shallowAssignImmutable({ validateHoles: true, validateClose: true, canonical: true }, options);
6814
+ if (!f)
6770
6815
  return null;
6771
- polyRewindRings(pp);
6772
- if (poly.type === 'Feature') {
6773
- if (poly.geometry.packed !== pp) {
6774
- poly.geometry.coordinates = PP.polyUnpack(pp);
6775
- // Also make sure first === last coordinate
6776
- let d = Util.depthof(poly.geometry.coordinates);
6777
- if (d === 4)
6778
- closePoly(poly.geometry.coordinates);
6779
- else if (d === 5)
6780
- poly.geometry.coordinates.forEach(closePoly);
6781
- poly.geometry.type = d === 4 ? 'Polygon' : 'MultiPolygon';
6782
- }
6783
- return poly;
6784
- }
6785
- else if (poly === pp)
6786
- return pp;
6787
- else
6788
- 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;
6789
6878
  }
6790
6879
  exports.featureRewind = featureRewind;
6791
6880
  //
@@ -8711,7 +8800,7 @@ function correctGeometry(f) {
8711
8800
  }
8712
8801
  else
8713
8802
  // TopoJSON does not guarantee proper winding order which messes up later processing. Fix it.
8714
- P.featureRewind(f);
8803
+ P.featureRewind(f, { validateHoles: false });
8715
8804
  return f;
8716
8805
  }
8717
8806
  function topoContiguity(topo) {