From 913a3b7409e08fd239a65ff7afabefe95b51865a Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 26 十二月 2025 19:44:23 +0800
Subject: [PATCH] 优化了异形有障碍物算法

---
 src/lujing/MowingPathGenerationPage.java |   50 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/src/lujing/MowingPathGenerationPage.java b/src/lujing/MowingPathGenerationPage.java
index 77c496c..78735ca 100644
--- a/src/lujing/MowingPathGenerationPage.java
+++ b/src/lujing/MowingPathGenerationPage.java
@@ -140,8 +140,21 @@
         contentPanel.add(createTextAreaSection(obstacleTitle, obstacleArea));
         
         // 鍓茶崏瀹藉害
-        widthField = createInfoTextField(widthValue != null ? widthValue : "", true);
-        contentPanel.add(createTextFieldSection("鍓茶崏瀹藉害 (cm)", widthField));
+        String displayWidth = "";
+        if (widthValue != null && !widthValue.trim().isEmpty() && !"-1".equals(widthValue.trim())) {
+            try {
+                double val = Double.parseDouble(widthValue.trim());
+                // 绠�鍗曠殑鍚彂寮忚浆鎹細濡傛灉鍊煎ぇ浜�5锛屽亣璁炬槸鍘樼背锛岃浆鎹负绫�
+                if (val > 5) {
+                    val = val / 100.0;
+                }
+                displayWidth = String.format(Locale.US, "%.2f", val);
+            } catch (NumberFormatException e) {
+                displayWidth = widthValue;
+            }
+        }
+        widthField = createInfoTextField(displayWidth, true);
+        contentPanel.add(createTextFieldSection("鍓茶崏瀹藉害 (m)", widthField));
         
         // 鍓茶崏瀹夊叏璺濈锛堝彧璇绘樉绀猴級
         // 浼樺厛浠嶥ikuai瀵硅薄鑾峰彇锛屽鏋淒ikuai涓病鏈夛紝鍐嶄粠Device鑾峰彇
@@ -223,9 +236,9 @@
         String sanitizedWidth = sanitizeWidthString(widthField.getText());
         if (sanitizedWidth != null) {
             try {
-                double widthCm = Double.parseDouble(sanitizedWidth);
-                widthField.setText(formatWidthForStorage(widthCm));
-                sanitizedWidth = formatWidthForStorage(widthCm);
+                double widthMeters = Double.parseDouble(sanitizedWidth);
+                widthField.setText(formatWidthForStorage(widthMeters));
+                sanitizedWidth = formatWidthForStorage(widthMeters);
             } catch (NumberFormatException ex) {
                 widthField.setText(sanitizedWidth);
             }
@@ -407,25 +420,25 @@
         String rawWidthInput = widthField.getText() != null ? widthField.getText().trim() : "";
         String widthSanitized = sanitizeWidthString(widthField.getText());
         if (widthSanitized == null) {
-                String message = rawWidthInput.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(cm)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
+                String message = rawWidthInput.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(m)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
             JOptionPane.showMessageDialog(this, message, "鎻愮ず", JOptionPane.WARNING_MESSAGE);
             return;
         }
         
-        double widthCm;
+        double widthMeters;
         try {
-            widthCm = Double.parseDouble(widthSanitized);
+            widthMeters = Double.parseDouble(widthSanitized);
         } catch (NumberFormatException ex) {
             JOptionPane.showMessageDialog(this, "鍓茶崏瀹藉害鏍煎紡涓嶆纭�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
             return;
         }
         
-        if (widthCm <= 0) {
+        if (widthMeters <= 0) {
             JOptionPane.showMessageDialog(this, "鍓茶崏瀹藉害蹇呴』澶т簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
             return;
         }
         
-        String widthNormalized = formatWidthForStorage(widthCm);
+        String widthNormalized = formatWidthForStorage(widthMeters);
         widthField.setText(widthNormalized);
         
         String pathNormalized = normalizeCoordinateInput(pathArea.getText());
@@ -518,15 +531,15 @@
         String widthStr = sanitizeWidthString(widthCmInput);
         if (widthStr == null) {
             if (showMessages) {
-                String message = rawWidth.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(cm)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
+                String message = rawWidth.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(m)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
                 JOptionPane.showMessageDialog(parentComponent, message, "鎻愮ず", JOptionPane.WARNING_MESSAGE);
             }
             return null;
         }
         
-        double widthCm;
+        double widthVal;
         try {
-            widthCm = Double.parseDouble(widthStr);
+            widthVal = Double.parseDouble(widthStr);
         } catch (NumberFormatException ex) {
             if (showMessages) {
                 JOptionPane.showMessageDialog(parentComponent, "鍓茶崏瀹藉害鏍煎紡涓嶆纭�", 
@@ -535,7 +548,7 @@
             return null;
         }
         
-        if (widthCm <= 0) {
+        if (widthVal <= 0) {
             if (showMessages) {
                 JOptionPane.showMessageDialog(parentComponent, "鍓茶崏瀹藉害蹇呴』澶т簬0", 
                     "鎻愮ず", JOptionPane.WARNING_MESSAGE);
@@ -543,7 +556,7 @@
             return null;
         }
         
-        double widthMeters = widthCm / 100.0d;
+        double widthMeters = widthVal;
         String plannerWidth = BigDecimal.valueOf(widthMeters)
             .setScale(3, RoundingMode.HALF_UP)
             .stripTrailingZeros()
@@ -1081,11 +1094,8 @@
         return cleaned.isEmpty() ? null : cleaned;
     }
     
-    private String formatWidthForStorage(double widthCm) {
-        return BigDecimal.valueOf(widthCm)
-            .setScale(2, RoundingMode.HALF_UP)
-            .stripTrailingZeros()
-            .toPlainString();
+    private String formatWidthForStorage(double widthVal) {
+        return String.format(Locale.US, "%.2f", widthVal);
     }
     
     private String formatMowingPatternForDialog(String patternValue) {

--
Gitblit v1.10.0