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

Use impl Into<Stroke> as argument in a few more places (#3420)

* Functions that take Stroke were updated to take Into<Stroke> to make
them consistent with other Into<Stroke> parameters.
* Vec2 implements DivAssign<f32>, to make it consistent with already
implementing MulAssign<f32> and Div<f32>.
* Vec2::angled() uses sin_cos() rather than an individual sin() and
cos() call for an immeasurable but hypothetical performance improvement.
* Disable the lock_reentry_single_thread() mutex test. Lock()ing twice
on the same thread is not guaranteed to panic.

* Closes <https://github.com/emilk/egui/issues/3419>.
This commit is contained in:
Phen-Ro
2023-11-10 15:36:51 -05:00
committed by GitHub
parent 5201c04512
commit 5f4046d68a
6 changed files with 44 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign};
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
/// A vector has a direction and length.
/// A [`Vec2`] is often used to represent a size.
@@ -203,7 +203,8 @@ impl Vec2 {
/// ```
#[inline(always)]
pub fn angled(angle: f32) -> Self {
vec2(angle.cos(), angle.sin())
let (sin, cos) = angle.sin_cos();
vec2(cos, sin)
}
#[must_use]
@@ -407,6 +408,14 @@ impl MulAssign<f32> for Vec2 {
}
}
impl DivAssign<f32> for Vec2 {
#[inline(always)]
fn div_assign(&mut self, rhs: f32) {
self.x /= rhs;
self.y /= rhs;
}
}
impl Mul<f32> for Vec2 {
type Output = Vec2;
@@ -470,4 +479,20 @@ fn test_vec2() {
assert_eq!(Vec2::DOWN.angle(), 0.25 * TAU);
almost_eq!(Vec2::LEFT.angle(), 0.50 * TAU);
assert_eq!(Vec2::UP.angle(), -0.25 * TAU);
let mut assignment = vec2(1.0, 2.0);
assignment += vec2(3.0, 4.0);
assert_eq!(assignment, vec2(4.0, 6.0));
let mut assignment = vec2(4.0, 6.0);
assignment -= vec2(1.0, 2.0);
assert_eq!(assignment, vec2(3.0, 4.0));
let mut assignment = vec2(1.0, 2.0);
assignment *= 2.0;
assert_eq!(assignment, vec2(2.0, 4.0));
let mut assignment = vec2(2.0, 4.0);
assignment /= 2.0;
assert_eq!(assignment, vec2(1.0, 2.0));
}