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 |  188 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 176 insertions(+), 12 deletions(-)

diff --git a/src/gecaoji/lujingdraw.java b/src/gecaoji/lujingdraw.java
index 15a4c46..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,12 +7,22 @@
 import java.awt.geom.Point2D; // 寮曞叆浜岀淮鐐圭被
 import java.util.ArrayList; // 寮曞叆鍔ㄦ�佹暟缁�
 import java.util.List; // 寮曞叆鍒楄〃鎺ュ彛
+import org.locationtech.jts.geom.Coordinate; // 寮曞叆鍧愭爣绫�
+import org.locationtech.jts.geom.GeometryFactory; // 寮曞叆鍑犱綍宸ュ巶绫�
+import org.locationtech.jts.geom.Polygon; // 寮曞叆澶氳竟褰㈢被
 
 /** // 鏂囨。娉ㄩ噴寮�澶�
  * Helper class to parse and render planned mowing paths. // 杈呭姪绫昏鏄�
  */ // 鏂囨。娉ㄩ噴缁撳熬
 public final class lujingdraw { // 绫诲畾涔夛紝闃叉缁ф壙
-    private static final Color PATH_COLOR = new Color(255, 0, 0, 220); // 璺緞棰滆壊锛堢孩鑹插崐閫忔槑锛�
+    // 椹皵鏂豢鑹� (RGB: 102, 205, 170) - 鐢ㄤ簬鍐呯缉杈圭晫锛堝洿杈癸級
+    private static final Color INNER_BOUNDARY_COLOR = new Color(102, 205, 170);
+    // 鎻愰绾㈤�忔槑搴�70% (RGB: 210, 4, 45, alpha: 178) - 鐢ㄤ簬鍓茶崏浣滀笟璺緞
+    private static final Color MOWING_PATH_COLOR = new Color(210, 4, 45, 178);
+    // 钃濊壊 - 鐢ㄤ簬闈炰綔涓氱Щ鍔ㄨ矾寰�
+    private static final Color TRAVEL_PATH_COLOR = new Color(0, 0, 255);
+    // 铏氱嚎鏍峰紡 - 鐢ㄤ簬闈炰綔涓氱Щ鍔ㄨ矾寰�
+    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); // 缁堢偣绠ご棰滆壊
 
@@ -70,11 +79,33 @@
     /** // 鏂囨。娉ㄩ噴寮�濮�
      * Draw the planned mowing path. // 缁樺埗璺緞
      */ // 鏂囨。娉ㄩ噴缁撴潫
