Skip to content

Commit 56713ad

Browse files
committed
Merge pull request #224 from jshs/master
Numeric traits moved to rust-lang/num
2 parents 6284864 + 5564e21 commit 56713ad

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ homepage = "https://github.com/pistondevelopers/vecmath"
1515
name = "vecmath"
1616
path = "src/lib.rs"
1717

18+
[dependencies]
19+
20+
num = "0.1.21"

src/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Various useful constants
22
3-
use std::num::FromPrimitive;
3+
use num::FromPrimitive;
44

55
/// Useful constants for radians.
66
pub trait Radians: FromPrimitive {
@@ -65,7 +65,7 @@ impl Radians for f64 {
6565
#[cfg(test)]
6666
mod test {
6767
use super::{Radians};
68-
use std::num::Float;
68+
use num::Float;
6969

7070
#[test]
7171
fn test_f32_deg_to_rad() {

src/lib.rs

+25-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![crate_name = "vecmath"]
22
#![deny(missing_docs)]
3-
#![feature(core, std_misc)]
3+
#![feature(core)]
44

55
//! A simple and generic library for vector math.
66
//!
@@ -19,7 +19,9 @@
1919
//! For example, `row_mat2x3_transform_pos2` transforms a position.
2020
//! `row_mat2x3_transform_vec2` transforms a vector.
2121
22-
use std::num::{Float, NumCast, ToPrimitive};
22+
extern crate num;
23+
24+
use num::{Float, NumCast, ToPrimitive};
2325

2426
pub mod consts;
2527

@@ -309,8 +311,8 @@ fn test_row_mat3x4_mul() {
309311
/// Constructs identity matrix.
310312
#[inline(always)]
311313
pub fn mat2x3_id<T: Float + Copy>() -> Matrix2x3<T> {
312-
let one = Float::one();
313-
let zero = Float::zero();
314+
let one = T::one();
315+
let zero = T::zero();
314316
[
315317
[one, zero, zero],
316318
[zero, one, zero]
@@ -320,8 +322,8 @@ pub fn mat2x3_id<T: Float + Copy>() -> Matrix2x3<T> {
320322
/// Constructs identity matrix.
321323
#[inline(always)]
322324
pub fn mat3x2_id<T: Float + Copy>() -> Matrix3x2<T> {
323-
let one = Float::one();
324-
let zero = Float::zero();
325+
let one = T::one();
326+
let zero = T::zero();
325327
[
326328
[one, zero],
327329
[zero, one],
@@ -332,8 +334,8 @@ pub fn mat3x2_id<T: Float + Copy>() -> Matrix3x2<T> {
332334
/// Constructs identity matrix.
333335
#[inline(always)]
334336
pub fn mat3_id<T: Float + Copy>() -> Matrix3<T> {
335-
let one = Float::one();
336-
let zero = Float::zero();
337+
let one = T::one();
338+
let zero = T::zero();
337339
[
338340
[one, zero, zero],
339341
[zero, one, zero],
@@ -344,8 +346,8 @@ pub fn mat3_id<T: Float + Copy>() -> Matrix3<T> {
344346
/// Constructs identity matrix.
345347
#[inline(always)]
346348
pub fn mat3x4_id<T: Float + Copy>() -> Matrix3x4<T> {
347-
let one = Float::one();
348-
let zero = Float::zero();
349+
let one = T::one();
350+
let zero = T::zero();
349351
[
350352
[one, zero, zero, zero],
351353
[zero, one, zero, zero],
@@ -356,8 +358,8 @@ pub fn mat3x4_id<T: Float + Copy>() -> Matrix3x4<T> {
356358
/// Constructs identity matrix.
357359
#[inline(always)]
358360
pub fn mat4x3_id<T: Float + Copy>() -> Matrix4x3<T> {
359-
let one = Float::one();
360-
let zero = Float::zero();
361+
let one = T::one();
362+
let zero = T::zero();
361363
[
362364
[one, zero, zero],
363365
[zero, one, zero],
@@ -369,8 +371,8 @@ pub fn mat4x3_id<T: Float + Copy>() -> Matrix4x3<T> {
369371
/// Constructs identity matrix.
370372
#[inline(always)]
371373
pub fn mat4_id<T: Float + Copy>() -> Matrix4<T> {
372-
let one = Float::one();
373-
let zero = Float::zero();
374+
let one = T::one();
375+
let zero = T::zero();
374376
[
375377
[one, zero, zero, zero],
376378
[zero, one, zero, zero],
@@ -809,21 +811,21 @@ pub fn vec4_len<T: Float>(a: Vector4<T>) -> T {
809811
/// Computes the inverse length of a vector.
810812
#[inline(always)]
811813
pub fn vec2_inv_len<T: Float>(a: Vector2<T>) -> T {
812-
let one: T = Float::one();
814+
let one = T::one();
813815
one / vec2_len(a)
814816
}
815817

816818
/// Computes the inverse length of a vector.
817819
#[inline(always)]
818820
pub fn vec3_inv_len<T: Float>(a: Vector3<T>) -> T {
819-
let one: T = Float::one();
821+
let one = T::one();
820822
one / vec3_len(a)
821823
}
822824

823825
/// Computes the inverse length of a vector.
824826
#[inline(always)]
825827
pub fn vec4_inv_len<T: Float>(a: Vector4<T>) -> T {
826-
let one: T = Float::one();
828+
let one = T::one();
827829
one / vec4_len(a)
828830
}
829831

@@ -1325,42 +1327,42 @@ pub fn mat4_det<T: Float>(mat: Matrix4<T>) -> T {
13251327
/// Computes inverse determinant of a 2x3 matrix.
13261328
#[inline(always)]
13271329
pub fn mat2x3_inv_det<T: Float>(mat: Matrix2x3<T>) -> T {
1328-
let one: T = Float::one();
1330+
let one = T::one();
13291331
one / mat2x3_det(mat)
13301332
}
13311333

13321334
/// Computes inverse determinant of a 3x2 matrix.
13331335
#[inline(always)]
13341336
pub fn mat3x2_inv_det<T: Float>(mat: Matrix3x2<T>) -> T {
1335-
let one: T = Float::one();
1337+
let one = T::one();
13361338
one / mat3x2_det(mat)
13371339
}
13381340

13391341
/// Computes inverse determinant of a 3x3 matrix.
13401342
#[inline(always)]
13411343
pub fn mat3_inv_det<T: Float>(mat: Matrix3<T>) -> T {
1342-
let one: T = Float::one();
1344+
let one = T::one();
13431345
one / mat3_det(mat)
13441346
}
13451347

13461348
/// Computes inverse determinant of a 3x4 matrix.
13471349
#[inline(always)]
13481350
pub fn mat3x4_inv_det<T: Float>(mat: Matrix3x4<T>) -> T {
1349-
let one: T = Float::one();
1351+
let one = T::one();
13501352
one / mat3x4_det(mat)
13511353
}
13521354

13531355
/// Computes inverse determinant of a 4x3 matrix.
13541356
#[inline(always)]
13551357
pub fn mat4x3_inv_det<T: Float>(mat: Matrix4x3<T>) -> T {
1356-
let one: T = Float::one();
1358+
let one = T::one();
13571359
one / mat4x3_det(mat)
13581360
}
13591361

13601362
/// Computes the inverse determinant of a 4x4 matrix.
13611363
#[inline(always)]
13621364
pub fn mat4_inv_det<T: Float>(mat: Matrix4<T>) -> T {
1363-
let one: T = Float::one();
1365+
let one = T::one();
13641366
one / mat4_det(mat)
13651367
}
13661368

0 commit comments

Comments
 (0)