src/Vector.hh
changeset 425 567144562978
parent 424 f337a86d144e
equal deleted inserted replaced
424:f337a86d144e 425:567144562978
   198  */
   198  */
   199 template<typename T> std::ostream& operator<< (std::ostream &s, const VectorType<T> &v) {
   199 template<typename T> std::ostream& operator<< (std::ostream &s, const VectorType<T> &v) {
   200     return s << "(" << v.x << ", " << v.y << ")";
   200     return s << "(" << v.x << ", " << v.y << ")";
   201 }
   201 }
   202 
   202 
   203 // Templates function implementations
   203 /*
   204 #include <cmath>
   204  * Vector template method implementation
   205 #include <cstdlib>
   205  */
   206 
       
   207 /**
       
   208  * Float/int absolute value
       
   209  */
       
   210 template<typename T> static T absType (T value);
       
   211 template<> static float absType<float> (float value) { return (float) fabs(value); }
       
   212 template<> static long absType<long> (long value) { return labs(value); }
       
   213 
   206 
   214 /**
   207 /**
   215  * Direction-normalize the given coordinate against the tangent coordinate.
   208  * Direction-normalize the given coordinate against the tangent coordinate.
   216  *
   209  *
   217  * Returns 1 if the coordinate is positive and greater than the tangent, -1 if the coordinate is less than and
   210  * Returns 1 if the coordinate is positive and greater than the tangent, -1 if the coordinate is less than and
   218  * negative, else zero.
   211  * negative, else zero.
   219  */
   212  */
   220 template<typename T> static T normalizeCoordinate (T coord, T tangent) {
   213 template<typename T> static T normalizeCoordinate (T coord, T tangent) {
   221     if (coord > absType(tangent))
   214     // XXX: use hand-crafted abs because GCC 4.3/4.2 static template functions seem to be broken somehow
       
   215     if (coord > (tangent < 0 ? -tangent : tangent))
   222         return 1;
   216         return 1;
   223 
   217 
   224     else if (coord < -absType(tangent))
   218     else if (coord < (tangent > 0 ? -tangent : tangent))
   225         return -1;
   219         return -1;
   226 
   220 
   227     else
   221     else
   228         return 0;
   222         return 0;
   229 }
   223 }