From 288009ab8b22318c7412988447d695c54e1bd19f Mon Sep 17 00:00:00 2001 From: Scott Lambert Date: Mon, 24 Apr 2023 23:24:52 +0800 Subject: [PATCH] Changed (Vec2, Vec2) to Rect in Camera::logical_viewport_rect (#7867) # 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` 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); } ``` --- crates/bevy_render/src/camera/camera.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index ab3af2c2429f0..16bf8ec5e9a49 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -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; @@ -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 { 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