@dra2020/baseclient 1.0.44 → 1.0.45

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.
@@ -6862,11 +6862,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6862
6862
  return (mod && mod.__esModule) ? mod : { "default": mod };
6863
6863
  };
6864
6864
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6865
- exports.polyLabel = void 0;
6865
+ exports.polyLabel = exports.polyDistance = void 0;
6866
6866
  const tinyqueue_1 = __importDefault(__webpack_require__(/*! tinyqueue */ "tinyqueue"));
6867
6867
  const P = __importStar(__webpack_require__(/*! ./poly */ "./lib/poly/poly.ts"));
6868
6868
  const PP = __importStar(__webpack_require__(/*! ./polypack */ "./lib/poly/polypack.ts"));
6869
6869
  //
6870
+ // polyDistance: return (smallest) distance to polygon edge.
6871
+ // Positive value indicates point is in poly, negative indicates point is outside.
6872
+ //
6873
+ function polyDistance(poly, x, y) {
6874
+ let pp = P.polyNormalize(poly);
6875
+ if (pp == null)
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);
6887
+ }
6888
+ exports.polyDistance = polyDistance;
6889
+ //
6870
6890
  // polyLabel: given polygon, return contained point furthest from any edge, and that distance
6871
6891
  //
6872
6892
  function polyLabel(poly, precision, debug) {
@@ -6902,7 +6922,7 @@ function polyLabel(poly, precision, debug) {
6902
6922
  let iLast = iOffset + nPoints * 2;
6903
6923
  let iSecond = iLast - 2;
6904
6924
  for (; iFirst < iLast; iSecond = iFirst, iFirst += 2)
6905
- iter(b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
6925
+ iter(iPoly, iRing, b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
6906
6926
  });
6907
6927
  };
6908
6928
  // find the bounding box of the outer ring
@@ -6976,13 +6996,34 @@ class Cell {
6976
6996
  }
6977
6997
  // signed distance from point to polygon outline (negative if point is outside)
6978
6998
  function pointToPolygonDist(x, y, forEachPointPair) {
6999
+ let iPolyLast = -1;
7000
+ let iRingLast = -1;
6979
7001
  let inside = false;
7002
+ let thisInside = false;
7003
+ let useInside = false;
7004
+ let isHole = false;
6980
7005
  let minDistSq = Infinity;
6981
- forEachPointPair((ax, ay, bx, by) => {
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
+ }
6982
7016
  if ((ay > y !== by > y) && (x < (bx - ax) * (y - ay) / (by - ay) + ax))
6983
- inside = !inside;
6984
- minDistSq = Math.min(minDistSq, getSegDistSq(x, y, ax, ay, bx, by));
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
+ }
6985
7024
  });
7025
+ if (useInside)
7026
+ inside = isHole ? !thisInside : thisInside;
6986
7027
  return (inside ? 1 : -1) * Math.sqrt(minDistSq);
6987
7028
  }
6988
7029
  // get polygon centroid
@@ -6992,7 +7033,7 @@ function getCentroidCell(forEachPointPair) {
6992
7033
  let y = 0;
6993
7034
  let fx;
6994
7035
  let fy;
6995
- forEachPointPair((ax, ay, bx, by) => {
7036
+ forEachPointPair((iPoly, iRing, ax, ay, bx, by) => {
6996
7037
  if (fx === undefined)
6997
7038
  fx = ax, fy = ay;
6998
7039
  let f = ax * by - bx * ay;