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 intPoints(ArrayList places){ HashMap 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 distanceMap = new HashMap();//保存与其他所有地点的距离集合 public Distance(Place place ) { this.place = place; } /** * 初始化距离 */ public Distance initDistance(ArrayList places){ for(Place temp : places){ if(temp != place){ //计算两个位置的距离 double lengthOfSide = TriangleUtils.getLengthOfSide(place.point, temp.point); distanceMap.put(temp,lengthOfSide); } } return this; } } }