From 64819e1e2254316a090fd056b80f139ca4dbcf94 Mon Sep 17 00:00:00 2001
From: jinglun-cloud <jinglun2019@foxmail.com>
Date: 星期三, 06 五月 2026 14:55:29 +0800
Subject: [PATCH] refactor(地图几何计算): 重构线段投影距离计算逻辑
---
src/main/webapp/components/MapCanvas.js | 47 +++++++++--------------------------------------
1 files changed, 9 insertions(+), 38 deletions(-)
diff --git a/src/main/webapp/components/MapCanvas.js b/src/main/webapp/components/MapCanvas.js
index 09a1112..636f184 100644
--- a/src/main/webapp/components/MapCanvas.js
+++ b/src/main/webapp/components/MapCanvas.js
@@ -1329,37 +1329,11 @@
calcSignedSegmentDelta(fromBarcode, toBarcode, trackInfo, totalSegmentCount) {
const from = Number(fromBarcode);
const to = Number(toBarcode);
- if (!isFinite(from) || !isFinite(to)) {
- return 0;
- }
+ if (!isFinite(from) || !isFinite(to)) return 0;
const raw = to - from;
- if (trackInfo.type !== 'annulus') {
- return raw;
- }
- const span = totalSegmentCount;
- if (!(span > 0)) {
- return raw;
- }
- const mod = (n, m) => ((n % m) + m) % m;
- return mod(raw, span);
- },
- lineSignedRemainAlong(path0, sx, sy, mx, my) {
- if (!path0 || path0.type !== 'line') {
- return null;
- }
- const x0 = path0.startX;
- const y0 = path0.startY;
- const vx = path0.x - x0;
- const vy = path0.y - y0;
- const segLen = Math.sqrt(vx * vx + vy * vy);
- if (!(segLen > EPSILON)) {
- return null;
- }
- const clampT = (px, py) => {
- const t = ((px - x0) * vx + (py - y0) * vy) / segLen;
- return Math.max(0, Math.min(segLen, t));
- };
- return clampT(mx, my) - clampT(sx, sy);
+ if (trackInfo.type !== 'annulus' || totalSegmentCount <= 0) return raw;
+ // 闈炶礋鍙栨ā
+ return ((raw % totalSegmentCount) + totalSegmentCount) % totalSegmentCount;
},
finishDeviceMotion(sprite) {
if (!sprite || !sprite.mappingInfo) {
@@ -1521,7 +1495,7 @@
pathList.length === 1 && pathList[0].type === 'line' && sprite.trackInfo.type !== 'annulus';
let smoothDistance;
if (singleLineTrack) {
- const remainAlong = this.lineSignedRemainAlong(
+ const remainAlong = G.lineSignedRemainAlong(
path,
sprite.x,
sprite.y,
@@ -1531,14 +1505,11 @@
if (remainAlong != null) {
let stepMag = Math.min(stepCap, Math.abs(remainAlong), restDistance);
if (stepMag < EPSILON && restDistance > EPSILON) {
- const x0 = path.startX;
- const y0 = path.startY;
- const vx = path.x - x0;
- const vy = path.y - y0;
- const sl = Math.sqrt(vx * vx + vy * vy);
+ const lineStart = { x: path.startX, y: path.startY };
+ const lineEnd = { x: path.x, y: path.y };
+ const sl = G.calcDistance(lineStart, lineEnd);
if (sl > EPSILON) {
- const ux = vx / sl;
- const uy = vy / sl;
+ const { x: ux, y: uy } = G.normalizeVector(lineStart, lineEnd);
const wdx = sprite.mappingInfo.x - sprite.x;
const wdy = sprite.mappingInfo.y - sprite.y;
const hint = wdx * ux + wdy * uy;
--
Gitblit v1.9.1