Skip to content

Comments

Fix divide by zero warning in LidarObservation#661

Open
dhruvildarji wants to merge 1 commit intoFarama-Foundation:masterfrom
dhruvildarji:fix/lidar-divide-by-zero
Open

Fix divide by zero warning in LidarObservation#661
dhruvildarji wants to merge 1 commit intoFarama-Foundation:masterfrom
dhruvildarji:fix/lidar-divide-by-zero

Conversation

@dhruvildarji
Copy link

Summary

  • Fix RuntimeWarning: divide by zero encountered in scalar divide in distance_to_rect() used by LidarObservation
  • Replace the insufficient eps = 1e-6 offset with np.errstate(divide="ignore", invalid="ignore") to properly suppress the warning
  • When the denominator is zero (ray parallel to rectangle edge), the resulting inf values correctly cause the interval intersection check to fail, returning np.inf (no intersection) — preserving existing mathematical behavior

Test plan

  • Verified the lidar observation code path no longer produces RuntimeWarning: divide by zero encountered in scalar divide
  • The fix is behavior-preserving: when denominator is zero, the function still correctly returns np.inf

Fixes #655

Replace the epsilon-based workaround in `distance_to_rect` with
`np.errstate(divide="ignore", invalid="ignore")` to properly suppress
the RuntimeWarning. The previous `eps = 1e-6` offset was insufficient
because `(q - r) @ v` could equal exactly `-eps`, still producing a
zero denominator.

When the denominator is zero the ray is parallel to that rectangle
edge, so the resulting inf values correctly cause the interval check
to fail and return `np.inf` (no intersection).

Fixes Farama-Foundation#655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LidarObservation Warning - divide by zero

1 participant