-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87e1f5a
commit cc077ff
Showing
4 changed files
with
221 additions
and
160 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use super::{Point, Size}; | ||
|
||
#[derive(Default, Clone, Copy)] | ||
pub struct Bbox { | ||
pub pos: Point<f32>, | ||
pub size: Size<f32>, | ||
} | ||
|
||
impl Bbox { | ||
pub fn new(pos: Point<f32>, size: Size<f32>) -> Self { | ||
Self { pos, size } | ||
} | ||
|
||
pub fn contains(&self, px: f32, py: f32) -> bool { | ||
let Point { x, y } = self.pos; | ||
let Size { w, h } = self.size; | ||
|
||
(x..(x + w)).contains(&px) && (y..(y + h)).contains(&py) | ||
} | ||
|
||
pub fn x(&self) -> f32 { | ||
self.pos.x | ||
} | ||
|
||
pub fn y(&self) -> f32 { | ||
self.pos.y | ||
} | ||
|
||
pub fn w(&self) -> f32 { | ||
self.size.w | ||
} | ||
|
||
pub fn h(&self) -> f32 { | ||
self.size.h | ||
} | ||
} |
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
Oops, something went wrong.