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

Use Self everywhere (#3787)

This turns on the clippy lint
[`clippy::use_self`](https://rust-lang.github.io/rust-clippy/v0.0.212/index.html#use_self)
and fixes it everywhere.
This commit is contained in:
Emil Ernerfeldt
2024-01-08 17:41:21 +01:00
committed by GitHub
parent 12ad9e7b36
commit 401de05630
72 changed files with 590 additions and 580 deletions

View File

@@ -70,13 +70,13 @@ impl Rect {
#[inline(always)]
pub const fn from_min_max(min: Pos2, max: Pos2) -> Self {
Rect { min, max }
Self { min, max }
}
/// left-top corner plus a size (stretching right-down).
#[inline(always)]
pub fn from_min_size(min: Pos2, size: Vec2) -> Self {
Rect {
Self {
min,
max: min + size,
}
@@ -84,7 +84,7 @@ impl Rect {
#[inline(always)]
pub fn from_center_size(center: Pos2, size: Vec2) -> Self {
Rect {
Self {
min: center - size * 0.5,
max: center + size * 0.5,
}
@@ -94,7 +94,7 @@ impl Rect {
pub fn from_x_y_ranges(x_range: impl Into<Rangef>, y_range: impl Into<Rangef>) -> Self {
let x_range = x_range.into();
let y_range = y_range.into();
Rect {
Self {
min: pos2(x_range.min, y_range.min),
max: pos2(x_range.max, y_range.max),
}
@@ -103,7 +103,7 @@ impl Rect {
/// Returns the bounding rectangle of the two points.
#[inline]
pub fn from_two_pos(a: Pos2, b: Pos2) -> Self {
Rect {
Self {
min: pos2(a.x.min(b.x), a.y.min(b.y)),
max: pos2(a.x.max(b.x), a.y.max(b.y)),
}
@@ -111,7 +111,7 @@ impl Rect {
/// Bounding-box around the points.
pub fn from_points(points: &[Pos2]) -> Self {
let mut rect = Rect::NOTHING;
let mut rect = Self::NOTHING;
for &p in points {
rect.extend_with(p);
}
@@ -187,7 +187,7 @@ impl Rect {
/// Expand by this much in each direction, keeping the center
#[must_use]
pub fn expand2(self, amnt: Vec2) -> Self {
Rect::from_min_max(self.min - amnt, self.max + amnt)
Self::from_min_max(self.min - amnt, self.max + amnt)
}
/// Shrink by this much in each direction, keeping the center
@@ -199,13 +199,13 @@ impl Rect {
/// Shrink by this much in each direction, keeping the center
#[must_use]
pub fn shrink2(self, amnt: Vec2) -> Self {
Rect::from_min_max(self.min + amnt, self.max - amnt)
Self::from_min_max(self.min + amnt, self.max - amnt)
}
#[must_use]
#[inline]
pub fn translate(self, amnt: Vec2) -> Self {
Rect::from_min_size(self.min + amnt, self.size())
Self::from_min_size(self.min + amnt, self.size())
}
/// Rotate the bounds (will expand the [`Rect`])
@@ -225,7 +225,7 @@ impl Rect {
#[must_use]
#[inline]
pub fn intersects(self, other: Rect) -> bool {
pub fn intersects(self, other: Self) -> bool {
self.min.x <= other.max.x
&& other.min.x <= self.max.x
&& self.min.y <= other.max.y
@@ -254,7 +254,7 @@ impl Rect {
}
#[must_use]
pub fn contains_rect(&self, other: Rect) -> bool {
pub fn contains_rect(&self, other: Self) -> bool {
self.contains(other.min) && self.contains(other.max)
}
@@ -289,8 +289,8 @@ impl Rect {
/// that contains both input rectangles.
#[inline(always)]
#[must_use]
pub fn union(self, other: Rect) -> Rect {
Rect {
pub fn union(self, other: Self) -> Self {
Self {
min: self.min.min(other.min),
max: self.max.max(other.max),
}
@@ -299,7 +299,7 @@ impl Rect {
/// The intersection of two [`Rect`], i.e. the area covered by both.
#[inline]
#[must_use]
pub fn intersect(self, other: Rect) -> Self {
pub fn intersect(self, other: Self) -> Self {
Self {
min: self.min.max(other.min),
max: self.max.min(other.max),
@@ -419,7 +419,7 @@ impl Rect {
/// Linearly self towards other rect.
#[inline]
pub fn lerp_towards(&self, other: &Rect, t: f32) -> Self {
pub fn lerp_towards(&self, other: &Self, t: f32) -> Self {
Self {
min: self.min.lerp(other.min, t),
max: self.max.lerp(other.max, t),
@@ -581,26 +581,26 @@ impl Rect {
}
/// Split rectangle in left and right halves. `t` is expected to be in the (0,1) range.
pub fn split_left_right_at_fraction(&self, t: f32) -> (Rect, Rect) {
pub fn split_left_right_at_fraction(&self, t: f32) -> (Self, Self) {
self.split_left_right_at_x(lerp(self.min.x..=self.max.x, t))
}
/// Split rectangle in left and right halves at the given `x` coordinate.
pub fn split_left_right_at_x(&self, split_x: f32) -> (Rect, Rect) {
let left = Rect::from_min_max(self.min, Pos2::new(split_x, self.max.y));
let right = Rect::from_min_max(Pos2::new(split_x, self.min.y), self.max);
pub fn split_left_right_at_x(&self, split_x: f32) -> (Self, Self) {
let left = Self::from_min_max(self.min, Pos2::new(split_x, self.max.y));
let right = Self::from_min_max(Pos2::new(split_x, self.min.y), self.max);
(left, right)
}
/// Split rectangle in top and bottom halves. `t` is expected to be in the (0,1) range.
pub fn split_top_bottom_at_fraction(&self, t: f32) -> (Rect, Rect) {
pub fn split_top_bottom_at_fraction(&self, t: f32) -> (Self, Self) {
self.split_top_bottom_at_y(lerp(self.min.y..=self.max.y, t))
}
/// Split rectangle in top and bottom halves at the given `y` coordinate.
pub fn split_top_bottom_at_y(&self, split_y: f32) -> (Rect, Rect) {
let top = Rect::from_min_max(self.min, Pos2::new(self.max.x, split_y));
let bottom = Rect::from_min_max(Pos2::new(self.min.x, split_y), self.max);
pub fn split_top_bottom_at_y(&self, split_y: f32) -> (Self, Self) {
let top = Self::from_min_max(self.min, Pos2::new(self.max.x, split_y));
let bottom = Self::from_min_max(Pos2::new(self.min.x, split_y), self.max);
(top, bottom)
}
}
@@ -620,11 +620,11 @@ impl From<[Pos2; 2]> for Rect {
}
impl Mul<f32> for Rect {
type Output = Rect;
type Output = Self;
#[inline]
fn mul(self, factor: f32) -> Rect {
Rect {
fn mul(self, factor: f32) -> Self {
Self {
min: self.min * factor,
max: self.max * factor,
}
@@ -644,11 +644,11 @@ impl Mul<Rect> for f32 {
}
impl Div<f32> for Rect {
type Output = Rect;
type Output = Self;
#[inline]
fn div(self, factor: f32) -> Rect {
Rect {
fn div(self, factor: f32) -> Self {
Self {
min: self.min / factor,
max: self.max / factor,
}