-
Notifications
You must be signed in to change notification settings - Fork 1
feat(geom): rmg-geom foundation (split PR 2) #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cbc0242
8832650
a086c56
c9ccd6e
025ede8
7f4188b
6938f00
9862678
7756121
80b7ede
9d1a355
8c26887
9b6d8be
e86474e
b98e81d
4fdaeb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| { | ||
| "name": "echo-dev", | ||
| "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", | ||
| "features": { | ||
| "ghcr.io/devcontainers/features/common-utils:2": { | ||
| "username": "vscode", | ||
| "installZsh": false | ||
| }, | ||
| "ghcr.io/devcontainers/features/rust:1": { | ||
| "profile": "minimal", | ||
| "components": ["rustfmt", "clippy"] | ||
| }, | ||
| "ghcr.io/devcontainers/features/node:1": { | ||
| "version": "20" | ||
| }, | ||
| "ghcr.io/devcontainers/features/github-cli:1": {} | ||
| }, | ||
| "customizations": { | ||
| "vscode": { | ||
| "extensions": [ | ||
| "rust-lang.rust-analyzer", | ||
| "serayuzgur.crates", | ||
| "tamasfe.even-better-toml", | ||
| "vadimcn.vscode-lldb" | ||
| ] | ||
| } | ||
| }, | ||
| "mounts": [ | ||
| "source=devcontainer-cargo-cache,target=/usr/local/cargo,type=volume", | ||
| "source=devcontainer-rustup-cache,target=/usr/local/rustup,type=volume" | ||
| ], | ||
| "containerEnv": { | ||
| "CARGO_TERM_COLOR": "always" | ||
| }, | ||
| "overrideCommand": false, | ||
| "postCreateCommand": "/bin/bash .devcontainer/post-create.sh" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| echo "[devcontainer] Installing MSRV toolchain (1.68.0) and respecting rust-toolchain.toml..." | ||
| if ! command -v rustup >/dev/null 2>&1; then | ||
| curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused --location --silent --show-error --fail https://sh.rustup.rs | sh -s -- --default-toolchain none -y | ||
| export PATH="$HOME/.cargo/bin:$PATH" | ||
| fi | ||
|
|
||
| rustup toolchain install 1.68.0 --profile minimal | ||
| # Do not override default; let rust-toolchain.toml control toolchain selection for this repo. | ||
| # Install optional newer toolchain for local convenience (kept as non-default). | ||
| rustup toolchain install 1.90.0 --profile minimal || true | ||
| # Ensure components/targets are available for the active (rust-toolchain.toml) toolchain. | ||
| rustup component add rustfmt clippy || true | ||
| rustup target add wasm32-unknown-unknown || true | ||
|
|
||
| echo "[devcontainer] Priming cargo registry cache (optional)..." | ||
| cargo fetch || true | ||
|
|
||
| echo "[devcontainer] Done. Run 'cargo test -p rmg-core' or 'make ci-local' to validate." |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [package] | ||
| name = "rmg-geom" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| description = "Echo geometry primitives: AABB, transforms, temporal proxies, and broad-phase scaffolding" | ||
| license = "Apache-2.0" | ||
| repository = "https://github.com/flyingrobots/echo" | ||
| readme = "../../README.md" | ||
| keywords = ["echo", "geometry", "aabb", "broad-phase"] | ||
| categories = ["game-engines", "data-structures"] | ||
|
|
||
| [dependencies] | ||
| rmg-core = { path = "../rmg-core" } | ||
|
|
||
| [dev-dependencies] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #![deny( | ||
| warnings, | ||
| clippy::all, | ||
| clippy::pedantic, | ||
| rust_2018_idioms, | ||
| missing_docs, | ||
| clippy::unwrap_used, | ||
| clippy::expect_used, | ||
| clippy::panic | ||
| )] | ||
| #![doc = r"Geometry primitives for Echo. | ||
|
|
||
| This crate provides: | ||
| - Axis-aligned bounding boxes (`Aabb`). | ||
| - Rigid transforms (`Transform`). | ||
| - Temporal utilities (`Tick`, `TemporalTransform`, `TemporalProxy`). | ||
| - A minimal broad-phase trait and an AABB-based pairing structure. | ||
|
|
||
| Design notes: | ||
| - Deterministic: no ambient RNG; ordering of pair outputs is canonical. | ||
| - Float32 throughout; operations favor clarity and reproducibility. | ||
| - Rustdoc is treated as part of the contract; public items are documented. | ||
| "] | ||
|
|
||
| /// Time-aware utilities for broad-phase and motion. | ||
| pub mod temporal; | ||
| /// Foundational geometric types. | ||
| pub mod types; | ||
| // Broad-phase will land in a follow-up PR. | ||
| // pub mod broad; | ||
|
|
||
| pub use types::aabb::Aabb; | ||
| pub use types::transform::Transform; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,40 @@ | ||||||||||||||||||||||||||
| use crate::temporal::tick::Tick; | ||||||||||||||||||||||||||
| use crate::types::aabb::Aabb; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /// Broad-phase proxy summarizing an entity’s swept position manifold over a tick. | ||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||
| /// Stores a conservative fat AABB and the owning `entity` identifier (opaque | ||||||||||||||||||||||||||
| /// to the geometry layer). The proxy is suitable for insertion into a broad- | ||||||||||||||||||||||||||
| /// phase accelerator. | ||||||||||||||||||||||||||
| #[derive(Debug, Copy, Clone, PartialEq)] | ||||||||||||||||||||||||||
| pub struct PositionProxy { | ||||||||||||||||||||||||||
| entity: u64, | ||||||||||||||||||||||||||
| tick: Tick, | ||||||||||||||||||||||||||
| fat: Aabb, | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+9
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major From: Linus Torvalds torvalds@linux-foundation.org Add Your rustdoc at line 7 says this proxy is "suitable for insertion into a broad-phase accelerator." Great. Except broad-phase accelerators use hash tables for O(1) proxy lookups by entity ID, and you've got This means your "suitable" type can't actually be used as a Apply this diff: -#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct PositionProxy {BunBun 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| impl PositionProxy { | ||||||||||||||||||||||||||
| /// Creates a new proxy for `entity` at `tick` with precomputed `fat` AABB. | ||||||||||||||||||||||||||
| #[must_use] | ||||||||||||||||||||||||||
| pub const fn new(entity: u64, tick: Tick, fat: Aabb) -> Self { | ||||||||||||||||||||||||||
| Self { entity, tick, fat } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /// Opaque entity identifier owning this proxy. | ||||||||||||||||||||||||||
| #[must_use] | ||||||||||||||||||||||||||
| pub const fn entity(&self) -> u64 { | ||||||||||||||||||||||||||
| self.entity | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /// Tick associated with the motion window. | ||||||||||||||||||||||||||
| #[must_use] | ||||||||||||||||||||||||||
| pub const fn tick(&self) -> Tick { | ||||||||||||||||||||||||||
| self.tick | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /// Conservative fat AABB for this proxy. | ||||||||||||||||||||||||||
| #[must_use] | ||||||||||||||||||||||||||
| pub const fn fat(&self) -> Aabb { | ||||||||||||||||||||||||||
| self.fat | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+16
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainFrom: Linus Torvalds torvalds@linux-foundation.org Where are the unit tests? Your PR description promises "unit tests will be added in this PR to meet the coverage gate." I see a struct with a constructor and three accessors, all marked This isn't a "ship now, test later" situation. You're introducing a public API for a geometry foundation crate. Test it BEFORE merge, not after. Verify that tests for
Run this script to check for tests: BunBun 🏁 Script executed: #!/bin/bash
# Description: Verify unit tests exist for PositionProxy
echo "=== Searching for PositionProxy tests ==="
rg -n --type rust -A 10 '#\[test\]|#\[cfg\(test\)\]' crates/rmg-geom/src/temporal/ | rg -A 10 'PositionProxy|manifold'
echo ""
echo "=== Searching for test modules ==="
fd -e rs test crates/rmg-geom/Length of output: 77 From: Linus Torvalds torvalds@linux-foundation.org Tests promised in PR description? Let's talk about the ZERO tests actually shipped. I ran the verification script. The results are crystal clear: no test blocks exist anywhere in You've got a public API here—a constructor and three accessors for a geometry foundation crate—and you're trying to merge it naked. No tests. No coverage. No validation that Fix this before I look at this PR again:
This is non-negotiable for a geometry foundation crate. Ship the tests with this PR or don't ship this PR. BunBun 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| //! Temporal types and helpers used for tick-based motion and broad-phase. | ||
|
|
||
| #[doc = "Broad-phase proxy carrying entity id, tick, and fat AABB."] | ||
| pub mod manifold; | ||
| #[doc = "Discrete Chronos ticks (u64 newtype)."] | ||
| pub mod tick; | ||
| #[doc = "Start/end transforms over a tick and fat AABB computation."] | ||
| pub mod timespan; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Discrete simulation tick in Chronos time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// The engine advances in integer ticks with a fixed `dt` per branch. This | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// newtype ensures explicit tick passing across APIs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[repr(transparent)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub struct Tick { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| index: u64, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| impl Tick { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Creates a new tick with the given index. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[must_use] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub const fn new(index: u64) -> Self { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Self { index } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Returns the tick index. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[must_use] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub const fn index(&self) -> u64 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| impl From<u64> for Tick { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn from(value: u64) -> Self { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Self { index: value } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| impl From<Tick> for u64 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn from(t: Tick) -> Self { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial From: Linus Torvalds torvalds@linux-foundation.org You implemented the critical parts from the past review.
Optional ergonomic additions still missing: The past review suggested If you want to add them now: +impl core::fmt::Display for Tick {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ write!(f, "{}", self.index)
+ }
+}
+
impl Tick {
+ /// Zero tick (epoch).
+ pub const ZERO: Self = Self { index: 0 };
+
/// Creates a new tick with the given index.
@@
pub const fn index(&self) -> u64 {
self.index
}
+
+ /// Next tick, saturating on overflow.
+ #[must_use]
+ pub const fn next(self) -> Self {
+ Self { index: self.index.saturating_add(1) }
+ }
}But honestly, the current code is fine for a foundation PR. Add them when you need them. BunBun 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| use crate::types::{aabb::Aabb, transform::Transform}; | ||
|
|
||
| /// Transform at two adjacent ticks used to bound motion in the broad-phase. | ||
| /// | ||
| /// - `start` corresponds to tick `n`. | ||
| /// - `end` corresponds to tick `n+1`. | ||
| /// | ||
| /// Determinism and plan: | ||
| /// - `fat_aabb` below currently uses a union of the start/end AABBs. This is | ||
| /// conservative for linear motion and sufficient for pairing/CCD triggers. | ||
| /// - Future: introduce a quantized margin policy (based on velocity, `dt`, and | ||
| /// shape scale) so that fat proxies are identical across peers/branches. The | ||
| /// policy and quantization will be recorded in the graph/spec. | ||
| #[derive(Debug, Copy, Clone, PartialEq)] | ||
| pub struct Timespan { | ||
| start: Transform, | ||
| end: Transform, | ||
| } | ||
|
|
||
| impl Timespan { | ||
| /// Creates a new `Timespan` from start and end transforms. | ||
| #[must_use] | ||
| pub const fn new(start: Transform, end: Transform) -> Self { | ||
| Self { start, end } | ||
| } | ||
|
|
||
| /// Returns the start transform. | ||
| #[must_use] | ||
| pub const fn start(&self) -> Transform { | ||
| self.start | ||
| } | ||
|
|
||
| /// Returns the end transform. | ||
| #[must_use] | ||
| pub const fn end(&self) -> Transform { | ||
| self.end | ||
| } | ||
|
|
||
| /// Computes a conservative fat AABB for a collider with local-space `shape` AABB. | ||
| /// | ||
| /// The fat box is defined as the union of the shape’s AABBs at the start and | ||
| /// end transforms. This is conservative for linear motion and suffices for | ||
| /// broad-phase pairing and CCD triggering. | ||
| #[must_use] | ||
| pub fn fat_aabb(&self, shape: &Aabb) -> Aabb { | ||
| let a0 = shape.transformed(&self.start.to_mat4()); | ||
| let a1 = shape.transformed(&self.end.to_mat4()); | ||
| a0.union(&a1) | ||
| } | ||
flyingrobots marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From: Linus Torvalds torvalds@linux-foundation.org
To: flyingrobots flyingrobots@users.noreply.github.com
Cc: code-rabbit@vger.kernel.org
Subject: [PATCH] pre-commit: auto-format restaging logic is sloppy
Good: You fixed the
git add -Acatastrophe.Bad: Your restaging logic is still wrong.
Line 59 captures the list of staged files before checking whether
cargo fmtactually touched them. Then line 61 blindly re-adds all of them.If
cargo fmtdidn't change a file (already formatted), you're doing pointless re-staging work. More importantly, you're not verifying that the working tree actually differs from the index post-format.Here's what you should do:
if [[ "${_auto_fmt}" == "1" ]]; then echo "pre-commit: ECHO_AUTO_FMT=${_auto_fmt} → running cargo fmt (auto-fix)" cargo fmt --all || { echo "pre-commit: cargo fmt failed" >&2; exit 1; } - # Re-stage only staged files that were reformatted - if STAGED=$(git diff --cached --name-only); then - if [[ -n "$STAGED" ]]; then - echo "$STAGED" | xargs -r git add -- - fi - fi + # Re-stage only files that were both staged AND modified by fmt + git diff --cached --name-only | while IFS= read -r file; do + if git diff --quiet -- "$file" 2>/dev/null; then + : # File wasn't changed by fmt, skip + else + git add -- "$file" + fi + doneOr simpler (if you trust
git addto be idempotent on unchanged files, which it is):The
--diff-filter=Mensures you only re-stage files that were actually modified, not added/deleted/etc.Also, minor nit: your case patterns on lines 55 and 65 accept
TRUEandYESbut real shell idiom is lowercase. Nobody setsECHO_AUTO_FMT=TRUEin practice. You're overthinking it. Just accept1|true|yesand0|false|no.BunBun
📝 Committable suggestion
🤖 Prompt for AI Agents