Skip to content

Commit 7154b59

Browse files
authored
Return URect instead of (UVec2, UVec2) in Camera::physical_viewport_rect (#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); } ```
1 parent 7345766 commit 7154b59

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

crates/bevy_core_pipeline/src/bloom/settings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::downsampling_pipeline::BloomUniforms;
22
use bevy_ecs::{prelude::Component, query::QueryItem, reflect::ReflectComponent};
3-
use bevy_math::{UVec4, Vec4};
3+
use bevy_math::{URect, UVec4, Vec4};
44
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
55
use bevy_render::{extract_component::ExtractComponent, prelude::Camera};
66

@@ -196,7 +196,7 @@ impl ExtractComponent for BloomSettings {
196196
camera.is_active,
197197
camera.hdr,
198198
) {
199-
(Some((origin, _)), Some(size), Some(target_size), true, true) => {
199+
(Some(URect { min: origin, .. }), Some(size), Some(target_size), true, true) => {
200200
let threshold = settings.prefilter_settings.threshold;
201201
let threshold_softness = settings.prefilter_settings.threshold_softness;
202202
let knee = threshold * threshold_softness.clamp(0.0, 1.0);

crates/bevy_math/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub mod prelude {
1919
#[doc(hidden)]
2020
pub use crate::{
2121
cubic_splines::{BSpline, Bezier, CardinalSpline, CubicGenerator, CubicSegment, Hermite},
22-
BVec2, BVec3, BVec4, EulerRot, IVec2, IVec3, IVec4, Mat2, Mat3, Mat4, Quat, Ray, Rect,
23-
UVec2, UVec3, UVec4, Vec2, Vec3, Vec4,
22+
BVec2, BVec3, BVec4, EulerRot, IRect, IVec2, IVec3, IVec4, Mat2, Mat3, Mat4, Quat, Ray,
23+
Rect, URect, UVec2, UVec3, UVec4, Vec2, Vec3, Vec4,
2424
};
2525
}
2626

crates/bevy_render/src/camera/camera.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use bevy_ecs::{
1919
system::{Commands, Query, Res, ResMut, Resource},
2020
};
2121
use bevy_log::warn;
22-
use bevy_math::{Mat4, Ray, Rect, UVec2, UVec4, Vec2, Vec3};
22+
use bevy_math::{Mat4, Ray, Rect, URect, UVec2, UVec4, Vec2, Vec3};
2323
use bevy_reflect::prelude::*;
2424
use bevy_transform::components::GlobalTransform;
2525
use bevy_utils::{HashMap, HashSet};
@@ -138,26 +138,26 @@ impl Camera {
138138
Some((physical_size.as_dvec2() / scale).as_vec2())
139139
}
140140

141-
/// The rendered physical bounds (minimum, maximum) of the camera. If the `viewport` field is
141+
/// The rendered physical bounds [`URect`] of the camera. If the `viewport` field is
142142
/// set to [`Some`], this will be the rect of that custom viewport. Otherwise it will default to
143143
/// the full physical rect of the current [`RenderTarget`].
144144
#[inline]
145-
pub fn physical_viewport_rect(&self) -> Option<(UVec2, UVec2)> {
145+
pub fn physical_viewport_rect(&self) -> Option<URect> {
146146
let min = self
147147
.viewport
148148
.as_ref()
149149
.map(|v| v.physical_position)
150150
.unwrap_or(UVec2::ZERO);
151151
let max = min + self.physical_viewport_size()?;
152-
Some((min, max))
152+
Some(URect { min, max })
153153
}
154154

155155
/// The rendered logical bounds [`Rect`] of the camera. If the `viewport` field is set to
156156
/// [`Some`], this will be the rect of that custom viewport. Otherwise it will default to the
157157
/// full logical rect of the current [`RenderTarget`].
158158
#[inline]
159159
pub fn logical_viewport_rect(&self) -> Option<Rect> {
160-
let (min, max) = self.physical_viewport_rect()?;
160+
let URect { min, max } = self.physical_viewport_rect()?;
161161
Some(Rect {
162162
min: self.to_logical(min)?,
163163
max: self.to_logical(max)?,
@@ -636,7 +636,14 @@ pub fn extract_cameras(
636636
continue;
637637
}
638638

639-
if let (Some((viewport_origin, _)), Some(viewport_size), Some(target_size)) = (
639+
if let (
640+
Some(URect {
641+
min: viewport_origin,
642+
..
643+
}),
644+
Some(viewport_size),
645+
Some(target_size),
646+
) = (
640647
camera.physical_viewport_rect(),
641648
camera.physical_viewport_size(),
642649
camera.physical_target_size(),

crates/bevy_ui/src/render/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
use bevy_app::prelude::*;
1717
use bevy_asset::{load_internal_asset, AssetEvent, Assets, Handle, HandleUntyped};
1818
use bevy_ecs::prelude::*;
19-
use bevy_math::{Mat4, Rect, UVec4, Vec2, Vec3, Vec4Swizzles};
19+
use bevy_math::{Mat4, Rect, URect, UVec4, Vec2, Vec3, Vec4Swizzles};
2020
use bevy_reflect::TypeUuid;
2121
use bevy_render::texture::DEFAULT_IMAGE_HANDLE;
2222
use bevy_render::{
@@ -453,7 +453,14 @@ pub fn extract_default_ui_camera_view<T: Component>(
453453
if matches!(camera_ui, Some(&UiCameraConfig { show_ui: false, .. })) {
454454
continue;
455455
}
456-
if let (Some(logical_size), Some((physical_origin, _)), Some(physical_size)) = (
456+
if let (
457+
Some(logical_size),
458+
Some(URect {
459+
min: physical_origin,
460+
..
461+
}),
462+
Some(physical_size),
463+
) = (
457464
camera.logical_viewport_size(),
458465
camera.physical_viewport_rect(),
459466
camera.physical_viewport_size(),

0 commit comments

Comments
 (0)