added len function to Array

This commit is contained in:
harrison 2017-07-31 16:13:15 -04:00
parent 67f82eef06
commit 9b84d804ae
3 changed files with 20 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),+ }