-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I stumbled on this while toying with the `vello` rendering engine (which is great btw, you guys are doing god's work). I'm trying to create a simple audio sequencer with it and while trying to determine whether shapes were visible on screen, I found that there was no way of checking for the intersection of two `Rect`s. Right now, the only way to do that is to compute their intersection, then verify whether it's empty or not. ```Rust let rect1 = Rect::new(0.0, 0.0, 10.0, 10.0); let rect2 = Rect::new(5.0, 5.0, 15.0, 15.0); assert!(!rect1.intersect(rect2).is_empty()); ``` This is not ideal for two reasons: 1. It's not very ergonomic. Checking whether two rectangles overlap should probably not involve that intermediary step. 2. This is doing a bunch of wasted work to find out what the intersection is when we only care about whether it's empty or not. This pull request adds `Rect::overlaps` and `Rect::contains_rect`, which do exactly that. ```Rust let rect1 = Rect::new(0.0, 0.0, 10.0, 10.0); let rect2 = Rect::new(5.0, 5.0, 15.0, 15.0); assert!(rect1.overlaps(rect2)); assert!(!rect1.contains_rect(rect2)); ```
- Loading branch information
1 parent
106317e
commit a568ab2
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters