Repository navigation
オートモードの加減速処理を修正 - #5298
オートモードの加減速処理を修正#5298
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthrough駅の選択をgroupIdからidへ切替し、セグメント内移動を線形補間で計算。セグメント終端で速度0のdwellを導入し、速度プロファイル生成は入力検証とcoast判定を再構築。テスト群をそれぞれ更新・追加。 Changes
Sequence Diagram(s)sequenceDiagram
participant Timer
participant SimHook as useSimulationMode
participant SpeedGen as generateTrainSpeedProfile
participant Movement as MovementEmitter
Timer->>SimHook: tick()
SimHook->>SimHook: resolve current segment (match by id)
SimHook->>SpeedGen: request speed profile for segment
SpeedGen-->>SimHook: speed profile array
SimHook->>SimHook: compute segmentDistance / nextProgressDistance / moveDistance
SimHook->>SimHook: interpolate lat/lon between prevWaypoint & nextWaypoint
alt speeds exhausted (end of segment)
SimHook->>SimHook: set dwellPendingRef (speed = 0)
SimHook->>Movement: emit location (speed=0, heading cleared)
SimHook->>SimHook: advance to next non-empty segment, reset progress
else moving within segment
SimHook->>Movement: emit interpolated location (speed = moveDistance)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
Comment |
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)
418-455:⚠️ Potential issue | 🟡 Minor終端ループ時に始点へ戻す処理を追加したい
nextSegmentIndex が -1 のとき座標が終端のまま index が 0 に戻るため、次ティックで始点区間へワープします。ループ時は始点座標へリセットしてから次区間へ進む方が安全です。修正案
- if (dwellPendingRef.current) { - const prev = store.get(locationAtom); - if (prev) { - setLocation({ - timestamp: Date.now(), - coords: { - ...prev.coords, - speed: 0, - heading: null, - }, - }); - } - const nextSegmentIndex = speedProfilesRef.current.findIndex( - (seg, idx) => seg.length > 0 && idx > segmentIndexRef.current - ); - segmentIndexRef.current = - nextSegmentIndex === -1 ? 0 : nextSegmentIndex; + if (dwellPendingRef.current) { + const nextSegmentIndex = speedProfilesRef.current.findIndex( + (seg, idx) => seg.length > 0 && idx > segmentIndexRef.current + ); + const nextIndex = nextSegmentIndex === -1 ? 0 : nextSegmentIndex; + const prev = store.get(locationAtom); + const firstStation = maybeRevsersedStations[0]; + if (prev) { + const resetToFirst = + nextSegmentIndex === -1 && + firstStation?.latitude != null && + firstStation?.longitude != null; + setLocation({ + timestamp: Date.now(), + coords: { + ...prev.coords, + ...(resetToFirst + ? { + latitude: firstStation.latitude, + longitude: firstStation.longitude, + } + : {}), + speed: 0, + heading: null, + }, + }); + } + segmentIndexRef.current = nextIndex; childIndexRef.current = 0; segmentProgressDistanceRef.current = 0; dwellPendingRef.current = false; return; } @@ - }, [enabled, selectedDirection, step]); + }, [enabled, selectedDirection, step, maybeRevsersedStations]);
🤖 Fix all issues with AI agents
In `@src/utils/trainSpeed.test.ts`:
- Around line 5-7: Replace the afterEach hook's call to jest.restoreAllMocks()
with jest.clearAllMocks() in the test file: locate the afterEach block
(afterEach(() => { jest.restoreAllMocks(); });) and change the mock-reset
function to jest.clearAllMocks() so the test follows the repository's guideline
and aligns with other test files.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/utils/trainSpeed.test.ts`:
- Around line 44-60: The test for generateTrainSpeedProfile can produce false
positives because start may be -1 (making slice empty) and equal-values
(25,25,25...) satisfy the current non-increasing check; update the test to
assert start !== -1 (fail if no maxSpeed found), then verify the coast segment
is strictly decreasing (each next value < previous) rather than non-increasing,
and finally restore the Math.random spy by calling mockRestore() (or use the spy
reference returned by jest.spyOn) at the end of the test to avoid leaking the
mock; target the generateTrainSpeedProfile usage and the Math.random spy in your
changes.
🧹 Nitpick comments (1)
src/utils/trainSpeed.test.ts (1)
92-102:approxDistanceの意図をテスト側で固定すると将来壊れにくいです
現状は「デフォルトinterval=1前提の近似」なので、明示的にinterval: 1を渡す/speed * intervalで積算する形にすると読み手に優しいです。
Summary by CodeRabbit
リリースノート
バグ修正
その他の改善
テスト