digitalmars.D - vector
- tm030127d galeb.etf.bg.ac.yu (26/26) Aug 31 2004 How to rewrite this class in D?
- Stephen Waits (5/8) Aug 31 2004 Icky.
How to rewrite this class in D? template<class T> struct Vec3 { T x, y, z; Vec3(T X = 0, T Y = 0, T Z = 0): x(X), y(Y), z(Z) {} Vec3<T> operator =(T a) {x=a; y=a; z=a; return *this;} void operator()(T X, T Y, T Z) {x=X; y=Y; z=Z;} Vec3<T> operator +(const Vec3<T>& V) const {return Vec3<T>(x+V.x, y+V.y, z+V.z);} Vec3<T> operator -(const Vec3<T>& V) const {return Vec3<T>(x-V.x, y-V.y, z-V.z);} Vec3<T> operator -() const {return Vec3<T>(-x,-y,-z);} Vec3<T> operator *(T a) const {return Vec3<T>(x*a, y*a, z*a);} Vec3<T> operator /(T a) const {return Vec3<T>(x/a, y/a, z/a);} void operator +=(const Vec3<T>& V) {x+=V.x; y+=V.y; z+=V.z;} void operator -=(const Vec3<T>& V) {x-=V.x; y-=V.y; z-=V.z;} void operator *=(T a) {x*=a; y*=a; z*=a;} void operator /=(T a) {x/=a; y/=a; z/=a;} T operator *(const Vec3<T>& V) const {return x*V.x + y*V.y + z*V.z;} Vec3<T> operator ^(const Vec3<T>& V) const {return Vec3<T>(y*V.z - z*V.y, z*V.x - x*V.z, x*V.y - y*V.x);} T sqr() const {return x*x + y*y + z*z;} T operator ~() const {return sqrt(sqr());} Vec3<T> operator !() const {return (*this)/~(*this);} };
Aug 31 2004
tm030127d galeb.etf.bg.ac.yu wrote:T operator *(const Vec3<T>& V) const {return x*V.x + y*V.y + z*V.z;} Vec3<T> operator ^(const Vec3<T>& V) const {return Vec3<T>(y*V.z - z*V.y, z*V.x - x*V.z, x*V.y - y*V.x);}Icky. s/operator \*/Dot/ s/operator \^/Cross/ --Steve
Aug 31 2004