From c5aeffce02ad53eb88192e4d3ef26549d9961406 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期四, 15 一月 2026 13:45:14 +0800
Subject: [PATCH] #
---
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneBuilder.java | 71 ++++++++++++++++++++++++++++++++++-
1 files changed, 68 insertions(+), 3 deletions(-)
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneBuilder.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneBuilder.java
index 73a3fd6..7f0c2a4 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneBuilder.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneBuilder.java
@@ -164,11 +164,15 @@
}
for (String codeData : codeDataList) {
- if (this.adjacencyCodeMap.get(codeData).size() == 2 && !visited.contains(codeData)) {
+ if (this.adjacencyCodeMap.get(codeData).size() == 2
+ && !visited.contains(codeData)
+ && !this.isTurnCorner(codeData)) {
// 妫�鏌ユ槸鍚︿负鐜矾鐨勪竴閮ㄥ垎
LaneDto laneDto = new LaneDto();
this.dfsCalcForLoop(codeData, null, laneDto, visited);
- this.laneDtoList.add(laneDto);
+ if (!Cools.isEmpty(laneDto.getCodes())) {
+ this.laneDtoList.add(laneDto);
+ }
}
}
@@ -189,6 +193,11 @@
}
private void dfsCalcIncludingEnd(String start, String current, LaneDto laneDto, Set<String> visited) {
+ // 濡傛灉 current 鏈韩鏄嫄瑙掞紙degree=2 涓斾笉鍏辩嚎锛夛紝涓嶅簲璇ヨ繘鍏� lane
+ if (this.isTurnCorner(current)) {
+ return;
+ }
+
laneDto.getCodes().add(current);
visited.add(current);
@@ -205,6 +214,10 @@
if (!visited.contains(neighbor)) {
int degree = this.adjacencyCodeMap.get(neighbor).size();
if (degree == 2) {
+ // 涓嬩竴璺冲鏋滄槸鎷愯锛氱洿鎺ュ湪鎷愯鍓嶇粓姝紝涓斾笉鎶婃嫄瑙掔畻杩� lane
+ if (this.isTurnCorner(neighbor)) {
+ continue;
+ }
if (this.isSameDirection(current, neighbor, start)) {
this.dfsCalcIncludingEnd(current, neighbor, laneDto, visited);
}
@@ -218,6 +231,11 @@
}
private void dfsCalcForLoop(String current, String parent, LaneDto laneDto, Set<String> visited) {
+ // 鐜矾 lane锛氭嫄瑙掔偣涓嶇畻鍏� lane锛屽苟涓斿湪鎷愯鍓嶅仠姝�
+ if (this.isTurnCorner(current)) {
+ return;
+ }
+
laneDto.getCodes().add(current);
visited.add(current);
@@ -234,6 +252,10 @@
if (!visited.contains(neighbor)) {
int degree = this.adjacencyCodeMap.get(neighbor).size();
if (degree == 2) {
+ // 涓嬩竴璺冲鏋滄槸鎷愯锛氬湪鎷愯鍓嶇粓姝紝涓嶆妸鎷愯鍔犲叆 lane锛屼篃涓嶆爣 visited
+ if (this.isTurnCorner(neighbor)) {
+ continue;
+ }
if (this.isSameDirection(current, neighbor, parent)) {
this.dfsCalcForLoop(neighbor, current, laneDto, visited);
}
@@ -263,6 +285,49 @@
// 璁剧疆瑙掑害宸槇鍊间负3搴�
return angleDifference < Math.toRadians(3);
+ }
+
+ private boolean isTurnCorner(String codeData) {
+ if (Cools.isEmpty(codeData)) {
+ return false;
+ }
+ List<String> neighbors = this.adjacencyCodeMap.get(codeData);
+ if (neighbors == null || neighbors.size() != 2) {
+ return false;
+ }
+
+ String n1 = neighbors.get(0);
+ String n2 = neighbors.get(1);
+
+ Code c1 = codeService.getCacheByData(n1);
+ Code c = codeService.getCacheByData(codeData);
+ Code c2 = codeService.getCacheByData(n2);
+
+ // v1 = c - c1, v2 = c2 - c
+ double v1x = c.getX() - c1.getX();
+ double v1y = c.getY() - c1.getY();
+ double v2x = c2.getX() - c.getX();
+ double v2y = c2.getY() - c.getY();
+
+ // 涓や釜鍚戦噺浠讳竴涓洪浂鍚戦噺锛氫笉鎸夋嫄瑙掑鐞�
+ double len1 = Math.hypot(v1x, v1y);
+ double len2 = Math.hypot(v2x, v2y);
+ if (len1 == 0 || len2 == 0) {
+ return false;
+ }
+
+ // 澶硅 cos = dot / (|v1||v2|)
+ double dot = v1x * v2x + v1y * v2y;
+ double cos = dot / (len1 * len2);
+
+ // 鍏辩嚎鏈変袱绉嶏細
+ // 1) 180掳锛歝os 鈮� -1锛堢洿绾胯蛋寤婏級
+ // 2) 0掳锛歝os 鈮� +1锛堣矾绾垮紓甯稿洖澶达級锛屼竴鑸篃瑙嗕负鍏辩嚎
+ // 鍙鈥滀笉鎺ヨ繎 卤1鈥濓紝灏辫鏄庝笉鍦ㄤ竴鏉$嚎涓� -> 鎷愯
+ double eps = Math.cos(Math.toRadians(3)); // 3搴﹀宸�
+ boolean nearOpposite = cos <= -eps; // 鎺ヨ繎 -1
+ boolean nearSame = cos >= eps; // 鎺ヨ繎 +1
+ return !(nearOpposite || nearSame);
}
/**
@@ -384,4 +449,4 @@
}
}
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.1