From 6fc533a424b5821d9e775d1ca89e00b8d16e57d4 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期一, 23 三月 2026 13:20:08 +0800
Subject: [PATCH] #
---
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneBuilder.java | 99 ++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 89 insertions(+), 10 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 76cd139..3549416 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
@@ -17,6 +17,7 @@
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
+import com.zy.acs.common.utils.News;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -105,7 +106,7 @@
stopWatch.start();
this.initLaneData();
stopWatch.stop();
- log.info("the rcs system calculated lane data which has spend {} millisecond......", stopWatch.getTime());
+ News.info("the rcs system calculated lane data which has spend {} millisecond......", stopWatch.getTime());
if (!Cools.isEmpty(this.laneDtoList)) {
laneService.batchSaveByLaneDtoList(null, this.laneDtoList);
@@ -118,7 +119,7 @@
}
private void initLaneData() {
- log.info("the rcs system is starting to initialize lane data...");
+ News.info("the rcs system is starting to initialize lane data...");
List<Code> codeList = codeService.list(new LambdaQueryWrapper<Code>().eq(Code::getStatus, StatusType.ENABLE.val));
@@ -134,7 +135,7 @@
this.generateLaneHash();
- log.info("the lane data initialization has been completed in rcs system.");
+ News.info("the lane data initialization has been completed in rcs system.");
}
private void fillAdjacencyCodeMap(List<Code> codeList) {
@@ -164,18 +165,40 @@
}
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);
+ }
}
}
-
+ // === 琛ワ細鏈浠讳綍 DFS 瑕嗙洊鐨勭鐐癸紙degree <= 1锛夛紝浣滀负鍗曠偣 lane ===
+ for (String codeData : codeDataList) {
+ if (visited.contains(codeData)) {
+ continue;
+ }
+ List<String> neighbors = adjacencyCodeMap.get(codeData);
+ int degree = neighbors == null ? 0 : neighbors.size();
+ if (degree <= 1) {
+ LaneDto laneDto = new LaneDto();
+ laneDto.getCodes().add(codeData);
+ laneDtoList.add(laneDto);
+ visited.add(codeData);
+ }
+ }
}
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);
@@ -192,6 +215,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);
}
@@ -205,6 +232,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);
@@ -221,8 +253,12 @@
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(current, neighbor, laneDto, visited);
+ this.dfsCalcForLoop(neighbor, current, laneDto, visited);
}
} else {
laneDto.getCodes().add(neighbor);
@@ -250,6 +286,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);
}
/**
@@ -343,7 +422,7 @@
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
- log.error("generateDigest", e);
+ News.error("generateDigest", e);
throw new RuntimeException(e);
}
String combined = list.stream().sorted().collect(Collectors.joining(","));
@@ -357,7 +436,7 @@
}
public void generateLaneCodeIdx(Integer lev) {
- log.info("There is initializing Lane CodeIdxMap......");
+ News.info("There is initializing Lane CodeIdxMap......");
if (Cools.isEmpty(this.laneDtoList)) {
return;
}
@@ -371,4 +450,4 @@
}
}
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.1