From 603e5bc5fb26845c6340039beb1f8b6d855af413 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 30 Apr 2022 15:50:12 +0200 Subject: [PATCH] Add Rect::lerp --- emath/src/rect.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/emath/src/rect.rs b/emath/src/rect.rs index 38dbc7e5..26b79450 100644 --- a/emath/src/rect.rs +++ b/emath/src/rect.rs @@ -359,6 +359,15 @@ impl Rect { inside_dist + outside_dist } + /// Linearly interpolate so that `[0, 0]` is [`Self::min`] and + /// `[1, 1]` is [`Self::max`]. + pub fn lerp(&self, t: Vec2) -> Pos2 { + Pos2 { + x: lerp(self.min.x..=self.max.x, t.x), + y: lerp(self.min.y..=self.max.y, t.y), + } + } + #[inline(always)] pub fn x_range(&self) -> RangeInclusive { self.min.x..=self.max.x