@@ -154,26 +154,23 @@ export const useSimulationMode = (): void => {
154154 useEffect ( ( ) => {
155155 const speedProfiles = maybeRevsersedStations . map (
156156 ( cur , curMapIndex , arr ) => {
157- const stationsWithoutPass = arr . filter ( ( s ) => ! getIsPass ( s ) ) ;
158-
159- const curIdx = stationsWithoutPass . indexOf ( cur ) ;
160- if ( curIdx === - 1 ) {
157+ if ( getIsPass ( cur ) ) {
161158 // 通過駅は速度プロファイル生成対象外
162159 return [ ] ;
163160 }
164161
165- const next = stationsWithoutPass [ curIdx + 1 ] ;
162+ const nextStationIndex = arr . findIndex (
163+ ( station , idx ) => idx > curMapIndex && ! getIsPass ( station )
164+ ) ;
165+ if ( nextStationIndex === - 1 ) {
166+ return [ ] ;
167+ }
168+ const next = arr [ nextStationIndex ] ;
166169 if ( ! next ) {
167170 return [ ] ;
168171 }
169172
170- const stationIndex = curMapIndex ;
171- const nextStationIndex = arr . indexOf ( next ) ;
172-
173- const betweenNextStation = arr . slice (
174- stationIndex + 1 ,
175- nextStationIndex
176- ) ;
173+ const betweenNextStation = arr . slice ( curMapIndex + 1 , nextStationIndex ) ;
177174
178175 if (
179176 cur . latitude == null ||
@@ -261,26 +258,10 @@ export const useSimulationMode = (): void => {
261258 }
262259
263260 // segmentIndexRefに基づいて目的地を決定(nextStationフックに依存しない)
264- const stationsWithoutPass = maybeRevsersedStations . filter (
265- ( s ) => ! getIsPass ( s )
266- ) ;
267- if ( stationsWithoutPass . length === 0 ) {
268- return ;
269- }
270-
271- const currentSegmentStation =
272- maybeRevsersedStations [ normalizedSegmentIndex ] ;
273- if ( ! currentSegmentStation ) {
274- return ;
275- }
276- const currentSegmentStationIndex = normalizedSegmentIndex ;
277-
278- const currentSegmentStopIndex = stationsWithoutPass . indexOf (
279- currentSegmentStation
261+ const nextStopStationIndex = maybeRevsersedStations . findIndex (
262+ ( station , idx ) => idx > normalizedSegmentIndex && ! getIsPass ( station )
280263 ) ;
281- const nextStopStation = stationsWithoutPass [ currentSegmentStopIndex + 1 ] ;
282-
283- if ( ! nextStopStation ) {
264+ if ( nextStopStationIndex === - 1 ) {
284265 segmentIndexRef . current = 0 ;
285266 childIndexRef . current = 0 ;
286267 segmentProgressDistanceRef . current = 0 ;
@@ -302,15 +283,25 @@ export const useSimulationMode = (): void => {
302283 return ;
303284 }
304285
286+ const currentSegmentStation =
287+ maybeRevsersedStations [ normalizedSegmentIndex ] ;
288+ if ( ! currentSegmentStation ) {
289+ return ;
290+ }
291+ const currentSegmentStationIndex = normalizedSegmentIndex ;
292+
293+ const nextStopStation = maybeRevsersedStations [ nextStopStationIndex ] ;
294+ if ( ! nextStopStation ) {
295+ return ;
296+ }
297+
305298 if (
306299 nextStopStation . latitude == null ||
307300 nextStopStation . longitude == null
308301 ) {
309302 return ;
310303 }
311304
312- const nextStopStationIndex =
313- maybeRevsersedStations . indexOf ( nextStopStation ) ;
314305 if (
315306 nextStopStationIndex < 0 ||
316307 nextStopStationIndex < currentSegmentStationIndex
0 commit comments