package com.mes.interaction.vehicle.model; import lombok.Data; import java.util.ArrayList; import java.util.List; /** * 车辆路径信息 * * @author mes * @since 2025-01-XX */ @Data public class VehiclePath { /** * 起始位置 */ private VehiclePosition startPosition; /** * 目标位置 */ private VehiclePosition endPosition; /** * 路径点列表(如果路径不是直线) */ private List waypoints; /** * 路径宽度(用于冲突检测) */ private Double pathWidth; public VehiclePath() { this.waypoints = new ArrayList<>(); } public VehiclePath(VehiclePosition start, VehiclePosition end) { this.startPosition = start; this.endPosition = end; this.waypoints = new ArrayList<>(); } /** * 检查路径是否与另一条路径冲突 */ public boolean conflictsWith(VehiclePath other) { if (other == null) { return false; } // 简单冲突检测:检查起点和终点是否重叠 if (startPosition != null && other.startPosition != null) { if (positionsOverlap(startPosition, other.startPosition)) { return true; } } if (endPosition != null && other.endPosition != null) { if (positionsOverlap(endPosition, other.endPosition)) { return true; } } // TODO: 更复杂的路径交叉检测 return false; } private boolean positionsOverlap(VehiclePosition pos1, VehiclePosition pos2) { if (pos1 == null || pos2 == null) { return false; } // 如果有坐标,使用坐标判断 if (pos1.getX() != null && pos1.getY() != null && pos2.getX() != null && pos2.getY() != null) { double distance = pos1.distanceTo(pos2); double threshold = (pathWidth != null ? pathWidth : 100.0) / 2.0; return distance < threshold; } // 如果有位置值,使用位置值判断 if (pos1.getPositionValue() != null && pos2.getPositionValue() != null) { return pos1.getPositionValue().equals(pos2.getPositionValue()); } return false; } }