From 1175f5fbe8fd832943880bfc37c0e2a451a0688a Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期四, 25 十二月 2025 19:34:38 +0800
Subject: [PATCH] 删除了几个类优化了路径生成的逻辑

---
 src/gecaoji/lujingdraw.java |  197 ++++++++++++++-----------------------------------
 1 files changed, 56 insertions(+), 141 deletions(-)

diff --git a/src/gecaoji/lujingdraw.java b/src/gecaoji/lujingdraw.java
index 95ed85a..5d54008 100644
--- a/src/gecaoji/lujingdraw.java
+++ b/src/gecaoji/lujingdraw.java
@@ -1,5 +1,4 @@
 package gecaoji; // 鍖呭0鏄�
-
 import java.awt.BasicStroke; // 寮曞叆鍩虹鎻忚竟绫�
 import java.awt.Color; // 寮曞叆棰滆壊绫�
 import java.awt.Graphics2D; // 寮曞叆2D鍥惧舰涓婁笅鏂�
@@ -8,7 +7,6 @@
 import java.awt.geom.Point2D; // 寮曞叆浜岀淮鐐圭被
 import java.util.ArrayList; // 寮曞叆鍔ㄦ�佹暟缁�
 import java.util.List; // 寮曞叆鍒楄〃鎺ュ彛
-import lujing.Lunjingguihua; // 寮曞叆璺緞瑙勫垝绫�
 import org.locationtech.jts.geom.Coordinate; // 寮曞叆鍧愭爣绫�
 import org.locationtech.jts.geom.GeometryFactory; // 寮曞叆鍑犱綍宸ュ巶绫�
 import org.locationtech.jts.geom.Polygon; // 寮曞叆澶氳竟褰㈢被
@@ -24,7 +22,7 @@
     // 钃濊壊 - 鐢ㄤ簬闈炰綔涓氱Щ鍔ㄨ矾寰�
     private static final Color TRAVEL_PATH_COLOR = new Color(0, 0, 255);
     // 铏氱嚎鏍峰紡 - 鐢ㄤ簬闈炰綔涓氱Щ鍔ㄨ矾寰�
-    private static final float[] DASH_PATTERN = {10.0f, 5.0f};
+    private static final float[] DASH_PATTERN = {5.0f, 5.0f};
     private static final Color START_POINT_COLOR = new Color(0, 0, 0, 220); // 璧风偣绠ご棰滆壊
     private static final Color END_POINT_COLOR = new Color(0, 0, 0, 220); // 缁堢偣绠ご棰滆壊
 
@@ -107,62 +105,29 @@
             drawInnerBoundary(g2d, boundaryCoords, safetyDistance, scale);
         }
         
-        // 2. 灏濊瘯閲嶆柊鐢熸垚璺緞娈典互鍖哄垎浣滀笟璺緞鍜岀Щ鍔ㄨ矾寰�
-        List<Lunjingguihua.PathSegment> segments = null;
-        if (boundaryCoords != null && mowingWidth != null) {
-            try {
-                // 瑙f瀽鍓茶崏妯″紡
-                String mode = "parallel"; // 榛樿骞宠妯″紡
-                if (mowingPattern != null && !mowingPattern.trim().isEmpty()) {
-                    String pattern = mowingPattern.trim().toLowerCase();
-                    if ("1".equals(pattern) || "spiral".equals(pattern) || "铻烘棆寮�".equals(pattern) || "铻烘棆".equals(pattern)) {
-                        mode = "spiral";
-                    } else if ("parallel".equals(pattern) || "骞宠绾�".equals(pattern) || "骞宠".equals(pattern)) {
-                        mode = "parallel";
-                    }
-                }
-                segments = Lunjingguihua.generatePathSegments(
-                    boundaryCoords, 
-                    obstaclesCoords != null ? obstaclesCoords : "", 
-                    mowingWidth, 
-                    safetyDistance, 
-                    mode
-                );
-            } catch (Exception e) {
-                // 濡傛灉閲嶆柊鐢熸垚澶辫触锛屼娇鐢ㄧ畝鍗曠粯鍒舵柟寮�
-                segments = null;
-            }
-        }
+        // 2. 鐩存帴缁樺埗璺緞锛堜笉鍐嶉噸鏂扮敓鎴愶級
+        Path2D polyline = new Path2D.Double(); // 鍒涘缓鎶樼嚎
+        boolean move = true; // 棣栨鏍囪
+        for (Point2D.Double point : path) { // 閬嶅巻鐐归泦
+            if (move) { // 绗竴娈�
+                polyline.moveTo(point.x, point.y); // 绉诲姩鍒伴鐐�
+                move = false; // 鏇存柊鏍囪
+            } else { // 鍚庣画娈�
+                polyline.lineTo(point.x, point.y); // 杩炵嚎鍒颁笅涓�鐐�
+            } // if缁撴潫
+        } // for缁撴潫
         
