[feature]
[条件重置]
This commit is contained in:
yangyakun
2023-06-15 10:06:21 +08:00
parent 204ce4c2ea
commit 9d1ffcf0d6
2 changed files with 26 additions and 25 deletions

View File

@@ -2,7 +2,7 @@ package com.mogo.och.common.module.manager.trajectorymamager
data class DistanceDegree(var distance:Float,var degree:Double?,var isNext:Boolean?):Comparable<DistanceDegree>{
override fun compareTo(other: DistanceDegree): Int {
// 对比面积
// 对比距离
if(distance == other.distance){
return 0;
} else if(distance < other.distance){

View File

@@ -16,7 +16,7 @@ import mogo.telematics.pad.MessagePad
import java.util.ArrayList
import java.util.concurrent.ConcurrentHashMap
object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
private val distanceListeners: ConcurrentHashMap<String, IDistanceListener> = ConcurrentHashMap()
private val trajectoryListeners: ConcurrentHashMap<String, ITrajectoryListener> = ConcurrentHashMap()
@@ -26,15 +26,15 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
const val TAGDISTANCE = "BusPassengerModelDistance"
fun addListener(tag: String, listener: IDistanceListener) {
fun addDistanceListener(tag: String, listener: IDistanceListener) {
if (distanceListeners.containsKey(tag)) { return }
distanceListeners[tag] = listener
}
fun addListener(tag: String, listener: ITrajectoryListener) {
fun addTrajectoryListener(tag: String, listener: ITrajectoryListener) {
if (trajectoryListeners.containsKey(tag)) { return }
trajectoryListeners[tag] = listener
}
fun addListener(tag: String, listener: ITrajectoryWithStationListener) {
fun addTrajectoryWithStationListener(tag: String, listener: ITrajectoryWithStationListener) {
if (trajectoryWithStationListeners.containsKey(tag)) { return }
trajectoryWithStationListeners[tag] = listener
}
@@ -74,6 +74,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
d(M_OCHCOMMON + TAG, "收到轨迹:${it.size}第一个点${it[0]}最后一个点:${it.last()}")
endCalculateDistanceLoop()
updateRoutePoints(it)
preCarLocationIndexInTrajectory = 0
startCalculateDistanceLoop()
}
}
@@ -121,7 +122,6 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
private fun calculateDistance() {
//mLocation gcj坐标
CallerChassisLocationGCJ02ListenerManager.getChassisLocationGCJ02().let {
if (mRoutePoints.isNullOrEmpty() || endStationInfo.stationPoint == null) {
d(M_OCHCOMMON + TAG, "没有轨迹或站点坐标停止计算")
//结束距离计算
@@ -175,6 +175,11 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
val carLocationInfo = CoordinateCalculateRouteUtil.getNearestPointInfo(
preCarLocationIndexInTrajectory, mRoutePoints!!, location
)
if(carLocationInfo.second==null||carLocationInfo.third>1_000){
preCarLocationIndexInTrajectory = 0
return
}
d(M_OCHCOMMON+ TAG,"距离车最近的点:${carLocationInfo.first} 点下后面的轨迹:${carLocationInfo.second} 距离点的距离:${carLocationInfo.third}")
preCarLocationIndexInTrajectory = carLocationInfo.first
// 计算结束站点在轨迹中的信息 这个是一个常量可以缓存
@@ -210,9 +215,9 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
var lastSumLength = 0f
val stationIndex = endStationInfo.index?:0
if (preCarLocationIndexInTrajectory < stationIndex) {
if (carLocationInfo.first < stationIndex-1) {
// subList 是[) 需要的是[]
val subList = mRoutePoints!!.subList(preCarLocationIndexInTrajectory, stationIndex + 1)
val subList = mRoutePoints!!.subList(carLocationInfo.first, stationIndex + 1)
// 轨迹点所有的距离
lastSumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(subList)
val stationDistance = endStationInfo.distance ?: 0f
@@ -221,16 +226,15 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
} else {// isNext = false
lastSumLength += stationDistance
}
if (carLocationInfo.second == true) {
if (carLocationInfo.second == true) {// 是否是下一个 true 下一个
lastSumLength += carLocationInfo.third
} else {
lastSumLength -= carLocationInfo.third
}
} else {
val lastPoints = mRoutePoints!![endStationInfo.index!!]
val lastPoints = endStationInfo.stationPoint
lastSumLength = CoordinateUtils.calculateLineDistance(
lastPoints.longitude, lastPoints.latitude,
lastPoints!!.longitude, lastPoints!!.latitude,
location.longitude, location.latitude
)
}
@@ -272,21 +276,20 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
location: MogoLocation
) {
if (mRoutePoints.isNullOrEmpty()) return
var tempPoints = mutableListOf<MogoLocation>()
val routeArrivied = mutableListOf<MogoLocation>()
val routeArriving = mutableListOf<MogoLocation>()
var fromCut = 0
var endCut = mRoutePoints!!.size
if (startStationInfo.stationPoint != null
&& startStationInfo.isNext != null
&& startStationInfo.index != null
&& startStationInfo.distance != null
) {
if(startStationInfo.isNext==true){
tempPoints.addAll(mRoutePoints!!.subList(startStationInfo.index!!,mRoutePoints!!.size))
fromCut = startStationInfo.index!!
}else{
tempPoints.addAll(mRoutePoints!!.subList(startStationInfo.index!!+1,mRoutePoints!!.size))
fromCut = startStationInfo.index!!+1
}
}else{
tempPoints.addAll(mRoutePoints!!)
}
if (endStationInfo.stationPoint != null
@@ -294,21 +297,19 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
&& endStationInfo.index != null
&& endStationInfo.distance != null
) {
val index = endStationInfo.index!!
if(endStationInfo.isNext==true){
tempPoints = tempPoints.subList(0, index-1)
endCut = endStationInfo.index!!
}else{
tempPoints = tempPoints.subList(0, index)
endCut = endStationInfo.index!!+1
}
}
if(carLocationInfo.second==true){// isNext = true
routeArrivied.addAll(tempPoints.subList(0,carLocationInfo.first))
routeArriving.addAll(mRoutePoints!!.subList(carLocationInfo.first,mRoutePoints!!.size))
routeArrivied.addAll(mRoutePoints!!.subList(fromCut,carLocationInfo.first))
routeArriving.addAll(mRoutePoints!!.subList(carLocationInfo.first,endCut))
}else{// isNext = false
val indexNext = carLocationInfo.first+1
routeArrivied.addAll(tempPoints.subList(0,indexNext))
routeArriving.addAll(mRoutePoints!!.subList(indexNext,mRoutePoints!!.size))
routeArrivied.addAll(mRoutePoints!!.subList(fromCut,indexNext))
routeArriving.addAll(mRoutePoints!!.subList(indexNext,endCut))
}
routeArrivied.add(0, startStationInfo.stationPoint!!)