simpleVectors.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __simpleVectors_h
00026 #define __simpleVectors_h
00027
00028 #include "stdio.h"
00029
00030 template <typename T>
00031 struct Vector2D
00032 {
00033 public:
00034 Vector2D(T x, T y) {
00035 set(x, y);
00036 }
00037
00038 Vector2D() {};
00039
00040 void set(T x, T y) {
00041 values[0] = x;
00042 values[1] = y;
00043 }
00044
00045 void print() {
00046 printf("Vector2D: %g %g\n", values[0], values[1]);
00047 }
00048
00049 T& operator [](int i) {
00050 return values[i];
00051 }
00052
00053 const T& operator [](int i) const {
00054 return values[i];
00055 }
00056
00057 T values[2];
00058 };
00059
00060
00061 template <typename T>
00062 struct Vector3D
00063 {
00064 public:
00065 Vector3D(T x, T y, T z) {
00066 set(x, y, z);
00067 }
00068
00069 Vector3D() {};
00070
00071 void set(T x, T y, T z) {
00072 values[0] = x;
00073 values[1] = y;
00074 values[2] = z;
00075 }
00076
00077 void print() {
00078 printf("Vector3D: %g %g %g\n", values[0], values[1], values[2]);
00079 }
00080
00081 T& operator [](int i) {
00082 return values[i];
00083 }
00084
00085 const T& operator [](int i) const {
00086 return values[i];
00087 }
00088
00089 T values[3];
00090 };
00091
00092 #endif