From f94b1436d7a28c8e28d010b2cb657ab7c064e353 Mon Sep 17 00:00:00 2001
From: 826220679@qq.com <826220679@qq.com>
Date: 星期日, 28 十二月 2025 20:36:38 +0800
Subject: [PATCH] 修改了导航预览
---
src/zhuye/MapRenderer.java | 105 ++++++++++++++++++++++++++++++++++------------------
1 files changed, 68 insertions(+), 37 deletions(-)
diff --git a/src/zhuye/MapRenderer.java b/src/zhuye/MapRenderer.java
index 2d77ce3..e354548 100644
--- a/src/zhuye/MapRenderer.java
+++ b/src/zhuye/MapRenderer.java
@@ -18,6 +18,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Set;
+import java.util.function.Consumer;
import java.io.File;
import set.Setsys;
import gecaoji.Device;
@@ -488,10 +489,7 @@
drawMower(g2d);
- // 缁樺埗瀵艰埅棰勮閫熷害锛堝鏋滄鍦ㄥ鑸瑙堬級
- if (navigationPreviewSpeed > 0 && mower != null && mower.hasValidPosition()) {
- drawNavigationPreviewSpeed(g2d, scale);
- }
+ // 宸叉寜闇�姹傜Щ闄わ細涓嶅湪鍓茶崏鏈哄浘鏍囦笂鏂规樉绀洪�熷害
// 缁樺埗娴嬮噺妯″紡锛堝鏋滄縺娲伙級
if (measurementModeActive) {
@@ -563,16 +561,21 @@
g2d.setFont(labelFont);
FontMetrics metrics = g2d.getFontMetrics(labelFont);
- // 璁$畻鏂囧瓧浣嶇疆锛堝湪鍓茶崏鏈哄浘鏍囦笂鏂癸級
+ // 璁$畻鏂囧瓧浣嶇疆锛堝湪鍓茶崏鏈哄浘鏍囨涓婃柟锛岄棿闅�20鍍忕礌鍥哄畾锛�
int textWidth = metrics.stringWidth(speedText);
int textHeight = metrics.getHeight();
int textX = (int)Math.round(screenPos.x - textWidth / 2.0);
- // 鍦ㄥ壊鑽夋満鍥炬爣涓婃柟锛岀暀鍑轰竴瀹氶棿璺�
- // 鍥炬爣鍦ㄤ笘鐣屽潗鏍囩郴涓殑澶у皬绾︿负 48 * 0.8 / scale 绫�
- // 杞崲涓哄睆骞曞儚绱狅細鍥炬爣楂樺害锛堝儚绱狅級= (48 * 0.8 / scale) * scale = 48 * 0.8 = 38.4 鍍忕礌
- double iconSizePixels = 48.0 * 0.8; // 鍥炬爣鍦ㄥ睆骞曚笂鐨勫ぇ灏忥紙鍍忕礌锛�
- int spacing = 8; // 闂磋窛锛堝儚绱狅級
- int textY = (int)Math.round(screenPos.y - iconSizePixels / 2.0 - spacing - textHeight);
+ // 鍦ㄥ壊鑽夋満鍥炬爣姝d笂鏂癸紝闂撮殧20鍍忕礌
+ // 浠巑ower瀵硅薄鑾峰彇鍥炬爣鍦ㄤ笘鐣屽潗鏍囩郴涓殑鍗婂緞锛岀劧鍚庤浆鎹负灞忓箷鍍忕礌
+ double iconWorldRadius = mower.getWorldRadius(scale);
+ double iconSizePixels = Double.isNaN(iconWorldRadius) ? 38.4 : (iconWorldRadius * 2.0 * scale); // 鍥炬爣鍦ㄥ睆骞曚笂鐨勫ぇ灏忥紙鍍忕礌锛�
+ int spacing = 20; // 闂磋窛锛堝儚绱狅級
+ // 鍥炬爣椤堕儴浣嶇疆 = 鍥炬爣涓績Y - 鍥炬爣楂樺害/2
+ double iconTopY = screenPos.y - iconSizePixels / 2.0;
+ // 绮剧‘绾︽潫锛氳鑳屾櫙鐭╁舰鐨勫簳杈逛笌鍥炬爣椤堕儴鐩歌窛鍥哄畾spacing鍍忕礌
+ // 鑳屾櫙搴曡竟 = textY + metrics.getDescent() + 2锛堢煩褰笅鏂瑰唴杈硅窛锛�
+ // 浠� 鑳屾櫙搴曡竟 = iconTopY - spacing锛岃В寰楋細
+ int textY = (int)Math.round(iconTopY - spacing - metrics.getDescent() - 2);
// 缁樺埗鏂囧瓧鑳屾櫙锛堝崐閫忔槑鐧借壊锛屽寮哄彲璇绘�э級
g2d.setColor(new Color(255, 255, 255, 200));
@@ -632,7 +635,7 @@
* 娣诲姞瀵艰埅棰勮杞ㄨ抗鐐�
*/
public void addNavigationPreviewTrackPoint(Point2D.Double point) {
- if (point != null && Double.isFinite(point.x) && Double.isFinite(point.y)) {
+ if (point != null && isFinite(point.x) && isFinite(point.y)) {
navigationPreviewTrack.add(new Point2D.Double(point.x, point.y));
if (visualizationPanel != null) {
visualizationPanel.repaint();
@@ -750,7 +753,7 @@
return;
}
Point2D.Double position = mower.getPosition();
- if (position == null || !Double.isFinite(position.x) || !Double.isFinite(position.y)) {
+ if (position == null || !isFinite(position.x) || !isFinite(position.y)) {
pendingTrackBreak = true;
return;
}
@@ -776,7 +779,7 @@
}
realtimeMowingTrack.add(candidate);
- if (!pendingTrackBreak && lastPoint != null && Double.isFinite(distance)) {
+ if (!pendingTrackBreak && lastPoint != null && isFinite(distance)) {
trackLengthMeters += distance;
}
@@ -807,7 +810,7 @@
}
Point2D.Double position = mower.getPosition();
- if (position == null || !Double.isFinite(position.x) || !Double.isFinite(position.y)) {
+ if (position == null || !isFinite(position.x) || !isFinite(position.y)) {
return;
}
@@ -852,7 +855,7 @@
// 鍒锋柊mower浣嶇疆锛屼娇鐢ㄦ渶鏂扮殑Device鏁版嵁
mower.refreshFromDevice();
Point2D.Double position = mower.getPosition();
- if (position == null || !Double.isFinite(position.x) || !Double.isFinite(position.y)) {
+ if (position == null || !isFinite(position.x) || !isFinite(position.y)) {
return;
}
@@ -963,7 +966,7 @@
}
private String formatTrackCoordinate(double value) {
- if (!Double.isFinite(value)) {
+ if (!isFinite(value)) {
return "0";
}
return String.format(Locale.US, "%.3f", value);
@@ -1154,7 +1157,7 @@
try {
double x = Double.parseDouble(parts[0].trim());
double y = Double.parseDouble(parts[1].trim());
- if (!Double.isFinite(x) || !Double.isFinite(y)) {
+ if (!isFinite(x) || !isFinite(y)) {
continue;
}
Point2D.Double current = new Point2D.Double(x, y);
@@ -1459,6 +1462,7 @@
String safetyDistance = null;
String obstaclesCoords = null;
String mowingPattern = null;
+ String plannedPathStr = null;
// 浠庡綋鍓嶅湴鍧楃紪鍙疯幏鍙栧湴鍧椾俊鎭�
if (currentBoundaryLandNumber != null) {
@@ -1468,6 +1472,8 @@
mowingWidth = landData.getMowingWidth();
safetyDistance = landData.getMowingSafetyDistance();
mowingPattern = landData.getMowingPattern();
+ // 浠庡湴鍧楄幏鍙杙lannedPath灞炴�у�间綔涓鸿矾寰�
+ plannedPathStr = landData.getPlannedPath();
// 鑾峰彇闅滅鐗╁潗鏍�
try {
@@ -1525,9 +1531,26 @@
}
}
- // 璋冪敤甯﹀湴鍧椾俊鎭殑缁樺埗鏂规硶
- lujingdraw.drawPlannedPath(g2d, currentPlannedPath, scale, arrowScale,
- boundaryCoords, mowingWidth, safetyDistance, obstaclesCoords, mowingPattern);
+ // 濡傛灉浠庡湴鍧楄幏鍙栧埌浜嗚矾寰勶紝浣跨敤鍦板潡鐨勮矾寰勶紱鍚﹀垯浣跨敤currentPlannedPath
+ List<Point2D.Double> pathToDraw = currentPlannedPath;
+ List<Boolean> flags = null;
+ if (plannedPathStr != null && !plannedPathStr.trim().isEmpty() && !"-1".equals(plannedPathStr.trim())) {
+ // 浼樺厛瑙f瀽甯︽爣娉ㄦ牸寮�
+ lujingdraw.ParsedPath parsed = lujingdraw.parsePlannedPathWithFlags(plannedPathStr);
+ pathToDraw = parsed.points;
+ flags = parsed.isMowingFlags;
+ }
+
+ // 璋冪敤甯﹀湴鍧椾俊鎭殑缁樺埗鏂规硶锛堝鏈夋爣娉ㄤ紭鍏堜娇鐢級
+ if (pathToDraw != null && pathToDraw.size() >= 2) {
+ if (flags != null && flags.size() == pathToDraw.size() - 1) {
+ lujingdraw.drawPlannedPath(g2d, pathToDraw, flags, scale, arrowScale,
+ boundaryCoords, mowingWidth, safetyDistance, obstaclesCoords, mowingPattern);
+ } else {
+ lujingdraw.drawPlannedPath(g2d, pathToDraw, scale, arrowScale,
+ boundaryCoords, mowingWidth, safetyDistance, obstaclesCoords, mowingPattern);
+ }
+ }
}
private void drawCircleSampleMarkers(Graphics2D g2d, List<double[]> markers, double scale) {
@@ -1549,7 +1572,7 @@
FontMetrics metrics = g2d.getFontMetrics(labelFont);
for (double[] pt : markers) {
- if (pt == null || pt.length < 2 || !Double.isFinite(pt[0]) || !Double.isFinite(pt[1])) {
+ if (pt == null || pt.length < 2 || !isFinite(pt[0]) || !isFinite(pt[1])) {
continue;
}
double x = pt[0];
@@ -1647,7 +1670,7 @@
}
double x = pt[0];
double y = pt[1];
- if (!Double.isFinite(x) || !Double.isFinite(y)) {
+ if (!isFinite(x) || !isFinite(y)) {
continue;
}
circleSampleMarkers.add(new double[]{x, y});
@@ -1870,7 +1893,7 @@
private double computeSelectionThresholdPixels() {
double scaleFactor = Math.max(0.5, scale);
double diameterScale = boundaryPointSizeScale * (previewSizingEnabled ? PREVIEW_BOUNDARY_MARKER_SCALE : 1.0d);
- if (!Double.isFinite(diameterScale) || diameterScale <= 0.0d) {
+ if (!isFinite(diameterScale) || diameterScale <= 0.0d) {
diameterScale = 1.0d;
}
double markerDiameterWorld = Math.max(1.0, (10.0 / scaleFactor) * 0.2 * diameterScale);
@@ -2035,7 +2058,7 @@
}
private boolean isPointInsideActiveBoundary(Point2D.Double point) {
- if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
+ if (point == null || !isFinite(point.x) || !isFinite(point.y)) {
return false;
}
if (realtimeTrackLandNumber == null) {
@@ -2046,7 +2069,7 @@
}
private boolean isPointInsideBoundary(Point2D.Double point, Path2D.Double path) {
- if (point == null || path == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
+ if (point == null || path == null || !isFinite(point.x) || !isFinite(point.y)) {
return false;
}
if (path.contains(point.x, point.y)) {
@@ -2067,7 +2090,7 @@
Path2D.Double path = new Path2D.Double();
boolean started = false;
for (Point2D.Double point : boundary) {
- if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
+ if (point == null || !isFinite(point.x) || !isFinite(point.y)) {
continue;
}
if (!started) {
@@ -2103,7 +2126,7 @@
// 璁剧疆鐐圭殑澶у皬锛堥殢缂╂斁鍙樺寲锛�
double scaleFactor = Math.max(0.5, scale);
double clampedScale = boundaryPointSizeScale * (previewSizingEnabled ? PREVIEW_BOUNDARY_MARKER_SCALE : 1.0d);
- if (!Double.isFinite(clampedScale) || clampedScale <= 0.0d) {
+ if (!isFinite(clampedScale) || clampedScale <= 0.0d) {
clampedScale = 1.0d;
}
double minimumDiameter = clampedScale < 1.0 ? 0.5 : 1.0;
@@ -2552,7 +2575,7 @@
}
double x = coord.getX();
double y = coord.getY();
- if (!Double.isFinite(x) || !Double.isFinite(y)) {
+ if (!isFinite(x) || !isFinite(y)) {
continue;
}
copy.add(new Obstacledge.XYCoordinate(x, y));
@@ -2890,7 +2913,7 @@
}
public void setBoundaryPointSizeScale(double sizeScale) {
- double normalized = (Double.isFinite(sizeScale) && sizeScale > 0.0d) ? sizeScale : 1.0d;
+ double normalized = (isFinite(sizeScale) && sizeScale > 0.0d) ? sizeScale : 1.0d;
if (Math.abs(boundaryPointSizeScale - normalized) < 1e-6) {
return;
}
@@ -2918,7 +2941,7 @@
}
public void setBoundaryPreviewMarkerScale(double markerScale) {
- double normalized = Double.isFinite(markerScale) && markerScale > 0.0d ? markerScale : 1.0d;
+ double normalized = isFinite(markerScale) && markerScale > 0.0d ? markerScale : 1.0d;
if (Math.abs(boundaryPreviewMarkerScale - normalized) < 1e-6) {
return;
}
@@ -2955,7 +2978,7 @@
}
public void addHandheldBoundaryPoint(double x, double y) {
- if (!Double.isFinite(x) || !Double.isFinite(y)) {
+ if (!isFinite(x) || !isFinite(y)) {
return;
}
if (!handheldBoundaryPreviewActive) {
@@ -3067,8 +3090,8 @@
Point2D.Double mowerPosition = mower.getPosition();
if (mowerPosition == null
- || !Double.isFinite(mowerPosition.x)
- || !Double.isFinite(mowerPosition.y)) {
+ || !isFinite(mowerPosition.x)
+ || !isFinite(mowerPosition.y)) {
return expanded;
}
@@ -3512,9 +3535,9 @@
/**
* 璁剧疆杈圭晫棰勮鏇存柊鍥炶皟
*/
- private java.util.function.Consumer<String> boundaryPreviewUpdateCallback;
+ private Consumer<String> boundaryPreviewUpdateCallback;
- public void setBoundaryPreviewUpdateCallback(java.util.function.Consumer<String> callback) {
+ public void setBoundaryPreviewUpdateCallback(Consumer<String> callback) {
this.boundaryPreviewUpdateCallback = callback;
}
@@ -3531,4 +3554,12 @@
fitBoundsToView(bounds);
}
}
-}
\ No newline at end of file
+
+ /**
+ * 妫�鏌ouble鍊兼槸鍚︽湁闄愶紙涓嶆槸NaN鎴栨棤绌峰ぇ锛�
+ * 鍏煎浣庣増鏈琂ava
+ */
+ private static boolean isFinite(double value) {
+ return !Double.isNaN(value) && !Double.isInfinite(value);
+ }
+}
--
Gitblit v1.10.0