-    public static void drawPlannedPath(Graphics2D g2d, List<Point2D.Double> path, double scale) { // 缁樺埗涓绘柟娉�
+    public static void drawPlannedPath(Graphics2D g2d, List<Point2D.Double> path, double scale, double arrowScale) { // 缁樺埗涓绘柟娉�
+        drawPlannedPath(g2d, path, scale, arrowScale, null, null, null, null, null); // 璋冪敤閲嶈浇鏂规硶
+    } // 鏂规硶缁撴潫
+    
+    /** // 鏂囨。娉ㄩ噴寮�濮�
+     * Draw the planned mowing path with segment information. // 缁樺埗璺緞锛堝甫娈典俊鎭級
+     * @param boundaryCoords 鍦板潡杈圭晫鍧愭爣瀛楃涓诧紝鐢ㄤ簬缁樺埗鍐呯缉杈圭晫
+     * @param mowingWidth 鍓茶崏瀹藉害锛堢背锛夛紝瀛楃涓叉牸寮�
+     * @param safetyDistance 瀹夊叏璺濈锛堢背锛夛紝瀛楃涓叉牸寮�
+     * @param obstaclesCoords 闅滅鐗╁潗鏍囧瓧绗︿覆
+     * @param mowingPattern 鍓茶崏妯″紡锛�"parallel"鎴�"spiral"锛�
+     */ // 鏂囨。娉ㄩ噴缁撴潫
+    public static void drawPlannedPath(Graphics2D g2d, List<Point2D.Double> path, double scale, double arrowScale,
+                                      String boundaryCoords, String mowingWidth, String safetyDistance, String obstaclesCoords, String mowingPattern) { // 缁樺埗涓绘柟娉曪紙閲嶈浇锛�
         if (path == null || path.size() < 2) { // 鍒ゅ畾鐐规暟
             return; // 鏁版嵁涓嶈冻鐩存帴杩斿洖
         } // if缁撴潫
 
+        Stroke previous = g2d.getStroke(); // 淇濆瓨鍘熸弿杈�
+        float strokeWidth = (float) (2.5 / Math.max(0.5, scale)); // 鏍规嵁缂╂斁璁$畻绾垮
+        
+        // 1. 缁樺埗鍐呯缉杈圭晫锛堝洿杈癸級- 椹皵鏂豢鑹�
+        if (boundaryCoords != null && !boundaryCoords.trim().isEmpty() && !"-1".equals(boundaryCoords.trim())) {
+            drawInnerBoundary(g2d, boundaryCoords, safetyDistance, scale);
+        }
+        
+        // 2. 鐩存帴缁樺埗璺緞锛堜笉鍐嶉噸鏂扮敓鎴愶級
         Path2D polyline = new Path2D.Double(); // 鍒涘缓鎶樼嚎
         boolean move = true; // 棣栨鏍囪
         for (Point2D.Double point : path) { // 閬嶅巻鐐归泦
@@ -85,25 +116,125 @@
                 polyline.lineTo(point.x, point.y); // 杩炵嚎鍒颁笅涓�鐐�
             } // if缁撴潫
         } // for缁撴潫
-
-        Stroke previous = g2d.getStroke(); // 淇濆瓨鍘熸弿杈�
-        float strokeWidth = (float) (2.5 / Math.max(0.5, scale)); // 鏍规嵁缂╂斁璁$畻绾垮
+        
         g2d.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // 璁剧疆鍦嗗ご鍦嗚鎻忚竟
-        g2d.setColor(PATH_COLOR); // 璁剧疆绾胯矾棰滆壊
+        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); // 缁樺埗璧风偣绠ご
-        drawArrowMarker(g2d, prev, end, END_POINT_COLOR, scale); // 缁樺埗缁堢偣绠ご
+        drawArrowMarker(g2d, start, second, START_POINT_COLOR, scale, arrowScale); // 缁樺埗璧风偣绠ご
+        drawArrowMarker(g2d, prev, end, END_POINT_COLOR, scale, arrowScale); // 缁樺埗缁堢偣绠ご
 
         g2d.setStroke(previous); // 鎭㈠鍘熸弿杈�
     } // 鏂规硶缁撴潫
