From 7b935c424b90476eb2dae0fcfbdbbd7ffd5bfa54 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Wed, 13 Nov 2024 14:09:17 +0000 Subject: [PATCH] Trivial `bevy_picking` refactor (#16374) # Objective Remove the rebinding and use `Rect::contains` in `bevy_picking::pointer::Location::is_in_viewport`. --- crates/bevy_picking/src/pointer.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/bevy_picking/src/pointer.rs b/crates/bevy_picking/src/pointer.rs index 23f544699a..fd7ec7b1ea 100644 --- a/crates/bevy_picking/src/pointer.rs +++ b/crates/bevy_picking/src/pointer.rs @@ -9,7 +9,7 @@ //! driven by lower-level input devices and consumed by higher-level interaction systems. use bevy_ecs::prelude::*; -use bevy_math::{Rect, Vec2}; +use bevy_math::Vec2; use bevy_reflect::prelude::*; use bevy_render::camera::{Camera, NormalizedRenderTarget}; use bevy_utils::HashMap; @@ -233,13 +233,9 @@ impl Location { return false; } - let position = Vec2::new(self.position.x, self.position.y); - camera .logical_viewport_rect() - .map(|Rect { min, max }| { - (position - min).min_element() >= 0.0 && (position - max).max_element() <= 0.0 - }) + .map(|rect| rect.contains(self.position)) .unwrap_or(false) } }