Subversion Repositories gelsvn

Rev

Rev 125 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 125 Rev 595
Line -... Line 1...
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
-
 
6
 
-
 
7
/** @file ArithVecFloat.h
-
 
8
 * @brief Abstract 2D floating point vector class
-
 
9
 */
-
 
10
 
1
#ifndef __CGLA__ARITHVECFLOAT_H__
11
#ifndef __CGLA__ARITHVECFLOAT_H__
2
#define __CGLA__ARITHVECFLOAT_H__
12
#define __CGLA__ARITHVECFLOAT_H__
3
 
13
 
4
#include "ArithVec.h"
14
#include "ArithVec.h"
5
 
15
 
Line 39... Line 49...
39
      void normalize() 
49
        void normalize() 
40
	{
50
        {
41
	  (*this) /= this->length();
51
            (*this) /= this->length();
42
	}
52
        }
43
		
53
        
-
 
54
        /// Conditionally normalize vector. The condition being that the vector has non-zero length
-
 
55
        void cond_normalize() 
-
 
56
        {
-
 
57
            T sql = sqr_length(*this);
-
 
58
            if(sql > 0)
-
 
59
                (*this) /= sqrt(sql);
-
 
60
        }
-
 
61
        
44
    };
62
    };
45
 
63
    
46
  /// Returns normalized vector
64
    /// Returns length of vector
47
  template<class T, class V, unsigned int N>
65
    template<class T, class V, unsigned int N>
48
    inline T length(const ArithVecFloat<T,V,N>& v) 
66
    inline T length(const ArithVecFloat<T,V,N>& v) 
49
    {
67
    {
50
      return v.length();
68
        return v.length();
51
    }
69
    }
Line 55... Line 73...
55
  template<class T, class V, unsigned int N>
73
    template<class T, class V, unsigned int N>
56
    inline V normalize(const ArithVecFloat<T,V,N>& v) 
74
    inline V normalize(const ArithVecFloat<T,V,N>& v) 
57
    {
75
    {
58
      return v/v.length();
76
        return v/v.length();
59
    }
77
    }
-
 
78
    
-
 
79
    /// Returns normalized vector if the vector has non-zero length - otherwise the 0 vector.
-
 
80
    template<class T, class V, unsigned int N>
-
 
81
    inline V cond_normalize(const ArithVecFloat<T,V,N>& v) 
-
 
82
    {
-
 
83
        T sql = sqr_length(v);
-
 
84
        if(sql > 0)
-
 
85
            return v/sqrt(sql);
-
 
86
        return v*1.0;
-
 
87
    }
-
 
88
    
60
}
89
}
61
 
90
 
62
#endif
91
#endif
63
 
92