+    
+    /** // 鏂囨。娉ㄩ噴寮�濮�
+     * 缁樺埗鍐呯缉杈圭晫锛堝洿杈癸級- 椹皵鏂豢鑹�
+     */ // 鏂囨。娉ㄩ噴缁撴潫
+    private static void drawInnerBoundary(Graphics2D g2d, String boundaryCoords, String safetyDistanceStr, double scale) {
+        try {
+            List<Coordinate> boundary = parseCoordinates(boundaryCoords);
+            if (boundary.size() < 4) {
+                return; // 杈圭晫鐐逛笉瓒�
+            }
+            
+            // 瑙f瀽瀹夊叏璺濈
+            double safetyDistance = 0.2; // 榛樿0.2绫�
+            if (safetyDistanceStr != null && !safetyDistanceStr.trim().isEmpty()) {
+                try {
+                    safetyDistance = Double.parseDouble(safetyDistanceStr.trim());
+                } catch (NumberFormatException e) {
+                    // 浣跨敤榛樿鍊�
+                }
+            }
+            
+            // 鍒涘缓澶氳竟褰㈠苟鍐呯缉
+            GeometryFactory gf = new GeometryFactory();
+            Polygon poly = gf.createPolygon(gf.createLinearRing(boundary.toArray(new Coordinate[0])));
+            if (!poly.isValid()) {
+                poly = (Polygon) poly.buffer(0);
+            }
+            
+            // 鍐呯缉鐢熸垚瀹夊叏杈圭晫
+            org.locationtech.jts.geom.Geometry innerBoundary = poly.buffer(-safetyDistance);
+            if (innerBoundary == null || innerBoundary.isEmpty()) {
+                return;
+            }
+            
+            // 缁樺埗鍐呯缉杈圭晫
+            g2d.setColor(INNER_BOUNDARY_COLOR); // 椹皵鏂豢鑹�
+            float strokeWidth = (float) (3.0 / Math.max(0.5, scale));
+            g2d.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+            
+            // 灏咼TS鍑犱綍浣撹浆鎹负Path2D骞剁粯鍒�
+            Path2D.Double innerPath = geometryToPath2D(innerBoundary);
+            if (innerPath != null) {
+                g2d.draw(innerPath);
+            }
+        } catch (Exception e) {
+            // 缁樺埗澶辫触鏃跺拷鐣ワ紝涓嶅奖鍝嶅叾浠栬矾寰勭粯鍒�
+        }
+    } // 鏂规硶缁撴潫
+    
+    /** // 鏂囨。娉ㄩ噴寮�濮�
+     * 灏咼TS鍑犱綍浣撹浆鎹负Path2D
+     */ // 鏂囨。娉ㄩ噴缁撴潫
+    private static Path2D.Double geometryToPath2D(org.locationtech.jts.geom.Geometry geom) {
+        if (geom == null) {
+            return null;
+        }
+        Path2D.Double path = new Path2D.Double();
+        if (geom instanceof Polygon) {
+            Polygon poly = (Polygon) geom;
+            addRingToPath(path, poly.getExteriorRing().getCoordinates(), true);
+            for (int i = 0; i < poly.getNumInteriorRing(); i++) {
+                addRingToPath(path, poly.getInteriorRingN(i).getCoordinates(), true);
+            }
+        } else if (geom instanceof org.locationtech.jts.geom.MultiPolygon) {
+            org.locationtech.jts.geom.MultiPolygon mp = (org.locationtech.jts.geom.MultiPolygon) geom;
+            for (int i = 0; i < mp.getNumGeometries(); i++) {
+                Polygon poly = (Polygon) mp.getGeometryN(i);
+                addRingToPath(path, poly.getExteriorRing().getCoordinates(), true);
+                for (int j = 0; j < poly.getNumInteriorRing(); j++) {
+                    addRingToPath(path, poly.getInteriorRingN(j).getCoordinates(), true);
+                }
+            }
+        }
+        return path;
+    } // 鏂规硶缁撴潫
+    
+    /** // 鏂囨。娉ㄩ噴寮�濮�
+     * 灏嗗潗鏍囩幆娣诲姞鍒癙ath2D
+     */ // 鏂囨。娉ㄩ噴缁撴潫
+    private static void addRingToPath(Path2D.Double path, Coordinate[] coords, boolean close) {
+        if (coords == null || coords.length < 2) {
+            return;
+        }
+        path.moveTo(coords[0].x, coords[0].y);
+        for (int i = 1; i < coords.length; i++) {
+            path.lineTo(coords[i].x, coords[i].y);
+        }
+        if (close) {
+            path.closePath();
+        }
+    } // 鏂规硶缁撴潫
+    
 
-    private static void drawArrowMarker(Graphics2D g2d, Point2D.Double from, Point2D.Double to, Color color, double scale) { // 缁樺埗绠ご杈呭姪
+    
+    /** // 鏂囨。娉ㄩ噴寮�濮�
+     * 姣旇緝涓や釜鍧愭爣鏄惁鐩稿悓锛堝宸級
+     */ // 鏂囨。娉ㄩ噴缁撴潫
+    private static boolean equals2D(Coordinate a, Coordinate b) {
+        if (a == b) return true;
+        if (a == null || b == null) return false;
+        return a.distance(b) < 1e-4;
+    } // 鏂规硶缁撴潫
+
+    private static void drawArrowMarker(Graphics2D g2d, Point2D.Double from, Point2D.Double to, Color color, double scale, double sizeScale) { // 缁樺埗绠ご杈呭姪
         if (from == null || to == null) { // 鍒ょ┖
             return; // 鏁版嵁涓嶈冻杩斿洖
         } // if缁撴潫
@@ -115,7 +246,8 @@
         } // if缁撴潫
 
     double arrowLength = Math.max(2.5, 5.5 / Math.max(0.5, scale)); // 璁$畻绠ご闀垮害
-    arrowLength *= 0.5; // 缂╁皬绠ご灏哄涓哄師鏉ョ殑涓�鍗�
+    double clampedScale = sizeScale > 0 ? sizeScale : 1.0; // 闃叉闈炴硶缂╂斁
+    arrowLength *= 0.25 * clampedScale; // 缂╁皬绠ご鑷冲師鏉ョ殑涓�鍗�
         double arrowWidth = arrowLength * 0.45; // 璁$畻绠ご瀹藉害
 
         double ux = dx / length; // 鍗曚綅鍚戦噺X
@@ -143,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