Repository navigation
オートモードのアプローチ変更 - #5322
オートモードのアプローチ変更#5322
Conversation
📝 WalkthroughWalkthroughシミュレーションフックの速度プロファイル生成とウェイポイント進行をインデックスベースで再実装し、座標検証・距離計算・プロファイル正規化を導入。重複駅IDを扱うテストスイートを追加。 Changes
Sequence Diagram(s)sequenceDiagram
participant Hook as useSimulationMode
participant Stations as StationList
participant Gen as generateTrainSpeedProfile
participant Store as LocationStore
Hook->>Stations: currentIndex, nextIndex, between stations を indexOf で取得
Hook->>Stations: ポイント列(cur + between + next) の座標を取得
Hook->>Gen: 距離・加減速パラメータで速度プロファイル生成を要求
Gen-->>Hook: 正規化された速度プロファイルを返却
Hook->>Store: ウェイポイント進行に基づく位置・経路更新を適用
Store-->>Hook: 更新結果(位置/到達情報)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/hooks/useSimulationMode.test.tsx (1)
61-93: テストヘルパー関数の再利用検討
mockStationやmockPassStationのようなヘルパー関数は他のテストでも有用な可能性があります。将来的にsrc/utils/test/へ抽出を検討してください。🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/hooks/useSimulationMode.test.tsx` around lines 61 - 93, Extract the test helpers mockStation and mockPassStation from useSimulationMode.test.tsx into a shared test-helper module and import them back into this test; update their exports so other test files can reuse them and adjust any imports in tests that previously redefined these helpers. Ensure the helpers keep the same signatures and types (e.g., mockStation(id:number, groupId:number, lat:number, lon:number, lineId?:number): Station) and update any type casts or dependencies (OperationStatus, StopCondition, LineType, YAMANOTE_LINE_ID) to be imported from their original modules in the new helper module.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/hooks/useSimulationMode.ts`:
- Around line 212-214: Guard against division by zero when computing
distanceRatio: after computing profileDistance (from speedProfile) check if
profileDistance === 0 and, if so, set correctedProfile to an array of zeros
(e.g., speedProfile.map(()=>0)) instead of dividing; otherwise compute
distanceRatio and correctedProfile as before. Update the logic around
profileDistance, distanceRatio and correctedProfile in useSimulationMode.ts
(referencing speedProfile, profileDistance, distanceRatio, correctedProfile and
generateTrainSpeedProfile) to ensure no Infinity values are produced.
---
Nitpick comments:
In `@src/hooks/useSimulationMode.test.tsx`:
- Around line 61-93: Extract the test helpers mockStation and mockPassStation
from useSimulationMode.test.tsx into a shared test-helper module and import them
back into this test; update their exports so other test files can reuse them and
adjust any imports in tests that previously redefined these helpers. Ensure the
helpers keep the same signatures and types (e.g., mockStation(id:number,
groupId:number, lat:number, lon:number, lineId?:number): Station) and update any
type casts or dependencies (OperationStatus, StopCondition, LineType,
YAMANOTE_LINE_ID) to be imported from their original modules in the new helper
module.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/hooks/useSimulationMode.ts (1)
269-305:⚠️ Potential issue | 🟠 Major
step側も同じ indexOf 問題で区間が戻る可能性
stationsWithoutPass.indexOf(currentSegmentStation)は重複参照で先頭一致になり、nextStopStationが過去側に戻る可能性があります。ここもcurrentSegmentStationIndexから前方検索に統一してください。🛠 修正案
- const currentSegmentStopIndex = stationsWithoutPass.indexOf( - currentSegmentStation - ); - const nextStopStation = stationsWithoutPass[currentSegmentStopIndex + 1]; + const nextStopStationIndex = maybeRevsersedStations.findIndex( + (s, idx) => idx > currentSegmentStationIndex && !getIsPass(s) + ); + const nextStopStation = + nextStopStationIndex === -1 + ? undefined + : maybeRevsersedStations[nextStopStationIndex]; @@ - const nextStopStationIndex = - maybeRevsersedStations.indexOf(nextStopStation);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/hooks/useSimulationMode.ts` around lines 269 - 305, The code uses stationsWithoutPass.indexOf(currentSegmentStation) which can match an earlier duplicate and make nextStopStation jump backwards; change the search to start after the current segment index by replacing that call with stationsWithoutPass.indexOf(currentSegmentStation, currentSegmentStationIndex + 1) (or otherwise use the existing currentSegmentStationIndex as the fromIndex) so nextStopStation is always found forward; update any related logic that assumes currentSegmentStopIndex accordingly (references: stationsWithoutPass.indexOf(currentSegmentStation), currentSegmentStationIndex, nextStopStation).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/hooks/useSimulationMode.ts`:
- Around line 146-167: The current map callback in maybeRevsersedStations uses
stationsWithoutPass.indexOf(cur) which breaks when identical station objects
appear multiple times; instead, starting from curMapIndex scan arr forward (from
curMapIndex+1) to find the first element where !getIsPass(s) and treat that as
the next stop. Update the logic in the map callback (the function using cur,
curMapIndex, arr and variables stationsWithoutPass, curIdx, next,
nextStationIndex, betweenNextStation) to compute nextStationIndex by
forward-searching arr for the next non-pass station rather than using
stationsWithoutPass.indexOf(cur), then slice between using those indices as
before.
---
Outside diff comments:
In `@src/hooks/useSimulationMode.ts`:
- Around line 269-305: The code uses
stationsWithoutPass.indexOf(currentSegmentStation) which can match an earlier
duplicate and make nextStopStation jump backwards; change the search to start
after the current segment index by replacing that call with
stationsWithoutPass.indexOf(currentSegmentStation, currentSegmentStationIndex +
1) (or otherwise use the existing currentSegmentStationIndex as the fromIndex)
so nextStopStation is always found forward; update any related logic that
assumes currentSegmentStopIndex accordingly (references:
stationsWithoutPass.indexOf(currentSegmentStation), currentSegmentStationIndex,
nextStopStation).
サンライズ出雲で途中駅で戻ったり進んだりするバグを修正
Summary by CodeRabbit
リリースノート
テスト
バグ修正