one-file-projects/vectors.cpp

51 lines
1 KiB
C++

#include <iostream>
#include "vectors.hpp"
/** A print function the Vector type
*
* this function print a vector which contains integers
*
* @tparam NDim dimension of the Vector
* @param v the vector to be printed
*/
template<
unsigned int NDim
>
void printVector(const Vector<NDim, int> v) {
printf("Vector [ %d", v[0]);
for(int i = 1; i < NDim; i++) {
printf(", %d", v[i]);
}
printf(" ] length %d\n", v.length());
}
/** A print function the Vector type
*
* this function print a vector which contains floats
*
* @tparam NDim dimension of the Vector
* @param v the vector to be printed
*/
template<
unsigned int NDim
>
void printVector(const Vector<NDim, float> v) {
printf("Vector [ %.3f", v[0]);
for(int i = 1; i < NDim; i++) {
printf(", %.3f", v[i]);
}
printf(" ] length %.3f\n", v.length());
}
#define DIM 3
int main( int argc, char *argv[] ) {
Vector<3,int> a{1,2,3};
Vector<3,float> c;
c = a.normalize();
printVector(c);
a = c;
printVector(a);
}