This adds get_size() to all vector implementations.
get_size() was added so that vectors could all be converted to Vector4 when being turned into binary values. from_str_radix() for floating point numbers was deprecated from the standard library. Until there is time to write our own implementation of this floating point numbers will panic on non base 10 string conversion. Base 10 string conversion will use the from_str function.
This commit is contained in:
parent
a618fb27f7
commit
902aeb5dbe
@ -3,7 +3,6 @@
|
|||||||
//!
|
//!
|
||||||
//!
|
//!
|
||||||
#![feature(zero_one)]
|
#![feature(zero_one)]
|
||||||
#![feature(float_from_str_radix)]
|
|
||||||
#![feature(float_extras)]
|
#![feature(float_extras)]
|
||||||
#![feature(associated_consts)]
|
#![feature(associated_consts)]
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ use std::cmp::PartialEq;
|
|||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::num::{Zero, One};
|
use std::num::{Zero, One};
|
||||||
use std::ops::{Add, Sub, Mul, Div, Rem};
|
use std::ops::{Add, Sub, Mul, Div, Rem};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use super::bounded::Bounded;
|
use super::bounded::Bounded;
|
||||||
|
|
||||||
@ -770,7 +771,13 @@ macro_rules! float_number_trait_impl
|
|||||||
fn from_str_radix(src: &str, radix: u32) ->
|
fn from_str_radix(src: &str, radix: u32) ->
|
||||||
Result<Self, ::std::num::ParseFloatError>
|
Result<Self, ::std::num::ParseFloatError>
|
||||||
{
|
{
|
||||||
<$varType>::from_str_radix(src, radix)
|
// TODO: Currently this will panic on a non base 10 radix.
|
||||||
|
// This is because the std library deprecated the
|
||||||
|
// from_str_radix function. Until a function can be
|
||||||
|
// written this will use the from_str function and
|
||||||
|
// panic for non base 10 requests.
|
||||||
|
assert!(radix == 10);
|
||||||
|
<$varType>::from_str(src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)*)
|
)*)
|
||||||
|
@ -47,6 +47,12 @@ pub trait Vector<T> : Clone where T: Number
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Property functions.
|
||||||
|
/// Returns the size, how many components the Vector
|
||||||
|
/// has, of this Vector.
|
||||||
|
fn get_size(&self) -> u8;
|
||||||
|
|
||||||
|
|
||||||
// Scalar operations that change this Vector.
|
// Scalar operations that change this Vector.
|
||||||
/// Add a scalar value to this Vector.
|
/// Add a scalar value to this Vector.
|
||||||
///
|
///
|
||||||
@ -511,7 +517,7 @@ macro_rules! binary_operator_impl
|
|||||||
/// that implements the Vector trait.
|
/// that implements the Vector trait.
|
||||||
macro_rules! define_vector
|
macro_rules! define_vector
|
||||||
{
|
{
|
||||||
($structName: ident <$T: ident> {$($field: ident),+}) =>
|
($structName: ident <$T: ident> {$($field: ident),+}, $field_count: expr) =>
|
||||||
{
|
{
|
||||||
// Do not add a where clause here or implementing
|
// Do not add a where clause here or implementing
|
||||||
// generic traits were the generic is different
|
// generic traits were the generic is different
|
||||||
@ -558,6 +564,11 @@ macro_rules! define_vector
|
|||||||
$structName {$($field: val),+}
|
$structName {$($field: val),+}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_size(&self) -> u8
|
||||||
|
{
|
||||||
|
$field_count
|
||||||
|
}
|
||||||
|
|
||||||
fn add_scalar(&mut self, scalar: T)
|
fn add_scalar(&mut self, scalar: T)
|
||||||
{
|
{
|
||||||
*self = &*self + scalar;
|
*self = &*self + scalar;
|
||||||
@ -665,9 +676,9 @@ macro_rules! define_vector
|
|||||||
|
|
||||||
|
|
||||||
// Define the Vector2, Vector3, and Vector4 structures.
|
// Define the Vector2, Vector3, and Vector4 structures.
|
||||||
define_vector!(Vector2<T> {x, y});
|
define_vector!(Vector2<T> {x, y}, 2u8);
|
||||||
define_vector!(Vector3<T> {x, y, z});
|
define_vector!(Vector3<T> {x, y, z}, 3u8);
|
||||||
define_vector!(Vector4<T> {x, y, z, w});
|
define_vector!(Vector4<T> {x, y, z, w}, 4u8);
|
||||||
|
|
||||||
|
|
||||||
// Implements operations specific to the different
|
// Implements operations specific to the different
|
||||||
|
Loading…
x
Reference in New Issue
Block a user