6 T
static zero() {
return 0; };
7 T
static one() {
return 1; };
9 template<>
struct Traits<float>;
10 template<>
struct Traits<double>;
13 template<
class T,
unsigned int D>
34 static VT
zero() {
return VT(TTrait::zero()); }
35 static VT
one() {
return VT(TTrait::one()); }
38 CTPtr
begin()
const {
return val; }
39 TPtr
end() {
return &val[D]; }
40 CTPtr
end()
const {
return &val[D]; }
41 static unsigned int size() {
return D; }
42 const T&
operator[](
unsigned int i)
const {
return val[i]; }
47 for(CTPtr pv=begin(); pv!=end(); pv++, sv++)
48 if(*pv != *sv)
return false;
53 for(CTPtr pv=begin(); pv!=end(); pv++, sv++)
54 if(*pv >= *sv)
return false;
59 for(CTPtr pv=begin(); pv!=end(); pv++, sv++)
60 if(*pv <= *sv)
return false;
65 for(CTPtr pv=begin(); pv!=end(); pv++, sv++)
66 if(*pv > *sv)
return false;
71 for(CTPtr pv=begin(); pv!=end(); pv++, sv++)
72 if(*pv < *sv)
return false;
77 for(TPtr pv=begin(); pv!=end(); pv++)
82 for(TPtr pv=begin(); pv!=end(); pv++, rhs++)
88 for(TPtr pv=begin(); pv!=end(); pv++, sv++)
95 for(TPtr pv=begin(); pv!=end(); pv++, sv++)
100 CTPtr sv=rhs.
begin();
101 for(TPtr pv=begin(); pv!=end(); pv++, sv++)
106 CTPtr sv=rhs.
begin();
107 for(TPtr pv=begin(); pv!=end(); pv++, sv++)
112 CTPtr sv=rhs.
begin();
113 for(TPtr pv=begin(); pv!=end(); pv++, sv++)
118 for(TPtr pv=begin(); pv!=end(); pv++)
123 for(TPtr pv=begin(); pv!=end(); pv++)
128 for(TPtr pv=begin(); pv!=end(); pv++)
133 for(TPtr pv=begin(); pv!=end(); pv++)
155 return (VT(*
this) += rhs);
158 return (VT(*
this) -= rhs);
161 return (VT(*
this) *= rhs);
164 return (VT(*
this) /= rhs);
168 CTPtr sv=rhs.
begin();
169 for(TPtr pv=begin(); pv!=end(); pv++, sv++)
174 T
dot(
const VT &rhs)
const {
176 for(CTPtr pv=begin(), *sv=rhs.
begin(); pv!=end(); pv++, sv++)
183 r.
val[0]= val[1]*rhs.
val[2] - val[2]*rhs.
val[1];
184 r.
val[1]= val[2]*rhs.
val[0] - val[0]*rhs.
val[2];
185 r.
val[2]= r.
val[2] = val[0]*rhs.
val[1] - val[1]*rhs.
val[0];
190 for(CTPtr pv=begin(); pv!=end(); pv++)
196 for(CTPtr pv=begin(); pv!=end(); pv++)
202 for(CTPtr pv=begin(); pv!=end(); pv++)
209 operator*=(TTrait::one()/n);
213 T
var()
const {
return (*
this-
avg()).norm2(); }
216 for(TPtr pv=begin(); pv!=end(); pv++)
222 for(CTPtr pv=begin(); pv!=end(); pv++)
223 if(mv < *pv) mv = *pv;
228 for(CTPtr pv=begin(); pv!=end(); pv++)
229 if(mv > *pv) mv = *pv;
234 unsigned int mc=0,cc=0;
235 for(CTPtr pv=begin(); pv!=end(); pv++, cc++) {
237 if(mv < apv) { mv = apv; mc = cc; }
243 for(TPtr pv=begin(); pv!=end(); pv++, sv++)
244 if(*pv < *sv) *pv = *sv;
249 for(TPtr pv=begin(); pv!=end(); pv++, sv++)
250 if(*pv > *sv) *pv = *sv;
253 VT&
clamp(
const VT &lb,
const VT &ub) {
256 for(TPtr pv=begin(); pv!=end(); pv++, sv++, uv++) {
257 if(*pv > *uv) *pv = *uv;
258 else if(*pv < *sv) *pv = *sv;
263 float dv = cross(rhs).norm();
265 #ifndef _THERE_IS_NO_ATAN2_ 276 float dhn = (dh < 0) ? 1.0 : 0.0;
279 psi = M_PI_2 * (dvp + 3.0 * dvn);
283 psi = atan(dv/dh) +
M_PI * dhn * dvp
285 return psi * (180.0*
M_1_PI);
289 friend std::ostream&
operator<<(std::ostream& os,
const VT& rhs) {
290 for(CTPtr pv= rhs.
begin(); pv != rhs.
end(); pv++) {
297 for(TPtr pv=rhs.
begin(); pv!=rhs.
end(); pv++) {
308 float static zero() {
return 0.f; };
309 float static one() {
return 1.f; };
313 double static zero() {
return 0.; };
314 double static one() {
return 1.; };
317 #endif // _VVECTOR_H_ VT operator/(const T &rhs) const
VT & operator*=(const T &rhs)
VT & operator=(const T &rhs)
VT & operator=(const VT &rhs)
bool operator>=(const VT &rhs) const
VT operator*(const VT &rhs) const
bool operator<=(const VT &rhs) const
VT & operator+=(const VT &rhs)
DMatrix< T > var(const DMatrix< T > &mat)
VT & clamp(const VT &lb, const VT &ub)
float angle(const VT &rhs) const
VT & operator/=(const VT &rhs)
VT & times(const VT &rhs)
VT operator+(const VT &rhs) const
T & operator[](unsigned int i)
VT & clampUB(const VT &ub)
VT operator-(const VT &rhs) const
bool operator==(const VT &rhs) const
DMatrix< T > & abs(DMatrix< T > &mat)
bool operator<(const VT &rhs) const
DMatrix< T > sum(const DMatrix< T > &mat)
bool operator>(const VT &rhs) const
VT & operator+=(const T &rhs)
VT & operator-=(const T &rhs)
const T & operator[](unsigned int i) const
VT & clampLB(const VT &lb)
T dot(const VT &rhs) const
VVector< T, 3 > cross(const VVector< T, 3 > &rhs) const
VT operator-(const T &rhs) const
VT & operator*=(const VT &rhs)
unsigned int majorComponent() const
VT & operator-=(const VT &rhs)
DMatrix< T > avg(const DMatrix< T > &mat)
VT operator+(const T &rhs) const
VT & operator=(CTPtr rhs)
VT operator*(const T &rhs) const
VT operator/(const VT &rhs) const
friend std::istream & operator>>(std::istream &is, VT &rhs)
friend std::ostream & operator<<(std::ostream &os, const VT &rhs)
static unsigned int size()
DMatrix< T > & sqrt(DMatrix< T > &mat)
VT & operator/=(const T &rhs)