688 |
khor |
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 |
* @brief Abstract 2D floating point vector class
|
|
|
6 |
* ----------------------------------------------------------------------- */
|
|
|
7 |
|
|
|
8 |
/** @file ArithVec2Float.h
|
|
|
9 |
* @brief Abstract 2D floating point vector class
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
#ifndef __CGLA__ARITHVEC2FLOAT_H__
|
|
|
13 |
#define __CGLA__ARITHVEC2FLOAT_H__
|
|
|
14 |
|
|
|
15 |
#include "ArithVecFloat.h"
|
|
|
16 |
|
|
|
17 |
namespace CGLA {
|
|
|
18 |
|
|
|
19 |
template<class T, class V>
|
|
|
20 |
class ArithVec2Float: public ArithVecFloat<T,V,2>
|
|
|
21 |
{
|
|
|
22 |
public:
|
|
|
23 |
|
|
|
24 |
/// Construct a 2D float vector.
|
|
|
25 |
ArithVec2Float(T a, T b): ArithVecFloat<T,V,2>(a,b) {}
|
|
|
26 |
|
|
|
27 |
/// Construct a 2D float vector.
|
|
|
28 |
ArithVec2Float() {}
|
|
|
29 |
};
|
|
|
30 |
|
|
|
31 |
/// Returns normalized vector
|
|
|
32 |
template<class T, class V>
|
|
|
33 |
inline V normalize(const ArithVec2Float<T,V>& v)
|
|
|
34 |
{
|
|
|
35 |
return v/v.length();
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
/// Rotates vector 90 degrees to obtain orthogonal vector
|
|
|
39 |
template<class T, class V>
|
|
|
40 |
inline V orthogonal(const ArithVec2Float<T,V>& v)
|
|
|
41 |
{
|
|
|
42 |
return V(-v[1],v[0]);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
// Computes (scalar) cross product from two vectors
|
|
|
46 |
template<class T, class V>
|
|
|
47 |
inline T cross(const ArithVec2Float<T,V>& a,
|
|
|
48 |
const ArithVec2Float<T,V>& b)
|
|
|
49 |
{
|
|
|
50 |
return a[0]*b[1]-a[1]*b[0];
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/** The two last (scalar) arguments are the linear combination of
|
|
|
54 |
the two first arguments (vectors) which produces the third argument.
|
|
|
55 |
*/
|
|
|
56 |
template<class T, class V>
|
|
|
57 |
bool linear_combine(const ArithVec2Float<T,V>& a,
|
|
|
58 |
const ArithVec2Float<T,V>& b,
|
|
|
59 |
const ArithVec2Float<T,V>& c,
|
|
|
60 |
T&,
|
|
|
61 |
T&);
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
#endif
|
|
|
67 |
|