diff --git a/Cargo.lock b/Cargo.lock index 1f650f2c..f8e3a569 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -823,6 +823,7 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" name = "emath" version = "0.11.0" dependencies = [ + "mint", "serde", ] @@ -1362,6 +1363,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mint" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "519df8d6856dcd4b40519947737b408f81be051fc032590659cae5d77d664185" + [[package]] name = "mio" version = "0.6.23" diff --git a/egui/Cargo.toml b/egui/Cargo.toml index 88784c9f..926a0222 100644 --- a/egui/Cargo.toml +++ b/egui/Cargo.toml @@ -37,5 +37,7 @@ persistence = ["serde", "epaint/persistence", "ron"] single_threaded = ["epaint/single_threaded"] multi_threaded = ["epaint/multi_threaded"] +mint = ["epaint/mint"] + [dev-dependencies] -serde_json = "1" \ No newline at end of file +serde_json = "1" diff --git a/emath/Cargo.toml b/emath/Cargo.toml index 6f2ccc73..8e4f84bf 100644 --- a/emath/Cargo.toml +++ b/emath/Cargo.toml @@ -20,6 +20,7 @@ include = [ [lib] [dependencies] +mint = { version = "0.5.6", optional = true } serde = { version = "1", features = ["derive"], optional = true } [features] diff --git a/emath/src/pos2.rs b/emath/src/pos2.rs index 09b5c02b..70fd53fe 100644 --- a/emath/src/pos2.rs +++ b/emath/src/pos2.rs @@ -84,6 +84,23 @@ impl From<&Pos2> for (f32, f32) { } } +// ---------------------------------------------------------------------------- +// Mint compatibility and convenience conversions + +#[cfg(feature = "mint")] +impl From> for Pos2 { + fn from(v: mint::Point2) -> Self { + Self::new(v.x, v.y) + } +} + +#[cfg(feature = "mint")] +impl From for mint::Point2 { + fn from(v: Pos2) -> Self { + Self { x: v.x, y: v.y } + } +} + // ---------------------------------------------------------------------------- impl Pos2 { diff --git a/emath/src/vec2.rs b/emath/src/vec2.rs index 34e5f631..d6465704 100644 --- a/emath/src/vec2.rs +++ b/emath/src/vec2.rs @@ -81,6 +81,23 @@ impl From<&Vec2> for (f32, f32) { } } +// ---------------------------------------------------------------------------- +// Mint compatibility and convenience conversions + +#[cfg(feature = "mint")] +impl From> for Vec2 { + fn from(v: mint::Vector2) -> Self { + Self::new(v.x, v.y) + } +} + +#[cfg(feature = "mint")] +impl From for mint::Vector2 { + fn from(v: Vec2) -> Self { + Self { x: v.x, y: v.y } + } +} + // ---------------------------------------------------------------------------- impl Vec2 { diff --git a/epaint/Cargo.toml b/epaint/Cargo.toml index faa29daa..0beb247f 100644 --- a/epaint/Cargo.toml +++ b/epaint/Cargo.toml @@ -43,3 +43,5 @@ single_threaded = ["atomic_refcell"] # Only needed if you plan to use the same fonts from multiple threads. multi_threaded = ["parking_lot"] + +mint = ["emath/mint"]