-        // 3. 鏍规嵁鏄惁鏈夋淇℃伅閫夋嫨涓嶅悓鐨勭粯鍒舵柟寮�
-        if (segments != null && !segments.isEmpty()) {
-            // 鏈夋淇℃伅锛氬垎鍒粯鍒朵綔涓氳矾寰勫拰绉诲姩璺緞
-            drawPathSegments(g2d, segments, scale, arrowScale);
-        } else {
-            // 鏃犳淇℃伅锛氫娇鐢ㄧ畝鍗曠粯鍒舵柟寮忥紙鎵�鏈夎矾寰勪娇鐢ㄤ綔涓氳矾寰勯鑹诧級
-            Path2D polyline = new Path2D.Double(); // 鍒涘缓鎶樼嚎
-            boolean move = true; // 棣栨鏍囪
-            for (Point2D.Double point : path) { // 閬嶅巻鐐归泦
-                if (move) { // 绗竴娈�
-                    polyline.moveTo(point.x, point.y); // 绉诲姩鍒伴鐐�
-                    move = false; // 鏇存柊鏍囪
-                } else { // 鍚庣画娈�
-                    polyline.lineTo(point.x, point.y); // 杩炵嚎鍒颁笅涓�鐐�
-                } // if缁撴潫
-            } // for缁撴潫
-            
-            g2d.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // 璁剧疆鍦嗗ご鍦嗚鎻忚竟
-            g2d.setColor(MOWING_PATH_COLOR); // 璁剧疆浣滀笟璺緞棰滆壊锛堟彁棣欑孩70%閫忔槑搴︼級
-            g2d.draw(polyline); // 缁樺埗鎶樼嚎
-            
-            Point2D.Double start = path.get(0); // 璧风偣
-            Point2D.Double second = path.get(1); // 绗簩涓偣
-            Point2D.Double end = path.get(path.size() - 1); // 缁堢偣
-            Point2D.Double prev = path.get(path.size() - 2); // 鍊掓暟绗簩涓偣
+        g2d.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // 璁剧疆鍦嗗ご鍦嗚鎻忚竟
+        g2d.setColor(MOWING_PATH_COLOR); // 璁剧疆浣滀笟璺緞棰滆壊锛堟彁棣欑孩70%閫忔槑搴︼級
+        g2d.draw(polyline); // 缁樺埗鎶樼嚎
+        
+        Point2D.Double start = path.get(0); // 璧风偣
+        Point2D.Double second = path.get(1); // 绗簩涓偣
+        Point2D.Double end = path.get(path.size() - 1); // 缁堢偣
+        Point2D.Double prev = path.get(path.size() - 2); // 鍊掓暟绗簩涓偣
 
-            drawArrowMarker(g2d, start, second, START_POINT_COLOR, scale, arrowScale); // 缁樺埗璧风偣绠ご
-            drawArrowMarker(g2d, prev, end, END_POINT_COLOR, scale, arrowScale); // 缁樺埗缁堢偣绠ご
-        }
+        drawArrowMarker(g2d, start, second, START_POINT_COLOR, scale, arrowScale); // 缁樺埗璧风偣绠ご
+        drawArrowMarker(g2d, prev, end, END_POINT_COLOR, scale, arrowScale); // 缁樺埗缁堢偣绠ご
 
         g2d.setStroke(previous); // 鎭㈠鍘熸弿杈�
     } // 鏂规硶缁撴潫
@@ -172,7 +137,7 @@
      */ // 鏂囨。娉ㄩ噴缁撴潫
     private static void drawInnerBoundary(Graphics2D g2d, String boundaryCoords, String safetyDistanceStr, double scale) {
         try {
-            List<Coordinate> boundary = Lunjingguihua.parseCoordinates(boundaryCoords);
+            List<Coordinate> boundary = parseCoordinates(boundaryCoords);
             if (boundary.size() < 4) {
                 return; // 杈圭晫鐐逛笉瓒�
             }
@@ -258,89 +223,7 @@
         }
     } // 鏂规硶缁撴潫
     
