Browse Source

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
fix-scrolling
Luis Wirth 4 years ago
committed by GitHub
parent
commit
87bc26fb5a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      Cargo.lock
  2. 4
      egui/Cargo.toml
  3. 1
      emath/Cargo.toml
  4. 17
      emath/src/pos2.rs
  5. 17
      emath/src/vec2.rs
  6. 2
      epaint/Cargo.toml

7
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"

4
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"
serde_json = "1"

1
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]

17
emath/src/pos2.rs

@ -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 {

17
emath/src/vec2.rs

@ -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 {

2
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"]

Loading…
Cancel
Save