00001 00020 #ifndef MOD128_H 00021 #define MOD128_H 00022 00023 #include "points.h" 00024 00026 #define MODULUS 128 00028 #define DIRBITS 7 00030 #define DIRSCALE 1000 00031 00036 class DLLSYM DIR128 00037 { 00038 public: 00039 DIR128() { 00040 } //empty constructor 00041 00042 DIR128( //constructor 00043 INT16 value) { //value to assign 00044 value %= MODULUS; //modulo arithmetic 00045 if (value < 0) 00046 value += MODULUS; //done properly 00047 dir = (INT8) value; 00048 } 00049 DIR128(const FCOORD fc); //quantize vector 00050 00051 DIR128 & operator= ( //assign of INT16 00052 INT16 value) { //value to assign 00053 value %= MODULUS; //modulo arithmetic 00054 if (value < 0) 00055 value += MODULUS; //done properly 00056 dir = (INT8) value; 00057 return *this; 00058 } 00059 INT8 operator- ( //subtraction 00060 const DIR128 & minus) const//for signed result 00061 { 00062 //result 00063 INT16 result = dir - minus.dir; 00064 00065 if (result > MODULUS / 2) 00066 result -= MODULUS; //get in range 00067 else if (result < -MODULUS / 2) 00068 result += MODULUS; 00069 return (INT8) result; 00070 } 00071 DIR128 operator+ ( //addition 00072 const DIR128 & add) const //of itself 00073 { 00074 DIR128 result; //sum 00075 00076 result = dir + add.dir; //let = do the work 00077 return result; 00078 } 00079 DIR128 & operator+= ( //same as + 00080 const DIR128 & add) { 00081 *this = dir + add.dir; //let = do the work 00082 return *this; 00083 } 00084 INT8 get_dir() const { //access function 00085 return dir; 00086 } 00087 ICOORD vector() const; //turn to vector 00088 00089 private: 00090 INT8 dir; //a direction 00091 }; 00092 #endif