Merge pull request #422 from hclarke/master

added len function to Array
This commit is contained in:
Brendan Zabarauskas 2017-08-01 08:35:53 +10:00 committed by GitHub
commit cbeba0883c
3 changed files with 25 additions and 0 deletions

View file

@ -103,6 +103,11 @@ macro_rules! impl_point {
impl<S: BaseNum> Array for $PointN<S> {
type Element = S;
#[inline]
fn len() -> usize {
$n
}
#[inline]
fn from_value(scalar: S) -> $PointN<S> {
$PointN { $($field: scalar),+ }

View file

@ -35,6 +35,16 @@ pub trait Array where
{
type Element: Copy;
/// Get the number of elements in the array type
///
/// ```rust
/// use cgmath::prelude::*;
/// use cgmath::Vector3;
///
/// assert_eq!(Vector3::<f32>::len(), 3);
/// ```
fn len() -> usize;
/// Construct a vector from a single value, replicating it.
///
/// ```rust

View file

@ -129,6 +129,11 @@ macro_rules! impl_vector {
impl<S: Copy> Array for $VectorN<S> {
type Element = S;
#[inline]
fn len() -> usize {
$n
}
#[inline]
fn from_value(scalar: S) -> $VectorN<S> {
$VectorN { $($field: scalar),+ }
@ -341,6 +346,11 @@ macro_rules! impl_vector_default {
impl<S: Copy> Array for $VectorN<S> {
type Element = S;
#[inline]
fn len() -> usize {
$n
}
#[inline]
fn from_value(scalar: S) -> $VectorN<S> {
$VectorN { $($field: scalar),+ }