From 7824e2ac18d714ac70ea021030997af42d7ccc26 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 30 Mar 2025 16:41:20 +0200 Subject: [PATCH] Implement `MulAssign` for `Pos2` --- crates/emath/src/pos2.rs | 14 ++++++++++++-- crates/epaint/src/shapes/shape.rs | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/emath/src/pos2.rs b/crates/emath/src/pos2.rs index 1f4bd8642..62590b10f 100644 --- a/crates/emath/src/pos2.rs +++ b/crates/emath/src/pos2.rs @@ -1,5 +1,7 @@ -use std::fmt; -use std::ops::{Add, AddAssign, Sub, SubAssign}; +use std::{ + fmt, + ops::{Add, AddAssign, MulAssign, Sub, SubAssign}, +}; use crate::{lerp, Div, Mul, Vec2}; @@ -305,6 +307,14 @@ impl Mul for f32 { } } +impl MulAssign for Pos2 { + #[inline(always)] + fn mul_assign(&mut self, rhs: f32) { + self.x *= rhs; + self.y *= rhs; + } +} + impl Div for Pos2 { type Output = Self; diff --git a/crates/epaint/src/shapes/shape.rs b/crates/epaint/src/shapes/shape.rs index 006289bf1..38af4ca2c 100644 --- a/crates/epaint/src/shapes/shape.rs +++ b/crates/epaint/src/shapes/shape.rs @@ -484,7 +484,7 @@ impl Shape { let row = Arc::make_mut(&mut placed_row.row); row.visuals.mesh_bounds = transform.scaling * row.visuals.mesh_bounds; for v in &mut row.visuals.mesh.vertices { - v.pos = Pos2::new(transform.scaling * v.pos.x, transform.scaling * v.pos.y); + v.pos *= transform.scaling; } }