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

Add a bunch on inline annotations

This commit is contained in:
Emil Ernerfeldt
2021-04-01 22:10:34 +02:00
parent d702e3078a
commit d7f9e2246c
7 changed files with 65 additions and 8 deletions

View File

@@ -111,47 +111,57 @@ impl Pos2 {
}
}
#[inline]
pub fn distance(self, other: Self) -> f32 {
(self - other).length()
}
#[inline]
pub fn distance_sq(self, other: Self) -> f32 {
(self - other).length_sq()
}
#[inline(always)]
pub fn floor(self) -> Self {
pos2(self.x.floor(), self.y.floor())
}
#[inline(always)]
pub fn round(self) -> Self {
pos2(self.x.round(), self.y.round())
}
#[inline(always)]
pub fn ceil(self) -> Self {
pos2(self.x.ceil(), self.y.ceil())
}
/// True if all members are also finite.
#[inline(always)]
pub fn is_finite(self) -> bool {
self.x.is_finite() && self.y.is_finite()
}
/// True if any member is NaN.
#[inline(always)]
pub fn any_nan(self) -> bool {
self.x.is_nan() || self.y.is_nan()
}
#[must_use]
#[inline]
pub fn min(self, other: Self) -> Self {
pos2(self.x.min(other.x), self.y.min(other.y))
}
#[must_use]
#[inline]
pub fn max(self, other: Self) -> Self {
pos2(self.x.max(other.x), self.y.max(other.y))
}
#[must_use]
#[inline]
pub fn clamp(self, min: Self, max: Self) -> Self {
Self {
x: self.x.clamp(min.x, max.x),
@@ -163,6 +173,7 @@ impl Pos2 {
impl std::ops::Index<usize> for Pos2 {
type Output = f32;
#[inline(always)]
fn index(&self, index: usize) -> &f32 {
match index {
0 => &self.x,
@@ -173,6 +184,7 @@ impl std::ops::Index<usize> for Pos2 {
}
impl std::ops::IndexMut<usize> for Pos2 {
#[inline(always)]
fn index_mut(&mut self, index: usize) -> &mut f32 {
match index {
0 => &mut self.x,

View File

@@ -149,53 +149,63 @@ impl Vec2 {
}
#[must_use]
#[inline(always)]
pub fn floor(self) -> Self {
vec2(self.x.floor(), self.y.floor())
}
#[must_use]
#[inline(always)]
pub fn round(self) -> Self {
vec2(self.x.round(), self.y.round())
}
#[must_use]
#[inline(always)]
pub fn ceil(self) -> Self {
vec2(self.x.ceil(), self.y.ceil())
}
/// True if all members are also finite.
#[inline(always)]
pub fn is_finite(self) -> bool {
self.x.is_finite() && self.y.is_finite()
}
/// True if any member is NaN.
#[inline(always)]
pub fn any_nan(self) -> bool {
self.x.is_nan() || self.y.is_nan()
}
#[must_use]
#[inline]
pub fn min(self, other: Self) -> Self {
vec2(self.x.min(other.x), self.y.min(other.y))
}
#[must_use]
#[inline]
pub fn max(self, other: Self) -> Self {
vec2(self.x.max(other.x), self.y.max(other.y))
}
/// Returns the minimum of `self.x` and `self.y`.
#[must_use]
#[inline(always)]
pub fn min_elem(self) -> f32 {
self.x.min(self.y)
}
/// Returns the maximum of `self.x` and `self.y`.
#[inline(always)]
#[must_use]
pub fn max_elem(self) -> f32 {
self.x.max(self.y)
}
#[must_use]
#[inline]
pub fn clamp(self, min: Self, max: Self) -> Self {
Self {
x: self.x.clamp(min.x, max.x),
@@ -207,6 +217,7 @@ impl Vec2 {
impl std::ops::Index<usize> for Vec2 {
type Output = f32;
#[inline(always)]
fn index(&self, index: usize) -> &f32 {
match index {
0 => &self.x,
@@ -217,6 +228,7 @@ impl std::ops::Index<usize> for Vec2 {
}
impl std::ops::IndexMut<usize> for Vec2 {
#[inline(always)]
fn index_mut(&mut self, index: usize) -> &mut f32 {
match index {
0 => &mut self.x,