@dra2020/baseclient 1.0.46 → 1.0.49

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.
@@ -6874,16 +6874,68 @@ function polyDistance(poly, x, y) {
6874
6874
  let pp = P.polyNormalize(poly);
6875
6875
  if (pp == null)
6876
6876
  return 0;
6877
- let forEachPointPair = (iter) => {
6878
- PP.polyPackEachRing(pp, (b, iPoly, iRing, iOffset, nPoints) => {
6879
- let iFirst = iOffset;
6880
- let iLast = iOffset + nPoints * 2;
6881
- let iSecond = iLast - 2;
6882
- for (; iFirst < iLast; iSecond = iFirst, iFirst += 2)
6883
- iter(iPoly, iRing, b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
6884
- });
6885
- };
6886
- return pointToPolygonDist(x, y, forEachPointPair);
6877
+ // First find if it is contained in one of the outer polygons, or outside all outer polygons
6878
+ let iContaining = -1;
6879
+ let maxOutside = -Infinity;
6880
+ let minInside = Infinity;
6881
+ let noholes = true;
6882
+ PP.polyPackEachRing(pp, (b, iPoly, iRing, iOffset, nPoints) => {
6883
+ // If we have determined we are inside this polygon, keep track of whether it has holes
6884
+ if (iContaining == iPoly && iRing > 0)
6885
+ noholes = false;
6886
+ // Don't process rings
6887
+ if (iRing > 0)
6888
+ return;
6889
+ // OK, get distance
6890
+ let forEachPointPair = (iter) => {
6891
+ PP.polyPackEachRing(pp, (b, iInteriorPoly, iRing, iOffset, nPoints) => {
6892
+ if (iRing || iInteriorPoly != iPoly)
6893
+ return;
6894
+ let iFirst = iOffset;
6895
+ let iLast = iOffset + nPoints * 2;
6896
+ let iSecond = iLast - 2;
6897
+ for (; iFirst < iLast; iSecond = iFirst, iFirst += 2)
6898
+ iter(b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
6899
+ });
6900
+ };
6901
+ let dist = pointToPolygonDist(x, y, forEachPointPair);
6902
+ // If inside, is it closest inside (deal with multipolygons that self-contain - think filled donut)
6903
+ if (dist > 0 && dist < minInside) {
6904
+ iContaining = iPoly;
6905
+ minInside = dist;
6906
+ noholes = true;
6907
+ }
6908
+ else if (dist < 0)
6909
+ maxOutside = Math.max(maxOutside, dist);
6910
+ });
6911
+ if (iContaining < 0)
6912
+ return maxOutside;
6913
+ if (noholes)
6914
+ return minInside;
6915
+ // OK, now need to worry about holes in the polygon it is contained in
6916
+ PP.polyPackEachRing(pp, (b, iPoly, iRing, iOffset, nPoints) => {
6917
+ // Only want to look at the holes for the containing polygon
6918
+ if (iPoly != iContaining || iRing == 0)
6919
+ return;
6920
+ // Compute distance to those holes
6921
+ let forEachPointPair = (iter) => {
6922
+ PP.polyPackEachRing(pp, (b, iInteriorPoly, iRing, iOffset, nPoints) => {
6923
+ if (iInteriorPoly != iContaining || iRing == 0)
6924
+ return;
6925
+ let iFirst = iOffset;
6926
+ let iLast = iOffset + nPoints * 2;
6927
+ let iSecond = iLast - 2;
6928
+ for (; iFirst < iLast; iSecond = iFirst, iFirst += 2)
6929
+ iter(b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
6930
+ });
6931
+ };
6932
+ // Negate distance since dealing with holes
6933
+ let dist = -pointToPolygonDist(x, y, forEachPointPair);
6934
+ // We take the min to either get a negative value (inside hole) or a smaller positive value
6935
+ // (outside hole but close to hole boundary).
6936
+ minInside = Math.min(minInside, dist);
6937
+ });
6938
+ return minInside;
6887
6939
  }
6888
6940
  exports.polyDistance = polyDistance;
6889
6941
  //
@@ -6922,7 +6974,7 @@ function polyLabel(poly, precision, debug) {
6922
6974
  let iLast = iOffset + nPoints * 2;
6923
6975
  let iSecond = iLast - 2;
6924
6976
  for (; iFirst < iLast; iSecond = iFirst, iFirst += 2)
6925
- iter(iPoly, iRing, b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
6977
+ iter(b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
6926
6978
  });
6927
6979
  };
6928
6980
  // find the bounding box of the outer ring
@@ -6996,34 +7048,13 @@ class Cell {
6996
7048
  }
6997
7049
  // signed distance from point to polygon outline (negative if point is outside)
6998
7050
  function pointToPolygonDist(x, y, forEachPointPair) {
6999
- let iPolyLast = -1;
7000
- let iRingLast = -1;
7001
7051
  let inside = false;
7002
- let thisInside = false;
7003
- let useInside = false;
7004
- let isHole = false;
7005
7052
  let minDistSq = Infinity;
7006
- forEachPointPair((iPoly, iRing, ax, ay, bx, by) => {
7007
- if (iPoly != iPolyLast || iRing != iRingLast) {
7008
- if (useInside)
7009
- inside = isHole ? !thisInside : thisInside;
7010
- iPolyLast = iPoly;
7011
- iRingLast = iRing;
7012
- thisInside = false;
7013
- useInside = false;
7014
- isHole = false;
7015
- }
7053
+ forEachPointPair((ax, ay, bx, by) => {
7016
7054
  if ((ay > y !== by > y) && (x < (bx - ax) * (y - ay) / (by - ay) + ax))
7017
- thisInside = !thisInside;
7018
- let thisDistSq = getSegDistSq(x, y, ax, ay, bx, by);
7019
- if (thisDistSq < minDistSq) {
7020
- minDistSq = thisDistSq;
7021
- useInside = true;
7022
- isHole = iRing != 0;
7023
- }
7055
+ inside = !inside;
7056
+ minDistSq = Math.min(minDistSq, getSegDistSq(x, y, ax, ay, bx, by));
7024
7057
  });
7025
- if (useInside)
7026
- inside = isHole ? !thisInside : thisInside;
7027
7058
  return (inside ? 1 : -1) * Math.sqrt(minDistSq);
7028
7059
  }
7029
7060
  // get polygon centroid
@@ -7033,7 +7064,7 @@ function getCentroidCell(forEachPointPair) {
7033
7064
  let y = 0;
7034
7065
  let fx;
7035
7066
  let fy;
7036
- forEachPointPair((iPoly, iRing, ax, ay, bx, by) => {
7067
+ forEachPointPair((ax, ay, bx, by) => {
7037
7068
  if (fx === undefined)
7038
7069
  fx = ax, fy = ay;
7039
7070
  let f = ax * by - bx * ay;
@@ -8350,7 +8381,6 @@ const P = __importStar(__webpack_require__(/*! ./poly */ "./lib/poly/poly.ts"));
8350
8381
  const PP = __importStar(__webpack_require__(/*! ./polypack */ "./lib/poly/polypack.ts"));
8351
8382
  const PL = __importStar(__webpack_require__(/*! ./polylabel */ "./lib/poly/polylabel.ts"));
8352
8383
  const shamos_1 = __webpack_require__(/*! ./shamos */ "./lib/poly/shamos.ts");
8353
- const pointinpoly_1 = __webpack_require__(/*! ./pointinpoly */ "./lib/poly/pointinpoly.ts");
8354
8384
  function getGEOID(f) {
8355
8385
  if (f.features && f.features.length)
8356
8386
  f = f.features[0];
@@ -8601,16 +8631,20 @@ function topoSimplifyCollection(col, options) {
8601
8631
  }
8602
8632
  if (!bDecided) {
8603
8633
  let pp = PP.polyPackTopoArcs(testtopo, arcs);
8634
+ P.polyRewindRings(pp);
8604
8635
  if (shamos_1.selfIntersectFast(pp)) {
8605
8636
  keepArcs(topo, oOld.arcs, keepweight);
8606
8637
  nBad++;
8607
8638
  }
8608
8639
  else {
8609
8640
  let { x, y } = intpt(f);
8610
- if (x && y && !pointinpoly_1.polyContainsPoint(pp, x, y)) {
8611
- keepArcs(topo, oOld.arcs, keepweight);
8612
- nBad++;
8613
- log(`topoSimplifyCollection: ${f.properties.id}: increasing feature fidelity because of intpt problem`);
8641
+ let d = PL.polyDistance(pp, x, y);
8642
+ if (d < 0.00001) // d is negative if outside the polygon, so that qualifies here
8643
+ {
8644
+ keepTiny.set(f, f);
8645
+ keepArcs(topo, oOld.arcs, 0); // keeps all points to avoid reprocessing these tiny shapes
8646
+ nBad++, nTiny++;
8647
+ log(`topoSimplifyCollection: ${f.properties.id}: increasing feature fidelity because intpt dist is ${d}`);
8614
8648
  }
8615
8649
  }
8616
8650
  }