Skip to content

Commit

Permalink
implement mint conversions (#352)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
luiswirth authored May 8, 2021
1 parent 2cb94b9 commit 87bc26f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions emath/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ include = [
[lib]

[dependencies]
mint = { version = "0.5.6", optional = true }
serde = { version = "1", features = ["derive"], optional = true }

[features]
Expand Down
17 changes: 17 additions & 0 deletions emath/src/pos2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions emath/src/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions epaint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 87bc26f

Please sign in to comment.