Skip to content

Commit de28fd0

Browse files
committed
Further cleanup
1 parent f45bb7d commit de28fd0

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

crates/bevy_render/src/camera/camera.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,28 @@ impl Camera {
111111
Some((input.as_dvec2() / scale).as_vec2())
112112
}
113113

114-
/// The logical dimensions of the viewport, the (minimum, maximum) points of the viewport,
115-
/// measured from the top-left.
114+
/// The rendered physical bounds (minimum, maximum) of the camera. If the `viewport` field is
115+
/// set to [`Some`], this will be the rect of that custom viewport. Otherwise it will default to
116+
/// the full physical rect of the current [`RenderTarget`].
116117
#[inline]
117-
pub fn logical_viewport_rect(&self) -> Option<(Vec2, Vec2)> {
118-
let vp_position = self.viewport.as_ref()?.physical_position;
119-
let min = self.physical_to_logical(vp_position)?;
120-
let max = self.logical_viewport_size()?;
118+
pub fn physical_viewport_rect(&self) -> Option<(UVec2, UVec2)> {
119+
let min = self.viewport.as_ref()?.physical_position;
120+
let max = min + self.physical_viewport_size()?;
121121
Some((min, max))
122122
}
123123

124+
/// The rendered logical bounds (minimum, maximum) of the camera. If the `viewport` field is set
125+
/// to [`Some`], this will be the rect of that custom viewport. Otherwise it will default to the
126+
/// full logical rect of the current [`RenderTarget`].
127+
#[inline]
128+
pub fn logical_viewport_rect(&self) -> Option<(Vec2, Vec2)> {
129+
let (min, max) = self.physical_viewport_rect()?;
130+
Some((
131+
self.physical_to_logical(min)?,
132+
self.physical_to_logical(max)?,
133+
))
134+
}
135+
124136
/// The logical size of this camera's viewport. If the `viewport` field is set to [`Some`], this
125137
/// will be the size of that custom viewport. Otherwise it will default to the full logical size
126138
/// of the current [`RenderTarget`].
@@ -130,8 +142,7 @@ impl Camera {
130142
pub fn logical_viewport_size(&self) -> Option<Vec2> {
131143
self.viewport
132144
.as_ref()
133-
.map(|v| self.physical_to_logical(v.physical_size))
134-
.flatten()
145+
.and_then(|v| self.physical_to_logical(v.physical_size))
135146
.or_else(|| self.logical_target_size())
136147
}
137148

@@ -155,8 +166,7 @@ impl Camera {
155166
self.computed
156167
.target_info
157168
.as_ref()
158-
.map(|t| self.physical_to_logical(t.physical_size))
159-
.flatten()
169+
.and_then(|t| self.physical_to_logical(t.physical_size))
160170
}
161171

162172
/// The full physical size of this camera's [`RenderTarget`], ignoring custom `viewport` configuration.

0 commit comments

Comments
 (0)