1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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<VehiclePosition> 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;
    }
}