-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix check that cursor position is within window bounds #9662
Fix check that cursor position is within window bounds #9662
Conversation
A fix (for the first issue you mentioned) was just merged: #9657 |
Should I open a new PR for the second issue (and close this one)? |
Feel free to modify this PR. Just making sure you know that the code just changed underneath you. |
I modified the commit and the PR description accordingly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like a quick regression test (or a handful of tests) for this :)
Good fix though.
Tests added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
# Objective The recently introduced check that the cursor position returned by `Window::cursor_position()` is within the bounds of the window (bevyengine@3cf94e7) has the following issue: If *w* is the window width, points within the window satisfy the condition 0 ≤ *x* < *w*, but the code assumes the condition 0 ≤ *x* ≤ *w*. In other words, if *x* = *w*, the point is not within the window bounds. Likewise for the height. This program demonstrates the issue: ```rust use bevy::{prelude::*, window::WindowResolution}; fn main() { let mut window = Window { resolution: WindowResolution::new(100.0, 100.0), ..default() }; window.set_cursor_position(Some(Vec2::new(100.0, 0.0))); println!("{:?}", window.cursor_position()); } ``` It prints `Some(Vec2(100.0, 0.0))` instead of the expected `None`. ## Solution - Exclude the upper bound, i.e., the window width for the *x* position and the window height for the *y* position.
Objective
The recently introduced check that the cursor position returned by
Window::cursor_position()
is within the bounds of the window (3cf94e7) has the following issue:If w is the window width, points within the window satisfy the condition 0 ≤ x < w, but the code assumes the condition 0 ≤ x ≤ w. In other words, if x = w, the point is not within the window bounds. Likewise for the height. This program demonstrates the issue:
It prints
Some(Vec2(100.0, 0.0))
instead of the expectedNone
.Solution