1 #include "arrcmp.h"
2 //#include "DDaceSamplePoint.h"
3 #include <math.h>
4
5 ///////////////////////////
6 // Written By: J Cramp
7 // Date: May 2004
8 ///////////////////////////
9
Arrcmp_d(std::vector<double> & a,std::vector<double> & b)10 int Arrcmp_d( std::vector<double>& a, std::vector<double>& b )
11 {
12 int len_a = a.size();
13 int len_b = b.size();
14
15 if( len_a != len_b )
16 {
17 return 1; // failed!
18 }
19
20 for( int i = 0; i < len_a; i++ )
21 {
22 if( a[i] != b[i] )
23 {
24 return 1; // failed!
25 }
26 }
27
28 return 0; // success!
29 }
30
Arrcmp_d_est(std::vector<double> & a,std::vector<double> & b,const float errlim)31 int Arrcmp_d_est( std::vector<double>& a,
32 std::vector<double>& b,
33 const float errlim )
34 {
35 int len_a = a.size();
36 int len_b = b.size();
37
38 if( len_a != len_b )
39 {
40 return 1; // failed!
41 }
42
43 for( int i = 0; i < len_a; i++ )
44 {
45 //if( abs(a[i] - b[i]) >= errlim )
46 //{
47 // return 1; // failed!
48 //}
49 if (a[i] >= b[i]) {
50 if ((a[i] - b[i]) >= errlim)
51 return 1; // failed!
52 } else {
53 if ((b[i] - a[i]) >= errlim)
54 return 1; // failed!
55 }
56
57
58 }
59
60 return 0; // success!
61 }
62
Arrcmp_i(std::vector<std::vector<int>> & a,std::vector<std::vector<int>> & b)63 int Arrcmp_i( std::vector<std::vector<int> >& a,
64 std::vector<std::vector<int> >& b )
65 {
66 int len_a = a.size();
67 int len_b = b.size();
68
69 if( len_a != len_b )
70 {
71 return 1; // failed!
72 }
73
74 for( int i = 0; i < len_a; i++ )
75 {
76 if( a[i].size() != b[i].size() )
77 {
78 return 1; // failed!
79 }
80 for( int j = 0; j < (int) a[i].size(); j++ )
81 {
82 if( a[i][j] != b[i][j] )
83 {
84 return 1; // failed!
85 }
86 }
87 }
88
89 return 0; // success!
90 }
91
Arrcmp_ad(std::vector<DDaceSamplePoint> & a,std::vector<std::vector<double>> & b)92 int Arrcmp_ad( std::vector<DDaceSamplePoint>& a,
93 std::vector< std::vector<double> >& b )
94 {
95 int len_a = a.size();
96 int len_b = b.size();
97
98 if( len_a != len_b )
99 {
100 return 1; // failed!
101 }
102
103 for( int i = 0; i < len_a; i++ )
104 {
105 if( a[i].length() != (int) b[i].size() )
106 {
107 return 1; // failed!
108 }
109 for( int j = 0; j < a[i].length(); j++ )
110 {
111 if( a[i][j] != b[i][j] )
112 {
113 return 1; // failed!
114 }
115 }
116 }
117
118 return 0; // success!
119 }
120
Arrcmp_ad_est(std::vector<DDaceSamplePoint> & a,std::vector<std::vector<double>> & b,const float errlim)121 int Arrcmp_ad_est( std::vector<DDaceSamplePoint>& a,
122 std::vector< std::vector<double> >& b,
123 const float errlim )
124 {
125 int len_a = a.size();
126 int len_b = b.size();
127
128 if( len_a != len_b )
129 {
130 return 1; // failed!
131 }
132
133 for( int i = 0; i < len_a; i++ )
134 {
135 if( a[i].length() != (int) b[i].size() )
136 {
137 return 1; // failed!
138 }
139 for( int j = 0; j < a[i].length(); j++ )
140 {
141 if( !closeEnough( a[i][j], b[i][j], errlim ) )
142 {
143 return 1; // failed!
144 }
145 }
146 }
147
148 return 0; // success!
149 }
150
DDaceSamplePoint_cmp(const DDaceSamplePoint & a,const DDaceSamplePoint & b)151 int DDaceSamplePoint_cmp( const DDaceSamplePoint& a, const DDaceSamplePoint& b )
152 {
153 int len_a = a.length();
154 int len_b = b.length();
155
156 if( len_a != len_b )
157 {
158 return 1; // Failed! sample points not the same
159 }
160
161 for( int i = 0; i < len_a; i++ )
162 {
163 if( a[i] != b[i] )
164 {
165 return 1; // Failed! sample points not the same
166 }
167 }
168
169 return 0; // Success! sample points are the same
170 }
171
172 // itoa is a native windows function
173 #ifndef _MSC_VER
itoa(int n,char buf[],const int size)174 void itoa( int n, char buf[], const int size )
175 {
176 int c = 0;
177 int tmp;
178 double i;
179 const char* alpha = "0123456789";
180
181 // determine highest power of 10 needed
182 i = -1;
183 while( (n/pow(10.0,++i)) > 1 )
184 ;
185
186 // i is one too big
187 i--;
188
189 // map each digit to its character
190 for( ; i >= 0 && c < size; i-- )
191 {
192 tmp = (n/((int)pow(10.0,i)));
193 buf[c++] = alpha[tmp];
194 n -= (tmp * ((int)pow(10.0,i)));
195 }
196
197 // insert null character
198 buf[c] = '\0';
199 }
200 #endif
201
closeEnough(double a,double b,const float errlim)202 bool closeEnough( double a, double b, const float errlim )
203 {
204 if( a > b )
205 {
206 return (a-b < errlim);
207 }
208 return (b-a < errlim );
209 }
210
211
212
213