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

implement mint conversions (#352)

* Implement mint conversions

Implement conversions for [mint](https://docs.rs/mint) (math interoperability standard types).

- `impl {From, Into}<mint::Point2> for Pos2`
- `impl {From, Into}<mint::Vector2> for Vec2`

* Forward `mint` feature: egui -> epaint -> emath
This commit is contained in:
Luis Wirth
2021-05-08 08:17:01 +02:00
committed by GitHub
parent 2cb94b98ef
commit 87bc26fb5a
6 changed files with 47 additions and 1 deletions

View File

@@ -84,6 +84,23 @@ impl From<&Pos2> for (f32, f32) {
}
}
// ----------------------------------------------------------------------------
// Mint compatibility and convenience conversions
#[cfg(feature = "mint")]
impl From<mint::Point2<f32>> for Pos2 {
fn from(v: mint::Point2<f32>) -> Self {
Self::new(v.x, v.y)
}
}
#[cfg(feature = "mint")]
impl From<Pos2> for mint::Point2<f32> {
fn from(v: Pos2) -> Self {
Self { x: v.x, y: v.y }
}
}
// ----------------------------------------------------------------------------
impl Pos2 {

View File

@@ -81,6 +81,23 @@ impl From<&Vec2> for (f32, f32) {
}
}
// ----------------------------------------------------------------------------
// Mint compatibility and convenience conversions
#[cfg(feature = "mint")]
impl From<mint::Vector2<f32>> for Vec2 {
fn from(v: mint::Vector2<f32>) -> Self {
Self::new(v.x, v.y)
}
}
#[cfg(feature = "mint")]
impl From<Vec2> for mint::Vector2<f32> {
fn from(v: Vec2) -> Self {
Self { x: v.x, y: v.y }
}
}
// ----------------------------------------------------------------------------
impl Vec2 {