Skip to content

Conversation

Breakdown-Dog
Copy link
Contributor

Objective

  • This PR refactors the Frustum struct to improve code readability and maintainability by replacing magic numbers with named constants and unrolling a loop for clarity.

Testing

  • I ran the command 'cargo test --package bevy_camera --lib -- primitives::tests --show-output' and all the test are passed.

Copy link
Contributor

@janis-bhm janis-bhm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes this section much more readable!

let row2 = clip_from_world.row(2);
let row3 = clip_from_world.row(3);

half_spaces[Self::LEFT_PLANE_IDX] = HalfSpace::new(row3 + row0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this section could also be written as a simple array instead of assigning each element individually.
i.e. Self { half_spaces: [HalfSpace::new(row3 + row0), ..] }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you said makes sense. We don't even need to declare a  mut   half_space  in advance and can directly return the value. However, some constants seem a bit redundant—I don't see where these constants are needed externally either.

const NEAR_PLANE_IDX: usize = 4;
const FAR_PLANE_IDX: usize = 5;

const INACTIVE_HALF_SPACE: Vec4 = Vec4::new(0.0, 0.0, 0.0, f32::MAX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied from the original code, but I'm wondering if it's correct to have a halfspace of NaNs here?

Comment on lines 278 to 283
const LEFT_PLANE_IDX: usize = 0;
const RIGHT_PLANE_IDX: usize = 1;
const BOTTOM_PLANE_IDX: usize = 2;
const TOP_PLANE_IDX: usize = 3;
const NEAR_PLANE_IDX: usize = 4;
const FAR_PLANE_IDX: usize = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be pub, since half_spaces is pub as well, and is used outside of this module.

@janis-bhm janis-bhm added D-Trivial Nice and easy! A great choice to get started with Bevy C-Code-Quality A section of code that is hard to understand or change S-Needs-Review Needs reviewer attention (from anyone!) to move forward A-Camera User-facing camera APIs and controllers. labels Oct 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Camera User-facing camera APIs and controllers. C-Code-Quality A section of code that is hard to understand or change D-Trivial Nice and easy! A great choice to get started with Bevy S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants