-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add math type conversions to
mint
types (#4753)
### What * Fixes #3292 Also fixes `Vec4D::w()` returning z instead! Adds missing extensions to Mat4. ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using newly built examples: [app.rerun.io](https://app.rerun.io/pr/4753/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/4753/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/4753/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4753) - [Docs preview](https://rerun.io/preview/82e8f1caab378afe4fb99032e10eaf7d59b28c95/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/82e8f1caab378afe4fb99032e10eaf7d59b28c95/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
- Loading branch information
Showing
22 changed files
with
582 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
use super::Mat4x4; | ||
|
||
use crate::datatypes::Vec4D; | ||
|
||
impl Mat4x4 { | ||
#[rustfmt::skip] | ||
pub const IDENTITY: Mat4x4 = Mat4x4([ | ||
1.0, 0.0, 0.0, 0.0, | ||
0.0, 1.0, 0.0, 0.0, | ||
0.0, 0.0, 1.0, 0.0, | ||
0.0, 0.0, 0.0, 1.0, | ||
]); | ||
|
||
/// Returns the matrix column for the given `index`. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Panics if `index` is greater than 2. | ||
#[inline] | ||
pub fn col(&self, index: usize) -> Vec4D { | ||
match index { | ||
0 => [self.0[0], self.0[1], self.0[2], self.0[3]].into(), | ||
1 => [self.0[4], self.0[5], self.0[6], self.0[7]].into(), | ||
2 => [self.0[8], self.0[9], self.0[10], self.0[11]].into(), | ||
3 => [self.0[12], self.0[13], self.0[14], self.0[15]].into(), | ||
_ => panic!("index out of bounds"), | ||
} | ||
} | ||
} | ||
|
||
impl<Idx> std::ops::Index<Idx> for Mat4x4 | ||
where | ||
Idx: std::slice::SliceIndex<[f32]>, | ||
{ | ||
type Output = Idx::Output; | ||
|
||
#[inline] | ||
fn index(&self, index: Idx) -> &Self::Output { | ||
&self.0[index] | ||
} | ||
} | ||
|
||
impl From<[Vec4D; 4]> for Mat4x4 { | ||
#[inline] | ||
#[rustfmt::skip] | ||
fn from(v: [Vec4D; 4]) -> Self { | ||
Self([ | ||
v[0].x(), v[0].y(), v[0].z(), v[0].w(), | ||
v[1].x(), v[1].y(), v[1].z(), v[1].w(), | ||
v[2].x(), v[2].y(), v[2].z(), v[2].w(), | ||
v[3].x(), v[3].y(), v[3].z(), v[3].w(), | ||
]) | ||
} | ||
} | ||
|
||
impl From<Mat4x4> for [Vec4D; 4] { | ||
fn from(val: Mat4x4) -> Self { | ||
[ | ||
[val.0[0], val.0[1], val.0[2], val.0[3]].into(), | ||
[val.0[4], val.0[5], val.0[6], val.0[7]].into(), | ||
[val.0[8], val.0[9], val.0[10], val.0[11]].into(), | ||
[val.0[12], val.0[13], val.0[14], val.0[15]].into(), | ||
] | ||
} | ||
} | ||
|
||
impl From<[[f32; 4]; 4]> for Mat4x4 { | ||
#[inline] | ||
fn from(v: [[f32; 4]; 4]) -> Self { | ||
Self::from([Vec4D(v[0]), Vec4D(v[1]), Vec4D(v[2]), Vec4D(v[3])]) | ||
} | ||
} | ||
|
||
#[cfg(feature = "glam")] | ||
impl From<Mat4x4> for glam::Mat4 { | ||
#[inline] | ||
fn from(v: Mat4x4) -> Self { | ||
let [x, y, z, w]: [Vec4D; 4] = v.into(); | ||
Self::from_cols(x.into(), y.into(), z.into(), w.into()) | ||
} | ||
} | ||
|
||
#[cfg(feature = "glam")] | ||
impl From<glam::Mat4> for Mat4x4 { | ||
#[inline] | ||
fn from(v: glam::Mat4) -> Self { | ||
Self::from(v.to_cols_array_2d()) | ||
} | ||
} | ||
|
||
#[cfg(feature = "mint")] | ||
impl From<Mat4x4> for mint::ColumnMatrix4<f32> { | ||
#[inline] | ||
fn from(v: Mat4x4) -> Self { | ||
v.0.into() | ||
} | ||
} | ||
|
||
#[cfg(feature = "mint")] | ||
impl From<mint::ColumnMatrix4<f32>> for Mat4x4 { | ||
#[inline] | ||
fn from(v: mint::ColumnMatrix4<f32>) -> Self { | ||
std::convert::From::<[[f32; 4]; 4]>::from([v.x.into(), v.y.into(), v.z.into(), v.w.into()]) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.