From 9cdcf78c04d3e3e77682c99fa7308a837a5dee8e Mon Sep 17 00:00:00 2001 From: Varphone Wong Date: Mon, 11 Mar 2024 10:21:58 +0800 Subject: [PATCH] `emath`: impl From for Pos --- crates/emath/src/pos2.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/emath/src/pos2.rs b/crates/emath/src/pos2.rs index 485e95c7f..c0a09fdda 100644 --- a/crates/emath/src/pos2.rs +++ b/crates/emath/src/pos2.rs @@ -90,6 +90,22 @@ impl From<&Pos2> for (f32, f32) { } } +// ---------------------------------------------------------------------------- +// Compatibility and convenience conversions to and from Vec2: +impl From for Pos2 { + #[inline(always)] + fn from(v: Vec2) -> Self { + Self { x: v.x, y: v.y } + } +} + +impl From<&Vec2> for Pos2 { + #[inline(always)] + fn from(v: &Vec2) -> Self { + Self { x: v.x, y: v.y } + } +} + // ---------------------------------------------------------------------------- // Mint compatibility and convenience conversions