Module cgmath::conv [−][src]
Expand description
Constrained conversion functions for assisting in situations where type inference is difficult.
For example, when declaring glium
uniforms, we need to convert to fixed
length arrays. We can use the Into
trait directly, but it is rather ugly!
— Doc-test disabled because glium causes problems with nightly-2019-01-01 needed for “simd”
`rust
#[macro_use]
extern crate glium;
extern crate cgmath;
use cgmath::{Matrix4, Point2}; use cgmath::prelude::*;
fn main() {
let point = Point2::new(1, 2); let matrix = Matrix4::from_scale(2.0);
let uniforms = uniform! { point: Into::<[; 2]>::into(point), matrix: Into::<[[; 4]; 4]>::into(matrix), // Yuck!! (ノಥ益ಥ)ノ ┻━┻ };
}
`
Instead, we can use the conversion functions from the conv
module:
— Doc-test disabled because glium causes problems nightly-2019-01-01 needed for “simd”
`rust
#[macro_use]
extern crate glium;
extern crate cgmath;
use cgmath::{Matrix4, Point2}; use cgmath::prelude::; use cgmath::conv::;
fn main() {
let point = Point2::new(1, 2); let matrix = Matrix4::from_scale(2.0);
let uniforms = uniform! { point: array2(point), matrix: array4x4(matrix), // ┬─┬ノ( º _ ºノ) };
}
`
Functions
Force a conversion into a 2-element array.
Force a conversion into a 2x2-element array.
Force a conversion into a 3-element array.
Force a conversion into a 3x3-element array.
Force a conversion into a 4-element array.
Force a conversion into a 4x4-element array.