Skip to content

Commit

Permalink
Changed (Vec2, Vec2) to Rect in Camera::logical_viewport_rect (#7867)
Browse files Browse the repository at this point in the history
# 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);
}
```
  • Loading branch information
s-lambert committed Apr 24, 2023
1 parent b5d24d8 commit 288009a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bevy_ecs::{
system::{Commands, Query, Res, ResMut, Resource},
};
use bevy_log::warn;
use bevy_math::{Mat4, Ray, UVec2, UVec4, Vec2, Vec3};
use bevy_math::{Mat4, Ray, Rect, UVec2, UVec4, Vec2, Vec3};
use bevy_reflect::prelude::*;
use bevy_reflect::FromReflect;
use bevy_transform::components::GlobalTransform;
Expand Down Expand Up @@ -156,13 +156,16 @@ impl Camera {
Some((min, max))
}

/// The rendered logical bounds (minimum, maximum) of the camera. If the `viewport` field is set
/// to [`Some`], this will be the rect of that custom viewport. Otherwise it will default to the
/// The rendered logical bounds [`Rect`] of the camera. If the `viewport` field is set to
/// [`Some`], this will be the rect of that custom viewport. Otherwise it will default to the
/// full logical rect of the current [`RenderTarget`].
#[inline]
pub fn logical_viewport_rect(&self) -> Option<(Vec2, Vec2)> {
pub fn logical_viewport_rect(&self) -> Option<Rect> {
let (min, max) = self.physical_viewport_rect()?;
Some((self.to_logical(min)?, self.to_logical(max)?))
Some(Rect {
min: self.to_logical(min)?,
max: self.to_logical(max)?,
})
}

/// The logical size of this camera's viewport. If the `viewport` field is set to [`Some`], this
Expand Down

0 comments on commit 288009a

Please sign in to comment.