From e59a23054bbaf71124ca1e7e642f1108b5c68786 Mon Sep 17 00:00:00 2001
From: jinglun-cloud <jinglun2019@foxmail.com>
Date: 星期三, 06 五月 2026 10:13:08 +0800
Subject: [PATCH] 运动都放到中轨上计算

---
 src/main/webapp/static/js/basMap/mapTrackGeometry.js |  219 +++++++-----------------------------------------------
 1 files changed, 29 insertions(+), 190 deletions(-)

diff --git a/src/main/webapp/static/js/basMap/mapTrackGeometry.js b/src/main/webapp/static/js/basMap/mapTrackGeometry.js
index f7ad23b..3c86fdb 100644
--- a/src/main/webapp/static/js/basMap/mapTrackGeometry.js
+++ b/src/main/webapp/static/js/basMap/mapTrackGeometry.js
@@ -1,7 +1,7 @@
 /**
  * 鐜┛ / 骞虫粦杞ㄩ亾鍑犱綍锛氱洿瑙掑杈瑰舰杞渾寮ц矾寰勩�丳IXI 缁樺埗銆佽澶囨湞鍚戠瓑銆�
+ * 鐜┛鎸佷箙鍖栫殑 pathList 涓轰腑杞紱澶栧湀銆佸唴鍦堜粎鍦ㄧ粯鍒舵椂鐢� buildAnnulusPaths 璁$畻銆�
  * 渚� basMap 缂栬緫鍣ㄤ笌鐩戞帶 MapCanvas 鍏辩敤銆傞渶鍦ㄩ〉闈腑鍏堜簬 editor.js / MapCanvas.js 寮曞叆銆�
- * 璁惧澶栬锛圕RN / RGV锛夌粯鍒朵笌 MapCanvas 璐村浘涓�鑷达紝瑙� drawCrnDeviceGraphics / drawRgvDeviceGraphics銆�
  */
 (function (global) {
   'use strict';
@@ -258,7 +258,6 @@
         return deviceForm;
       }
       var allDistance = getAllDistance(pathList);
-      var ab = annulusBandContext(rect, rect.shape || 'rect');
       deviceForm.deviceList.forEach(function (item) {
         var deltaDistance = (allDistance * item.progress) / 100;
         var startPoint = {
@@ -271,16 +270,8 @@
           pathIndex: 0,
           deltaDistance: deltaDistance
         });
-        var centered = shiftAnnulusPointToBandCenter(
-          moved.x,
-          moved.y,
-          moved.path,
-          ab.inset,
-          ab.refInside
-        );
-
-        item.x = centered.x;
-        item.y = centered.y;
+        item.x = moved.x;
+        item.y = moved.y;
         item.path = moved.path;
         item.width = item.deviceLength;
         item.height = item.deviceWidth;
@@ -396,69 +387,6 @@
   }
 
   /**
-   * 灏勭嚎娉曞垽鐐规槸鍚﹀湪绠�鍗曞杈瑰舰鍐咃紙鐢ㄤ簬鎵惧弬鑰冨唴鐐癸紝绠楀唴鍚戞硶鍚戯級銆�
-   * @param {{ x: number, y: number }} pt
-   * @param {{ x: number, y: number }[]} ring
-   * @returns {boolean}
-   */
-  function pointInPolygon(pt, ring) {
-    var inside = false;
-    var n = ring.length;
-    var i;
-    for (i = 0; i < n; i++) {
-      var a = ring[i];
-      var b = ring[(i + 1) % n];
-      var intersects =
-        a.y > pt.y !== b.y > pt.y &&
-        pt.x < ((b.x - a.x) * (pt.y - a.y)) / (b.y - a.y + 1e-12) + a.x;
-      if (intersects) {
-        inside = !inside;
-      }
-    }
-    return inside;
-  }
-
-  /**
-   * 鍦ㄥ皷鐐圭幆鍖呭洿鐩掑唴閲囨牱锛屽緱鍒板杈瑰舰鍐呴儴涓�鐐癸紝渚涚洿绾挎涓婂垽鏂�屾寚鍚戝唴渚с�嶇殑娉曞悜銆�
-   * @param {{ x: number, y: number }[]} pointList
-   * @returns {{ x: number, y: number }}
-   */
-  function findInteriorRefPoint(pointList) {
-    var minX = Infinity;
-    var minY = Infinity;
-    var maxX = -Infinity;
-    var maxY = -Infinity;
-    var i;
-    for (i = 0; i < pointList.length; i++) {
-      var p = pointList[i];
-      minX = Math.min(minX, p.x);
-      minY = Math.min(minY, p.y);
-      maxX = Math.max(maxX, p.x);
-      maxY = Math.max(maxY, p.y);
-    }
-    var cx = (minX + maxX) / 2;
-    var cy = (minY + maxY) / 2;
-    if (pointInPolygon({ x: cx, y: cy }, pointList)) {
-      return { x: cx, y: cy };
-    }
-    var g;
-    for (g = 1; g <= 6; g++) {
-      var sj;
-      for (sj = 1; sj < g; sj++) {
-        var si;
-        for (si = 1; si < g; si++) {
-          var tx = minX + ((maxX - minX) * si) / g;
-          var ty = minY + ((maxY - minY) * sj) / g;
-          if (pointInPolygon({ x: tx, y: ty }, pointList)) {
-            return { x: tx, y: ty };
-          }
-        }
-      }
-    }
-    return { x: cx, y: cy };
-  }
-
-  /**
    * 鏈夊悜杈� (ax,ay)鈫�(bx,by) 娌跨幆鍓嶈繘鏂瑰悜鐨勫崟浣嶅唴鍚戞硶鍚戦噺锛堥�嗘椂閽堢幆鏃跺唴渚у湪鍓嶈繘鏂瑰悜宸︿晶锛夈��
    * @param {number} ax
    * @param {number} ay
@@ -552,6 +480,7 @@
     return out;
   }
 
+  // 鏆傛椂娉ㄩ噴鎺夈�備互鍚庡啀鑰冭檻鍔犱笂銆傚厛涓嶅垹闄ゃ��
   /**
    * 瑙f瀽鐜┛鍗曚晶鍐呯缉鍍忕礌璺濈锛涜嫢浼犲叆 `precomputedSharp` 鍒欎笉鍐嶉噸澶嶆眰灏栫偣鐜��
    * @param {{ width: number, height: number, shape?: string, annulusBandInset?: number, value?: string|object }} sprite
@@ -603,17 +532,16 @@
   // }
 
   /**
-   * 鐜┛鍏辩敤锛氬皷鐐圭幆銆佸唴渚у弬鑰冪偣銆乮nset锛堝彧绠椾竴閬嶅皷鐐癸紝閬垮厤澶氬閲嶅 getSharpCornerList锛夈��
+   * 鐜┛鍏辩敤锛氬皷鐐圭幆銆乮nset锛堝彧绠椾竴閬嶅皷鐐癸級銆�
    * @param {object} sprite x/y/width/height/shape/turningPoint/annulusBandInset
    * @param {string} defaultShape
-   * @returns {{ sharp: object[], refInside: {x:number,y:number}, inset: number }}
+   * @returns {{ sharp: object[], inset: number }}
    */
   function annulusBandContext(sprite, defaultShape) {
     sprite.shape = sprite.shape || defaultShape;
     var sharp = getSharpCornerList(sprite, defaultShape);
     return {
       sharp: sharp,
-      refInside: findInteriorRefPoint(sharp),
       inset: 6
     };
   }
@@ -871,12 +799,12 @@
   }
 
   /**
-   * 鐢熸垚澶栧湀涓庡唴鍦� smooth pathList锛涘唴鍦堢敱姝d氦灏栫偣鐜� offset 鍚庡啀 setRadius/smooth銆�
+   * 澶栧湀銆佷腑杞ㄣ�佸唴鍦堬細澶�/鍐呬粎鐢ㄤ簬缁樺埗锛涗腑杞ㄤ负 pathList 涓庤繍鍔ㄥ鎵�鐢ㄣ��
    * @param {{ x: number, y: number, width: number, height: number, shape?: string, turningPoint?: object, annulusBandInset?: number }} sprite
    * @param {string} defaultShape
-   * @returns {{ outerPath: object[], innerPath: object[]|null, inset: number }}
+   * @returns {{ outerPath: object[], innerPath: object[]|null, centerPath: object[], inset: number }}
    */
