| | |
| | | } |
| | | |
| | | List<PathSegment> generate() { |
| | | if (!"spiral".equals(mode)) { |
| | | return generateParallelPath(); |
| | | if ("spiral".equals(mode)) { |
| | | return generateSpiralPath(); |
| | | } |
| | | return generateParallelPath(); |
| | | } |
| | |
| | | return path; |
| | | } |
| | | |
| | | private List<PathSegment> generateSpiralPath() { |
| | | Geometry safeArea = buildSafeArea(); |
| | | if (safeArea == null || safeArea.isEmpty()) { |
| | | System.err.println("安全区域为空,无法生成螺旋路径"); |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | List<PathSegment> spiral = luoxuan.generateSpiralPath(safeArea, width); |
| | | if (spiral.isEmpty()) { |
| | | return spiral; |
| | | } |
| | | |
| | | postProcess(spiral); |
| | | PathSegment firstMowing = null; |
| | | PathSegment endCandidate = null; |
| | | for (int i = 0; i < spiral.size(); i++) { |
| | | PathSegment seg = spiral.get(i); |
| | | if (seg != null && seg.isMowing) { |
| | | if (firstMowing == null) { |
| | | firstMowing = seg; |
| | | } |
| | | endCandidate = seg; |
| | | } |
| | | } |
| | | if (firstMowing != null) { |
| | | firstMowing.setAsStartPoint(); |
| | | } |
| | | if (endCandidate != null && endCandidate != firstMowing) { |
| | | endCandidate.setAsEndPoint(); |
| | | } |
| | | return spiral; |
| | | } |
| | | |
| | | private Geometry buildSafeArea() { |
| | | try { |
| | | Coordinate[] coords = polygon.toArray(new Coordinate[0]); |