Debian Codegraph @

sphere_fitting/utils/nvector.hh

raw
1 /////////////////////////////////////////////////////////////
2 // //
3 // Copyright (c) 2007-2017 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.apache.org/licenses/LICENSE-2.0 //
10 // //
11 /////////////////////////////////////////////////////////////
12
13 template<class T,int n>
14 nvector<T,n>::nvector()
15 {}
16
17 template<class T,int n>
18 nvector<T,n>::nvector(const T t)
19 {
20 for(int i=0;i<n;i++){
21 m_data[i]=t;
22 }
23 }
24
25 template<class T,int n>
26 nvector<T,n>::nvector(const nvector& v)
27 {
28 for(int i=0;i<n;i++){
29 m_data[i]=v.m_data[i];
30 }
31 }
32
33 template<class T,int n>
34 nvector<T,n>::~nvector()
35 {}
36
37 template<class T,int n>
38 nvector<T,n>& nvector<T,n>::operator=(const nvector<T,n>& v)
39 {
40 if(&v!=this){
41 for(int i=0;i<n;i++){
42 m_data[i]=v.m_data[i];
43 }
44 }
45 return *this;
46 }
47
48 template<class T,int n>
49 nvector<T,n>& nvector<T,n>::operator-=(const nvector<T,n>& v)
50 {
51 for(int i=0;i<n;i++){
52 m_data[i]-=v.m_data[i];
53 }
54 return *this;
55 }
56
57 template<class T,int n>
58 nvector<T,n>& nvector<T,n>::operator+=(const nvector<T,n>& v)
59 {
60 for(int i=0;i<n;i++){
61 m_data[i]+=v.m_data[i];
62 }
63 return *this;
64 }
65
66 template<class T,int n>
67 nvector<T,n> nvector<T,n>::operator+(const nvector<T,n>& v) const
68 {
69 nvector<T,n> res;
70 for(int i=0;i<n;i++){
71 res.m_data[i]=m_data[i]+v.m_data[i];
72 }
73 return res;
74 }
75
76 template<class T,int n>
77 nvector<T,n> nvector<T,n>::operator-(const nvector<T,n>& v) const
78 {
79 nvector<T,n> res;
80 for(int i=0;i<n;i++){
81 res.m_data[i]=m_data[i]-v.m_data[i];
82 }
83 return res;
84 }
85
86 template<class T,int n>
87 nvector<T,n> operator/(const nvector<T,n>& v, T d)
88 {
89 nvector<T,n> res;
90 for(int i=0;i<n;i++){
91 res.m_data[i]=v.m_data[i]/d;
92 }
93 return res;
94 }
95
96 template<class T,int n>
97 nvector<T,n> nvector<T,n>::unit(int i)
98 {
99 nvector<T,n> res;
100 for(int j=0;j<n;j++){
101 res.m_data[j]=(i==j)? T(1) : T(0);
102 }
103 return res;
104 }
105
106 template<class T,int n>
107 ostream& operator<<(ostream& ost,const nvector<T,n>& v)
108 {
109 ost << "<" << v.m_data[0];
110 for(int i=1;i<n;i++){
111 ost << "," << v.m_data[i];
112 }
113 ost << ">";
114 return ost;
115 }