Skip to content
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

Changed (Vec2, Vec2) to Rect in Camera::logical_viewport_rect #7867

Merged
merged 1 commit into from
Apr 24, 2023
Merged

Changed (Vec2, Vec2) to Rect in Camera::logical_viewport_rect #7867

merged 1 commit into from
Apr 24, 2023

Conversation

s-lambert
Copy link
Contributor

Objective

Camera::logical_viewport_rect() returns Option<(Vec2, Vec2)> which is a tuple of vectors representing the (min, max) bounds of the viewport rect. Since the function says it returns a rect and there is a Rect { min, max } struct in bevy_math, using the struct will be clearer.

Solution

Replaced Option<(Vec2, Vec2)> with Option<Rect> for Camera::logical_viewport_rect().


Changelog

  • Changed Camera::logical_viewport_rect return type from (Vec2, Vec2) to Rect

Migration Guide

Before:

fn view_logical_camera_rect(camera_query: Query<&Camera>) {
    let camera = camera_query.single();
    let Some((min, max)) = camera.logical_viewport_rect() else { return };
    dbg!(min, max);
}

After:

fn view_logical_camera_rect(camera_query: Query<&Camera>) {
    let camera = camera_query.single();
    let Some(Rect { min, max }) = camera.logical_viewport_rect() else { return };
    dbg!(min, max);
}

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2023

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@james7132 james7132 added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Mar 2, 2023
@james7132 james7132 added this to the 0.11 milestone Mar 2, 2023
@mockersf
Copy link
Member

mockersf commented Mar 2, 2023

Could you also change physical_viewport_rect?

@s-lambert
Copy link
Contributor Author

s-lambert commented Mar 2, 2023

Could you also change physical_viewport_rect?

I had a look at that but since there's no Rect equivalent for UVec2 I wasn't confident in changing it. I'm not sure where to put the URect struct too, this is the only place that uses a (UVec2, UVec2).

@james7132
Copy link
Member

I had a look at that but since there's no Rect equivalent for UVec2 I wasn't confident in changing it. I'm not sure where to put the URect struct too, this is the only place that uses a (UVec2, UVec2).

Seems like a good case for a URect type of some kind. Not going to block on this though.

@Weibye Weibye added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Apr 6, 2023
@alice-i-cecile
Copy link
Member

@s-lambert CI seems to be failing to detect the right settings. Can you please rebase your PR or merge main into your branch?

@s-lambert
Copy link
Contributor Author

@s-lambert CI seems to be failing to detect the right settings. Can you please rebase your PR or merge main into your branch?

Done 👍, rebased on latest main.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 24, 2023
Merged via the queue into bevyengine:main with commit 288009a Apr 24, 2023
@s-lambert s-lambert deleted the use-rect-instead-of-tuple branch April 25, 2023 05:10
github-merge-queue bot pushed a commit that referenced this pull request Jul 15, 2023
…ect (#9085)

# Objective

Continue #7867 now that we have URect #7984
- Return `URect` instead of `(UVec2, UVec2)` in
`Camera::physical_viewport_rect`
 - Add `URect` and `IRect` to prelude

## Changelog

- Changed `Camera::physical_viewport_rect` return type from `(UVec2,
UVec2)` to `URect`
- `URect` and `IRect` were added to prelude

## Migration Guide

Before:

```rust
fn view_physical_camera_rect(camera_query: Query<&Camera>) {
    let camera = camera_query.single();
    let Some((min, max)) = camera.physical_viewport_rect() else { return };
    dbg!(min, max);
}
```

After:

```rust
fn view_physical_camera_rect(camera_query: Query<&Camera>) {
    let camera = camera_query.single();
    let Some(URect { min, max }) = camera.physical_viewport_rect() else { return };
    dbg!(min, max);
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants