[emath] Add Pos2::zero() and Rect::clamp(point)
This commit is contained in:
parent
33545501f9
commit
d11b02d45e
2 changed files with 15 additions and 0 deletions
|
@ -35,6 +35,13 @@ impl From<&[f32; 2]> for Pos2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pos2 {
|
impl Pos2 {
|
||||||
|
/// The zero position, the origin.
|
||||||
|
/// The top left corner in a GUI.
|
||||||
|
/// Same as `Pos2::default()`.
|
||||||
|
pub const fn zero() -> Self {
|
||||||
|
Self { x: 0.0, y: 0.0 }
|
||||||
|
}
|
||||||
|
|
||||||
pub const fn new(x: f32, y: f32) -> Self {
|
pub const fn new(x: f32, y: f32) -> Self {
|
||||||
Self { x, y }
|
Self { x, y }
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,6 +131,14 @@ impl Rect {
|
||||||
&& p.y <= self.min.y + self.size().y
|
&& p.y <= self.min.y + self.size().y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the given points clamped to be inside the rectangle
|
||||||
|
#[must_use]
|
||||||
|
pub fn clamp(&self, mut p: Pos2) -> Pos2 {
|
||||||
|
p.x = clamp(p.x, self.x_range());
|
||||||
|
p.y = clamp(p.y, self.y_range());
|
||||||
|
p
|
||||||
|
}
|
||||||
|
|
||||||
pub fn extend_with(&mut self, p: Pos2) {
|
pub fn extend_with(&mut self, p: Pos2) {
|
||||||
self.min = self.min.min(p);
|
self.min = self.min.min(p);
|
||||||
self.max = self.max.max(p);
|
self.max = self.max.max(p);
|
||||||
|
|
Loading…
Reference in a new issue