46 #ifndef _PEXSI_TINYVEC_HPP_
47 #define _PEXSI_TINYVEC_HPP_
64 enum{ X=0, Y=1, Z=2 };
66 Vec3T() { v_[0]=F(0); v_[1]=F(0); v_[2]=F(0); }
67 Vec3T(
const F* f) { v_[0]=f[0]; v_[1]=f[1]; v_[2]=f[2]; }
68 Vec3T(
const F a,
const F b,
const F c) { v_[0]=a; v_[1]=b; v_[2]=c; }
69 Vec3T(
const Vec3T& c){ v_[0]=c.v_[0]; v_[1]=c.v_[1]; v_[2]=c.v_[2]; }
72 operator F*() {
return &v_[0]; }
73 operator const F*()
const {
return &v_[0]; }
74 F* Data() {
return &v_[0]; }
76 const F& operator()(Int i)
const;
78 const F& operator[](Int i)
const;
80 Vec3T& operator= (
const Vec3T& c ) { v_[0] =c.v_[0]; v_[1] =c.v_[1]; v_[2] =c.v_[2];
return *
this; }
81 Vec3T& operator+=(
const Vec3T& c ) { v_[0]+=c.v_[0]; v_[1]+=c.v_[1]; v_[2]+=c.v_[2];
return *
this; }
82 Vec3T& operator-=(
const Vec3T& c ) { v_[0]-=c.v_[0]; v_[1]-=c.v_[1]; v_[2]-=c.v_[2];
return *
this; }
83 Vec3T& operator*=(
const F& s ) { v_[0]*=s; v_[1]*=s; v_[2]*=s;
return *
this; }
84 Vec3T& operator/=(
const F& s ) { v_[0]/=s; v_[1]/=s; v_[2]/=s;
return *
this; }
86 F l1(
void )
const { F sum=F(0);
for(Int i=0; i<3; i++) sum=sum+std::abs(v_[i]);
return sum; }
87 F linfty(
void )
const { F cur=F(0);
for(Int i=0; i<3; i++) cur=std::max(cur,std::abs(v_[i]));
return cur; }
88 F l2(
void )
const { F sum=F(0);
for(Int i=0; i<3; i++) sum=sum+v_[i]*v_[i];
return sqrt(sum); }
100 template <
class F>
inline bool operator==(
const Vec3T<F>& a,
const Vec3T<F>& b) {
101 return (a[0]==b[0] && a[1]==b[1] && a[2]==b[2]);
103 template <
class F>
inline bool operator!=(
const Vec3T<F>& a,
const Vec3T<F>& b) {
106 template <
class F>
inline bool operator> (
const Vec3T<F>& a,
const Vec3T<F>& b) {
107 for(Int i=0; i<3; i++) {
108 if( a[i]>b[i])
return true;
109 else if(a[i]<b[i])
return false;
113 template <
class F>
inline bool operator< (const Vec3T<F>& a,
const Vec3T<F>& b) {
114 for(Int i=0; i<3; i++) {
115 if( a[i]<b[i])
return true;
116 else if(a[i]>b[i])
return false;
120 template <
class F>
inline bool operator>=(
const Vec3T<F>& a,
const Vec3T<F>& b) {
121 for(Int i=0; i<3; i++) {
122 if( a[i]>b[i])
return true;
123 else if(a[i]<b[i])
return false;
127 template <
class F>
inline bool operator<=(const Vec3T<F>& a,
const Vec3T<F>& b) {
128 for(Int i=0; i<3; i++) {
129 if( a[i]<b[i])
return true;
130 else if(a[i]>b[i])
return false;
138 template <
class F>
inline Vec3T<F> operator- (
const Vec3T<F>& a) {
139 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = -a[i];
return r;
141 template <
class F>
inline Vec3T<F> operator+ (
const Vec3T<F>& a,
const Vec3T<F>& b) {
142 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = a[i]+b[i];
return r;
144 template <
class F>
inline Vec3T<F> operator- (
const Vec3T<F>& a,
const Vec3T<F>& b) {
145 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = a[i]-b[i];
return r;
147 template <
class F>
inline Vec3T<F> operator* (F scl,
const Vec3T<F>& a) {
148 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = scl*a[i];
return r;
150 template <
class F>
inline Vec3T<F> operator* (
const Vec3T<F>& a, F scl) {
151 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = scl*a[i];
return r;
153 template <
class F>
inline Vec3T<F> operator/ (
const Vec3T<F>& a, F scl) {
154 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = a[i]/scl;
return r;
156 template <
class F>
inline F operator* (
const Vec3T<F>& a,
const Vec3T<F>& b) {
157 F sum=F(0);
for(Int i=0; i<3; i++) sum=sum+a(i)*b(i);
return sum;
159 template <
class F>
inline F dot (
const Vec3T<F>& a,
const Vec3T<F>& b) {
162 template <
class F>
inline Vec3T<F> operator^ (
const Vec3T<F>& a,
const Vec3T<F>& b) {
163 return Vec3T<F>(a(1)*b(2)-a(2)*b(1), a(2)*b(0)-a(0)*b(2), a(0)*b(1)-a(1)*b(0));
165 template <
class F>
inline Vec3T<F> cross (
const Vec3T<F>& a,
const Vec3T<F>& b) {
172 template <
class F>
inline Vec3T<F> ewmin(
const Vec3T<F>& a,
const Vec3T<F>& b) {
173 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = std::min(a[i], b[i]);
return r;
175 template <
class F>
inline Vec3T<F> ewmax(
const Vec3T<F>& a,
const Vec3T<F>& b) {
176 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = std::max(a[i], b[i]);
return r;
178 template <
class F>
inline Vec3T<F> ewabs(
const Vec3T<F>& a) {
179 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = std::abs(a[i]);
return r;
181 template <
class F>
inline Vec3T<F> ewmul(
const Vec3T<F>&a,
const Vec3T<F>& b) {
182 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = a[i]*b[i];
return r;
184 template <
class F>
inline Vec3T<F> ewdiv(
const Vec3T<F>&a,
const Vec3T<F>& b) {
185 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = a[i]/b[i];
return r;
187 template <
class F>
inline Vec3T<F> ewrnd(
const Vec3T<F>&a) {
188 Vec3T<F> r;
for(Int i=0; i<3; i++) r[i] = round(a[i]);
return r;
194 template <
class F>
inline bool allequ(
const Vec3T<F>& a,
const Vec3T<F>& b) {
195 bool res =
true;
for(Int i=0; i<3; i++) res = res && (a(i)==b(i));
return res;
197 template <
class F>
inline bool allneq(
const Vec3T<F>& a,
const Vec3T<F>& b) {
200 template <
class F>
inline bool allgtt(
const Vec3T<F>& a,
const Vec3T<F>& b) {
201 bool res =
true;
for(Int i=0; i<3; i++) res = res && (a(i)> b(i));
return res;
203 template <
class F>
inline bool alllst(
const Vec3T<F>& a,
const Vec3T<F>& b) {
204 bool res =
true;
for(Int i=0; i<3; i++) res = res && (a(i)< b(i));
return res;
206 template <
class F>
inline bool allgoe(
const Vec3T<F>& a,
const Vec3T<F>& b) {
207 bool res =
true;
for(Int i=0; i<3; i++) res = res && (a(i)>=b(i));
return res;
209 template <
class F>
inline bool allloe(
const Vec3T<F>& a,
const Vec3T<F>& b) {
210 bool res =
true;
for(Int i=0; i<3; i++) res = res && (a(i)<=b(i));
return res;
217 template <
class F> std::istream& operator>>(std::istream& is, Vec3T<F>& a) {
218 for(Int i=0; i<3; i++) is>>a[i];
return is;
220 template <
class F> std::ostream& operator<<(std::ostream& os, const Vec3T<F>& a) {
221 for(Int i=0; i<3; i++) os<<a[i]<<
" ";
return os;
230 #endif // _PEXSI_TINYVEC_HPP_
Tiny vectors of dimension 3.
Definition: tinyvec.hpp:60
Implementation of tiny vectors.