-    /** // 鏂囨。娉ㄩ噴寮�濮�
-     * 缁樺埗璺緞娈碉紙鍖哄垎浣滀笟璺緞鍜岀Щ鍔ㄨ矾寰勶級
-     */ // 鏂囨。娉ㄩ噴缁撴潫
-    private static void drawPathSegments(Graphics2D g2d, List<Lunjingguihua.PathSegment> segments, double scale, double arrowScale) {
-        if (segments == null || segments.isEmpty()) {
-            return;
-        }
-        
-        float strokeWidth = (float) (2.5 / Math.max(0.5, scale));
-        Stroke previous = g2d.getStroke();
-        
-        // 鍒嗗埆缁樺埗浣滀笟璺緞鍜岀Щ鍔ㄨ矾寰�
-        Path2D.Double mowingPath = new Path2D.Double();
-        Path2D.Double travelPath = new Path2D.Double();
-        boolean mowingStarted = false;
-        boolean travelStarted = false;
-        
-        Coordinate lastMowingEnd = null;
-        Coordinate lastTravelEnd = null;
-        
-        for (Lunjingguihua.PathSegment seg : segments) {
-            if (seg == null || seg.start == null || seg.end == null) {
-                continue;
-            }
-            
-            if (seg.isMowing) {
-                // 浣滀笟璺緞 - 鎻愰绾�70%閫忔槑搴�
-                if (!mowingStarted || lastMowingEnd == null || !equals2D(lastMowingEnd, seg.start)) {
-                    mowingPath.moveTo(seg.start.x, seg.start.y);
-                    mowingStarted = true;
-                }
-                mowingPath.lineTo(seg.end.x, seg.end.y);
-                lastMowingEnd = seg.end;
-            } else {
-                // 绉诲姩璺緞 - 钃濊壊铏氱嚎
-                if (!travelStarted || lastTravelEnd == null || !equals2D(lastTravelEnd, seg.start)) {
-                    travelPath.moveTo(seg.start.x, seg.start.y);
-                    travelStarted = true;
-                }
-                travelPath.lineTo(seg.end.x, seg.end.y);
-                lastTravelEnd = seg.end;
-            }
-        }
-        
-        // 缁樺埗浣滀笟璺緞
-        if (mowingStarted) {
-            g2d.setColor(MOWING_PATH_COLOR); // 鎻愰绾�70%閫忔槑搴�
-            g2d.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
-            g2d.draw(mowingPath);
-        }
-        
-        // 缁樺埗绉诲姩璺緞锛堣櫄绾匡級
-        if (travelStarted) {
-            g2d.setColor(TRAVEL_PATH_COLOR); // 钃濊壊
-            g2d.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, DASH_PATTERN, 0));
-            g2d.draw(travelPath);
-        }
-        
-        // 缁樺埗璧风偣鍜岀粓鐐圭澶�
-        if (!segments.isEmpty()) {
-            Lunjingguihua.PathSegment firstSeg = segments.get(0);
-            if (firstSeg != null && firstSeg.start != null && segments.size() > 1) {
-                Lunjingguihua.PathSegment secondSeg = segments.get(1);
-                if (secondSeg != null && secondSeg.start != null) {
-                    Point2D.Double start = new Point2D.Double(firstSeg.start.x, firstSeg.start.y);
-                    Point2D.Double second = new Point2D.Double(secondSeg.start.x, secondSeg.start.y);
-                    drawArrowMarker(g2d, start, second, START_POINT_COLOR, scale, arrowScale);
-                }
-            }
-            
-            Lunjingguihua.PathSegment lastSeg = segments.get(segments.size() - 1);
-            if (lastSeg != null && lastSeg.end != null && segments.size() > 1) {
-                Lunjingguihua.PathSegment prevSeg = segments.get(segments.size() - 2);
-                if (prevSeg != null && prevSeg.end != null) {
-                    Point2D.Double prev = new Point2D.Double(prevSeg.end.x, prevSeg.end.y);
-                    Point2D.Double end = new Point2D.Double(lastSeg.end.x, lastSeg.end.y);
-                    drawArrowMarker(g2d, prev, end, END_POINT_COLOR, scale, arrowScale);
-                }
-            }
-        }
-        
-        g2d.setStroke(previous);
-    } // 鏂规硶缁撴潫
+
     
     /** // 鏂囨。娉ㄩ噴寮�濮�
      * 姣旇緝涓や釜鍧愭爣鏄惁鐩稿悓锛堝宸級
@@ -392,4 +275,36 @@
         g2d.setColor(color); // 璁剧疆棰滆壊
         g2d.fill(arrow); // 濉厖绠ご
     } // 鏂规硶缁撴潫
+
+    /**
+     * 瑙f瀽鍧愭爣瀛楃涓�
+     */
+    private static List<Coordinate> parseCoordinates(String s) {
+        List<Coordinate> list = new ArrayList<>();
+        if (s == null || s.trim().isEmpty()) return list;
+        // 澧炲己姝e垯锛氬鐞嗗彲鑳藉瓨鍦ㄧ殑澶氱鍒嗛殧绗�
+        String[] pts = s.split("[;\\s]+");
+        for (String p : pts) {
+            String trimmed = p.trim().replace("(", "").replace(")", "");
+            if (trimmed.isEmpty()) continue;
+            String[] xy = trimmed.split("[,锛孿\s]+");
+            if (xy.length >= 2) {
+                try {
+                    double x = Double.parseDouble(xy[0].trim());
+                    double y = Double.parseDouble(xy[1].trim());
+                    // 杩囨护鏃犳晥鍧愭爣
+                    if (!Double.isNaN(x) && !Double.isNaN(y) && !Double.isInfinite(x) && !Double.isInfinite(y)) {
+                        list.add(new Coordinate(x, y));
+                    }
+                } catch (NumberFormatException ex) {
+                    // 蹇界暐瑙f瀽閿欒鐨勭偣
+                }
+            }
+        }
+        // 纭繚澶氳竟褰㈤棴鍚�
+        if (list.size() > 2 && !list.get(0).equals2D(list.get(list.size() - 1))) {
+            list.add(new Coordinate(list.get(0)));
+        }
+        return list;
+    }
 } // 绫荤粨鏉�

--
Gitblit v1.10.0