1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Replace emath::clamp with f32::clamp (new in rustc 1.50)

This commit is contained in:
Emil Ernerfeldt
2021-03-21 17:47:03 +01:00
parent cdab9d777f
commit f5c372910c
16 changed files with 66 additions and 63 deletions

View File

@@ -159,6 +159,7 @@ where
/// Returns `range.start()` if `x <= range.start()`,
/// returns `range.end()` if `x >= range.end()`
/// and returns `x` elsewhen.
#[deprecated = "Use f32::clamp instead"]
pub fn clamp<T>(x: T, range: RangeInclusive<T>) -> T
where
T: Copy + PartialOrd,

View File

@@ -1,4 +1,4 @@
use std::ops::{Add, AddAssign, RangeInclusive, Sub, SubAssign};
use std::ops::{Add, AddAssign, Sub, SubAssign};
use crate::*;
@@ -143,10 +143,10 @@ impl Pos2 {
}
#[must_use]
pub fn clamp(self, range: RangeInclusive<Self>) -> Self {
pub fn clamp(self, min: Self, max: Self) -> Self {
Self {
x: clamp(self.x, range.start().x..=range.end().x),
y: clamp(self.y, range.start().y..=range.end().y),
x: self.x.clamp(min.x, max.x),
y: self.y.clamp(min.y, max.y),
}
}
}

View File

@@ -204,11 +204,10 @@ impl Rect {
}
/// Return the given points clamped to be inside the rectangle
/// Panics if [`Self::is_negative`].
#[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 clamp(&self, p: Pos2) -> Pos2 {
p.clamp(self.min, self.max)
}
pub fn extend_with(&mut self, p: Pos2) {

View File

@@ -1,11 +1,9 @@
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, RangeInclusive, Sub, SubAssign};
use crate::*;
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign};
/// A vector has a direction and length.
/// A [`Vec2`] is often used to represent a size.
///
/// emath represents positions using [`Pos2`].
/// emath represents positions using [`crate::Pos2`].
///
/// Normally the units are points (logical pixels).
#[derive(Clone, Copy, Default, PartialEq)]
@@ -183,10 +181,10 @@ impl Vec2 {
}
#[must_use]
pub fn clamp(self, range: RangeInclusive<Self>) -> Self {
pub fn clamp(self, min: Self, max: Self) -> Self {
Self {
x: clamp(self.x, range.start().x..=range.end().x),
y: clamp(self.y, range.start().y..=range.end().y),
x: self.x.clamp(min.x, max.x),
y: self.y.clamp(min.y, max.y),
}
}
}