-  function buildOuterAndInnerPaths(sprite, defaultShape) {
+  function buildAnnulusPaths(sprite, defaultShape) {
     var ctx = annulusBandContext(sprite, defaultShape);
     var sharp = ctx.sharp;
     var sharpClone = sharp.map(function (p) {
@@ -887,112 +815,32 @@
     var inset = ctx.inset;
     var minSide = Math.min(sprite.width, sprite.height);
     if (inset <= 0 || minSide <= inset * 2 + 4) {
-      return { outerPath: outerPath, innerPath: null, inset: inset };
+      return { outerPath: outerPath, innerPath: null, centerPath: outerPath, inset: inset };
     }
+    var centerSharp = offsetOrthogonalSharpRing(
+      sharpClone.map(function (p) {
+        return { x: p.x, y: p.y, direction: p.direction };
+      }),
+      inset / 2
+    );
+    var centerMeta = {};
+    setRadiusInPoint(centerSharp, centerMeta);
+    var centerPath = smoothRightAnglePath(centerSharp);
     var innerSharp = offsetOrthogonalSharpRing(sharpClone, inset);
     var innerMeta = {};
     setRadiusInPoint(innerSharp, innerMeta);
     var innerPath = smoothRightAnglePath(innerSharp);
-    return { outerPath: outerPath, innerPath: innerPath, inset: inset };
+    return { outerPath: outerPath, innerPath: innerPath, centerPath: centerPath, inset: inset };
   }
 
   /**
-   * 澶栬疆寤撲笂涓�鐐规部娉曞悜锛堢洿绾挎锛夋垨寰勫悜锛堝渾寮ф锛夊唴绉� half锛岃惤鍦ㄥ弻杞ㄥ嚑浣曚腑绾裤��
-   * @param {number} x
-   * @param {number} y
-   * @param {object} path 褰撳墠娈� line|arc
-   * @param {number} inset 鍗曚晶甯﹀
-   * @param {{ x: number, y: number }} refInside 澶氳竟褰㈠唴鍙傝�冪偣
-   * @returns {{ x: number, y: number }}
-   */
-  function shiftAnnulusPointToBandCenter(x, y, path, inset, refInside) {
-    var half = inset / 2;
-    if (half <= 0) {
-      return { x: x, y: y };
-    }
-    if (path.type === 'line') {
-      var tx = path.x - path.startX;
-      var ty = path.y - path.startY;
-      var tlen = Math.sqrt(tx * tx + ty * ty) || 1;
-      var nx = -ty / tlen;
-      var ny = tx / tlen;
-      var mx = (path.startX + path.x) / 2;
-      var my = (path.startY + path.y) / 2;
-      if ((refInside.x - mx) * nx + (refInside.y - my) * ny < 0) {
-        nx = -nx;
-        ny = -ny;
-      }
-      return { x: x + nx * half, y: y + ny * half };
-    }
-    if (path.type === 'arc') {
-      var ox = x - path.x;
-      var oy = y - path.y;
-      var olen = Math.sqrt(ox * ox + oy * oy) || 1;
-      return { x: x - (ox / olen) * half, y: y - (oy / olen) * half };
-    }
-    return { x: x, y: y };
-  }
-
-  /**
-   * 灏嗗鍦� path 涓婂潗鏍囨槧灏勫埌杞ㄩ亾甯︿腑绾匡紙鐩戞帶/鏉$爜涓庣紪杈戝櫒涓�鑷达級銆�
-   * @param {{ type: string, x: number, y: number, width: number, height: number, shape?: string, turningPoint?: object, annulusBandInset?: number }} element
-   * @param {number} x
-   * @param {number} y
-   * @param {object} path
-   * @returns {{ x: number, y: number }}
-   */
-  function centerAnnulusBandPoint(element, x, y, path) {
-    if (!element || element.type !== 'annulus' || path == null) {
-      return { x: x, y: y };
-    }
-    var ctx = annulusBandContext(element, element.shape || 'rect');
-    return shiftAnnulusPointToBandCenter(x, y, path, ctx.inset, ctx.refInside);
-  }
-
-  /**
-   * 鐜┛锛氭妸 getPositionAfterMove 绛夎繑鍥炵殑 position 鍘嬪埌杞ㄥ甫涓嚎锛涢潪鐜┛鎴栨棤鏁� position 鍘熸牱杩斿洖銆�
-   * @param {{ type: string }} trackInfo
-   * @param {{ x: number, y: number, path?: object }|null|undefined} position
-   * @returns {typeof position}
-   */
-  function applyAnnulusBandCenterToPosition(trackInfo, position) {
-    if (!position || !trackInfo || trackInfo.type !== 'annulus') {
-      return position;
-    }
-    var c = centerAnnulusBandPoint(trackInfo, position.x, position.y, position.path);
-    return Object.assign({}, position, { x: c.x, y: c.y });
-  }
-
-  /**
-   * 娌� pathList 绉诲姩鍚庡啀瀵圭幆绌垮仛杞ㄥ甫涓嚎淇锛堜笌 getPositionAfterMove + applyAnnulusBandCenterToPosition 绛変环锛夈��
-   * @param {{ type: string }} trackInfo
-   * @param {{ x: number, y: number }} point 璧风偣锛涚幆绌夸笂搴斿湪澶栧湀 path 涓�
-   * @param {object[]} pathList
-   * @param {object} path
-   * @param {number} deltaDistance
-   * @param {number} [angle]
-   * @returns {{ x: number, y: number, path: object, angle?: number }} 涓� getPositionAfterMove 杩斿洖褰㈡�佷竴鑷�
-   */
-  function computeFinalPosition(trackInfo, point, pathList, path, deltaDistance, angle) {
-    var position = getPositionAfterMove({
-      point: point,
-      pathList: pathList,
-      path: path,
-      deltaDistance: deltaDistance,
-      angle: angle
-    });
-    return applyAnnulusBandCenterToPosition(trackInfo, position);
-  }
-
-  /**
-   * 灏嗗潗鏍囧帇鍥炵幆绌垮鍦� path锛堢洿绾挎鎶曞奖銆佸渾寮ф钀藉埌鍗婂緞涓婏級銆�
-   * sprite 宸插仛 centerAnnulusBandPoint 鏃朵笉鑳界洿鎺ヤ綔涓� getPositionAfterMove 鐨勮捣鐐癸紝鍚﹀垯浼氭部銆岀偣鈫掓缁堢偣銆嶆枩绉绘紓绉汇��
+   * 灏嗗潗鏍囧帇鍥炵幆绌� pathList锛堜腑杞級褰撳墠娈典笂銆�
    * @param {number} x
    * @param {number} y
    * @param {{ type: string, startX?: number, startY?: number, x?: number, y?: number, radius?: number }|null|undefined} path
    * @returns {{ x: number, y: number }}
    */
-  function snapToAnnulusOuterPath(trackInfo, x, y, path) {
+  function snapToAnnulusPath(trackInfo, x, y, path) {
     if (!path || trackInfo.type !== 'annulus') {
       return { x: x, y: y };
     }
@@ -1025,16 +873,12 @@
   }
 
   /**
-   * 鐩戞帶杞ㄩ亾灞傦細宸蹭繚瀛樼殑 pathList 鎻忓鍦� + 鎸夊嚑浣曢噸绠楀唴鍦堝啀鎻忎竴鍦堛��
+   * 鐩戞帶杞ㄩ亾灞傦細鎸夊嚑浣曠畻澶栧湀銆佸唴鍦堝苟鎻忚竟锛坧athList 涓轰腑杞紝涓嶇敤浜庢鎻忚竟锛夈��
    * @param {PIXI.Graphics} smoothedGraphics
    * @param {{ pathList: object[], x: number, y: number, width: number, height: number, shape?: string, turningPoint?: object, annulusBandInset?: number }} item
    * @param {string} defaultShape
    */
   function strokeAnnulusDualOutline(smoothedGraphics, item, defaultShape) {
-    var outerPath = item && item.pathList;
-    if (!outerPath || !outerPath.length) {
-      return;
-    }
     var tmp = {
       x: item.x,
       y: item.y,
@@ -1044,24 +888,22 @@
       turningPoint: item.turningPoint,
       annulusBandInset: item.annulusBandInset
     };
-    var pair = buildOuterAndInnerPaths(tmp, item.shape || defaultShape);
-    traceSmoothedPath(smoothedGraphics, outerPath);
+    var pair = buildAnnulusPaths(tmp, item.shape || defaultShape);
+    traceSmoothedPath(smoothedGraphics, pair.outerPath);
     if (pair.innerPath && pair.innerPath.length) {
       traceSmoothedPath(smoothedGraphics, pair.innerPath);
     }
   }
 
   /**
-   * 缂栬緫鍣ㄧ幆绌垮~鍏咃細鍐欏洖 sprite.pathList锛堝鍦堬級锛岀粯鍒跺濉�+鍐呮礊銆�
-   * PIXI 涓甫娲炲~鍏呴�氬父涓嶄細缁欐礊杈圭晫鎻忚竟锛屾晠鍦� endFill 鍚庡啀娌垮唴鍦� trace 涓�閬嶏紝涓庣洃鎺ц建 strokeAnnulusDualOutline 涓�鑷达紝
-   * 浣� trackLayer / guideLayer / selectionLayer 鍧囪兘鐪嬪埌鍐呭湀杞粨銆�
+   * 缂栬緫鍣ㄧ幆绌匡細鍐欏洖 sprite.pathList锛堜腑杞級锛岀粯鍒跺濉�+鍐呮礊銆�
    * @param {PIXI.Graphics} smoothedGraphics
    * @param {object} sprite 鍏冪礌鎴栭瑙� rect
    * @param {string} defaultShape 濡� annulusShape
    */
   function startDrawSmoothedPath(smoothedGraphics, sprite, defaultShape) {
-    var pair = buildOuterAndInnerPaths(sprite, defaultShape);
-    sprite.pathList = pair.outerPath;
+    var pair = buildAnnulusPaths(sprite, defaultShape);
+    sprite.pathList = pair.centerPath;
     if (!pair.innerPath || !pair.innerPath.length) {
       drawSmoothedPath(smoothedGraphics, pair.outerPath);
       return;
@@ -1171,12 +1013,9 @@
     drawSmoothedPath: drawSmoothedPath,
     traceSmoothedPath: traceSmoothedPath,
     strokeAnnulusDualOutline: strokeAnnulusDualOutline,
-    centerAnnulusBandPoint: centerAnnulusBandPoint,
-    snapToAnnulusOuterPath: snapToAnnulusOuterPath,
+    snapToAnnulusPath: snapToAnnulusPath,
     startDrawSmoothedPath: startDrawSmoothedPath,
     getRotate: getRotate,
-    computeFinalPosition:computeFinalPosition,
-    applyAnnulusBandCenterToPosition:applyAnnulusBandCenterToPosition,
     drawCrnDeviceGraphics: drawCrnDeviceGraphics,
     drawRgvDeviceGraphics: drawRgvDeviceGraphics
   };

--
Gitblit v1.9.1