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!
#[macro_use]
extern crate glium;
extern crate cgmath;
use cgmath::{Matrix4, Point2};
use cgmath::prelude::*;
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:
#[macro_use]
extern crate glium;
extern crate cgmath;
use cgmath::{Matrix4, Point2};
use cgmath::prelude::*;
use cgmath::conv::*;
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.