@@ -11,7 +11,14 @@ class RouteCore() {
1111 // 获取最后一个点
1212 val lastPoint: ControlNode ? get() = waypoints.lastOrNull()
1313 val totalLength: Double get() = trajectoryList.sumOf { it.length }
14- val totalTime: Double get() = trajectoryList.sumOf { it.duration }
14+ val totalTime: Double
15+ get() = trajectoryList.indices.sumOf { index ->
16+ trajectoryList[index].duration.coerceAtLeast(0.0 ) + arrivalDelayForTrajectory(index)
17+ }
18+
19+ private fun arrivalDelayForTrajectory (index : Int ): Double {
20+ return _waypoints .getOrNull(index + 1 )?.delayAfterArrive?.coerceAtLeast(0.0 ) ? : 0.0
21+ }
1522
1623 // 根据 waypoints 重新构建整条轨迹
1724 private fun rebuildTrajectories () {
@@ -119,13 +126,20 @@ class RouteCore() {
119126 val coercedTime = time.coerceIn(0.0 , totalTime)
120127
121128 var accumulatedTime = 0.0
122- for (traj in trajectoryList) {
123- val nextAccumulatedTime = accumulatedTime + traj.duration
124- if (coercedTime <= nextAccumulatedTime) {
129+ for ((index, traj) in trajectoryList.withIndex()) {
130+ val trajectoryDuration = traj.duration.coerceAtLeast(0.0 )
131+ val trajectoryEndTime = accumulatedTime + trajectoryDuration
132+ if (coercedTime <= trajectoryEndTime) {
125133 val localTime = coercedTime - accumulatedTime
126134 return traj.getPointAtTime(localTime)
127135 }
128- accumulatedTime = nextAccumulatedTime
136+
137+ val delayEndTime = trajectoryEndTime + arrivalDelayForTrajectory(index)
138+ if (coercedTime <= delayEndTime) {
139+ return traj.getPointAtTime(traj.duration)
140+ }
141+
142+ accumulatedTime = delayEndTime
129143 }
130144 // 理论上循环一定能命中,但为了防止极限情况下的浮点精度微小误差导致跳出循环
131145 // 直接返回最后一段轨迹的终点状态
0 commit comments