mirror of
https://github.com/flame-engine/flame.git
synced 2026-03-13 09:43:03 +08:00
`raytrace()` reuses the same `RaycastResult` objects across bounces, so the reflected direction from one bounce becomes the incident direction for the next. `Vector2.reflect()` is not bit-exact, so each bounce introduces a tiny floating-point rounding error. After enough bounces the direction's length drifts just past the `1e-6` tolerance that `Ray2` enforces, causing a `direction must be normalized` assertion crash. Two fixes: - **`CircleHitbox`** and **`PolygonRayIntersection`** (used by `RectangleHitbox` / `PolygonHitbox`): call `normalize()` on the reflected direction before passing it to `Ray2`, so drift is corrected on every bounce. - **`raytrace_example`**: the initial ray direction was set via a cascade on the `Vector2` getter (`ray.direction..setValues(...)`), which bypasses the `direction=` setter and leaves the cached inverse values stale. Fixed to assign through the setter. Regression tests are included that inject a direction whose length² is already above the threshold (by writing directly to the underlying `Vector2`, bypassing the setter), then assert that `raycast()` does not throw. --------- Co-authored-by: Lukas Klingsbo <me@lukas.fyi>