-
Notifications
You must be signed in to change notification settings - Fork 465
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
add ClippingRect #1450
Merged
Merged
add ClippingRect #1450
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6a21843
add ClippingRect type
jagprog5 1367626
add derive
jagprog5 25b61eb
amend previous commit (add eq)
jagprog5 3b87439
cargo fmt
jagprog5 acc5d3b
changelog entry
jagprog5 880632d
improve - settings is now backwards compatible. querying is not
jagprog5 76a697e
drop let binding
jagprog5 e7f0184
fix fmt
jagprog5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use sdl2::{rect::Rect, render::ClippingRect}; | ||
|
||
extern crate sdl2; | ||
|
||
#[test] | ||
fn clipping_rect_intersection() { | ||
// a zero area clipping rect intersecting with anything else gives zero | ||
assert_eq!( | ||
ClippingRect::Zero.intersection(ClippingRect::Zero), | ||
ClippingRect::Zero | ||
); | ||
assert_eq!( | ||
ClippingRect::Zero.intersection(ClippingRect::None), | ||
ClippingRect::Zero | ||
); | ||
assert_eq!( | ||
ClippingRect::Zero.intersection(ClippingRect::Some(Rect::new(0, 0, 1, 1))), | ||
ClippingRect::Zero | ||
); | ||
|
||
// none gives whatever the arg was | ||
assert_eq!( | ||
ClippingRect::None.intersection(ClippingRect::Zero), | ||
ClippingRect::Zero | ||
); | ||
assert_eq!( | ||
ClippingRect::None.intersection(ClippingRect::None), | ||
ClippingRect::None | ||
); | ||
assert_eq!( | ||
ClippingRect::None.intersection(ClippingRect::Some(Rect::new(0, 0, 1, 1))), | ||
ClippingRect::Some(Rect::new(0, 0, 1, 1)) | ||
); | ||
|
||
assert_eq!( | ||
ClippingRect::Some(Rect::new(0, 0, 1, 1)).intersection(ClippingRect::Zero), | ||
ClippingRect::Zero | ||
); | ||
assert_eq!( | ||
ClippingRect::Some(Rect::new(0, 0, 1, 1)).intersection(ClippingRect::None), | ||
ClippingRect::Some(Rect::new(0, 0, 1, 1)) | ||
); | ||
assert_eq!( | ||
ClippingRect::Some(Rect::new(0, 0, 10, 10)) | ||
.intersection(ClippingRect::Some(Rect::new(20, 20, 1, 1))), | ||
ClippingRect::Zero | ||
); | ||
|
||
assert_eq!( | ||
ClippingRect::Some(Rect::new(0, 0, 10, 10)) | ||
.intersection(ClippingRect::Some(Rect::new(5, 5, 10, 10))), | ||
ClippingRect::Some(Rect::new(5, 5, 5, 5)) | ||
); | ||
} | ||
|
||
#[test] | ||
fn clipping_rect_intersect_rect() { | ||
assert_eq!(ClippingRect::Zero.intersect_rect(None), ClippingRect::Zero); | ||
assert_eq!( | ||
ClippingRect::Zero.intersect_rect(Rect::new(0, 0, 1, 1)), | ||
ClippingRect::Zero | ||
); | ||
|
||
assert_eq!(ClippingRect::None.intersect_rect(None), ClippingRect::Zero); | ||
assert_eq!( | ||
ClippingRect::None.intersect_rect(Rect::new(0, 0, 1, 1)), | ||
ClippingRect::Some(Rect::new(0, 0, 1, 1)) | ||
); | ||
|
||
assert_eq!( | ||
ClippingRect::Some(Rect::new(0, 0, 1, 1)).intersect_rect(None), | ||
ClippingRect::Zero | ||
); | ||
assert_eq!( | ||
ClippingRect::Some(Rect::new(0, 0, 10, 10)).intersect_rect(Rect::new(5, 5, 10, 10)), | ||
ClippingRect::Some(Rect::new(5, 5, 5, 5)) | ||
); | ||
assert_eq!( | ||
ClippingRect::Some(Rect::new(0, 0, 10, 10)).intersect_rect(Rect::new(20, 20, 1, 1)), | ||
ClippingRect::Zero | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
binding is unnecessary here, just do
if sys::SDL_bool::SDL_FALSE == clip_enabled {
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.
fails to compileaddressed: 76a697e