feat(viz): LiDAR sensor mount offset - #84
Conversation
`LidarScan.scan(origin, rot?, mountOffset?)` now accepts an optional drone-local mount offset (e.g. `[0, 0.5, 0]` for a sensor on a 0.5 m mast). The offset is rotated into world space by `rot` and added to `origin` to produce the actual scan origin. Mechanics: - Hoists the q→3x3 rotation matrix outside the existing per-ray loop so it can be reused for both the mount-offset transform and the direction rotation. No new compute cost on the scan side (matrix already needed to be built); offset application is a single matrix-vector multiply per scan. - Hit positions now derive from `this._origin` (the post-offset scan origin) rather than the raw `origin` parameter — without this, a mast-mounted sensor would report hits as if rays started at the drone center but ended at the mast tip, drifting by the offset length. - Backward-compatible: existing `effects.ts:_updateLidar` keeps passing two args; `mountOffset` defaults to undefined and the bare drone-origin path stays bit-identical to PR #80. Tests: - World-axis-aligned offset application (no rot) - Rotation of offset by quaternion (yaw 90° → +X local maps to −Z world) - Bare-origin path unchanged Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughIntroduces an optional Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
There was a problem hiding this comment.
Code Review
This pull request adds support for a mountOffset in the LidarScan.scan method, allowing hit positions to be calculated relative to a sensor's local position on a drone. The changes include logic to rotate the offset into world space and new unit tests to verify the coordinate math. A potential race condition was identified where the scan origin is read from a shared mutable buffer after an asynchronous operation, which could lead to incorrect results if multiple scans are performed concurrently.
Address Gemini review on PR #84: capture `ox/oy/oz` from `this._origin` BEFORE the `await this.los.query(rays)` rather than after. The tuple is shared mutable state; if another scan() landed on the same instance while the query was in flight, the post-await read would see the next scan's origin and the hit-position math would silently produce wrong world-space positions. The current consumer gates per-drone via the in-flight flag in effects.ts, so the race isn't reachable today — this just makes LidarScan robust to other call patterns and future mistakes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
LidarScan.scan(origin, rot?, mountOffset?)now accepts an optional drone-local mount offset (e.g.[0, 0.5, 0]for a sensor on a 0.5 m mast). The offset is rotated into world space byrotand added tooriginto produce the actual scan origin.Mechanics
this._origin(the post-offset scan origin) rather than the raworiginparameter — without this, a mast-mounted sensor would report hits as if rays started at the drone center but ended at the mast tip.effects.ts:_updateLidarkeeps passing two args;mountOffsetdefaults to undefined and the bare drone-origin path stays bit-identical to PR feat(viz): per-drone LiDAR scans #80.Tests
Three new cases in
client/__tests__/lidar.test.ts:Suite goes 14 → 17 tests, runtime unchanged (~380 ms).
Bundle
Main 756.4 → 756.6 KB (+200 B; 92 % of cap).
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Tests