Runt
2021-01-04 0e8ecae4a1140c5e23475bbd589f591208e9ed65
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
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.demo.navtogether.utils;
 
import android.graphics.Point;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeMap;
 
/**
 * My father is Object, ites purpose of 距离
 *
 * @purpose Created by Runt (qingingrunt2010@qq.com) on 2020-12-23.
 */
 
public class PathPlan {
 
 
    /**
     * 初始化
     * @param places 地点
     * @return
     */
    public static HashMap<Place,Distance> intPoints(ArrayList<Place> places){
        HashMap<Place,Distance> distanceMap = new HashMap();
        for(Place temp : places){
            distanceMap.put(temp,new Distance(temp).initDistance(places));
        }
        return distanceMap;
 
    }
 
 
    /**
     * 位置
     */
    public static class Place {
        //名称
        public String name;
        //坐标
        public Point point;
        //权重,优先权
        public int priority;
        //上一站距離,计算时补充,初始化为0
        public double distance;
 
        public Place(Place place){
            this.name = place.name;
            this.point = new Point(place.point.x,place.point.y);
            this.priority = place.priority;
        }
        public Place(String name, Point point, int priority) {
            this.name = name;
            this.point = point;
            this.priority = priority;
        }
 
        @Override
        public String toString() {
            return "Place{" +
                    "name='" + name + '\'' +
                    ", point=" + point +
                    '}';
        }
 
 
        @Override
        public int hashCode() {
            return name.hashCode() + point.hashCode();
        }
 
        @Override
        public boolean equals(Object obj) {
            return this.hashCode() == obj.hashCode();
        }
    }
 
    /**
     * 距离
     */
    public static class Distance{
        public Place place;//地点
        public HashMap<Place,Double> distanceMap = new HashMap();//保存与其他所有地点的距离集合
        public Distance(Place place ) {
            this.place = place;
        }
 
        /**
         * 初始化距离
         */
        public Distance initDistance(ArrayList<Place> places){
            for(Place temp : places){
                if(temp != place){
                    //计算两个位置的距离
                    double lengthOfSide = TriangleUtils.getLengthOfSide(place.point, temp.point);
                    distanceMap.put(temp,lengthOfSide);
                }
            }
            return this;
        }
 
    }
 
}