0022904: Clean up sccsid variables
[occt.git] / src / math / math_IntegerVector.cxx
CommitLineData
7fd59977 1//#ifndef DEB
2#define No_Standard_RangeError
3#define No_Standard_OutOfRange
4#define No_Standard_DimensionError
5//#endif
6
7#include <math_IntegerVector.ixx>
8
9#include <Standard_DimensionError.hxx>
10#include <Standard_RangeError.hxx>
11
12
13
14math_IntegerVector::math_IntegerVector(const Standard_Integer First,
15 const Standard_Integer Last):
16 FirstIndex(First),
17 LastIndex(Last),
18 Array(First, Last) {
19
20 Standard_RangeError_Raise_if(First > Last, " ");
21}
22
23math_IntegerVector::math_IntegerVector(const Standard_Integer First,
24 const Standard_Integer Last,
25 const Standard_Integer InitialValue):
26 FirstIndex(First),
27 LastIndex(Last),
28 Array(First, Last) {
29
30 Standard_RangeError_Raise_if(First > Last, " ");
31 Array.Init(InitialValue);
32}
33
34
35math_IntegerVector::math_IntegerVector(const Standard_Address Tab,
36 const Standard_Integer First,
37 const Standard_Integer Last) :
38 FirstIndex(First),
39 LastIndex(Last),
40 Array(*((const Standard_Integer *)Tab),
41 First, Last)
42{
43 Standard_RangeError_Raise_if(First > Last, " ");
44}
45
46
47void math_IntegerVector::Init(const Standard_Integer InitialValue)
48{
49 Array.Init(InitialValue);
50}
51
52
53math_IntegerVector::math_IntegerVector(const math_IntegerVector& Other):
54
55 FirstIndex(Other.FirstIndex),
56 LastIndex(Other.LastIndex),
57 Array(Other.Array) {}
58
59
60
61void math_IntegerVector::SetFirst(const Standard_Integer First) {
62
63 Array.SetLower(First);
64 LastIndex = LastIndex - FirstIndex + First;
65 FirstIndex = First;
66}
67
68
69Standard_Real math_IntegerVector::Norm() const {
70 Standard_Real Result = 0;
71 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
72 Result = Result + Array(Index) * Array(Index);
73 }
74 return Sqrt(Result);
75}
76
77
78Standard_Real math_IntegerVector::Norm2() const {
79 Standard_Real Result = 0;
80 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
81 Result = Result + Array(Index) * Array(Index);
82 }
83 return Result;
84}
85
86
87Standard_Integer math_IntegerVector::Max() const {
88 Standard_Integer I=0;
89 Standard_Real X = RealFirst();
90 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
91 if(Array(Index) > X) {
92 X = Array(Index);
93 I = Index;
94 }
95 }
96 return I;
97}
98
99
100Standard_Integer math_IntegerVector::Min() const {
101 Standard_Integer I=0;
102 Standard_Real X = RealLast();
103 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
104 if(Array(Index) < X) {
105 X = Array(Index);
106 I = Index;
107 }
108 }
109 return I;
110}
111
112
113void math_IntegerVector::Invert() {
114
115 Standard_Integer J;
116 Standard_Integer Temp;
117
118 for(Standard_Integer Index = FirstIndex;
119 Index <= FirstIndex + Length() / 2 ; Index++) {
120 J = LastIndex + FirstIndex - Index;
121 Temp = Array(Index);
122 Array(Index) = Array(J);
123 Array(J) = Temp;
124 }
125}
126
127
128math_IntegerVector math_IntegerVector::Inverse() const {
129
130 math_IntegerVector Result = *this;
131 Result.Invert();
132 return Result;
133}
134
135
136void math_IntegerVector::Set(const Standard_Integer I1,
137 const Standard_Integer I2,
138 const math_IntegerVector &V) {
139
140 Standard_DimensionError_Raise_if((I1 < FirstIndex) ||
141 (I2 > LastIndex) ||
142 (I1 > I2) ||
143 (I2 - I1 + 1 != V.Length()), " ");
144
145 Standard_Integer I = V.Lower();
146 for(Standard_Integer Index = I1; Index <= I2; Index++) {
147 Array(Index) = V.Array(I);
148 I++;
149 }
150}
151
152
153void math_IntegerVector::Multiply(const Standard_Integer Right) {
154
155 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
156 Array(Index) = Array(Index) * Right;
157 }
158}
159
160
161void math_IntegerVector::Add(const math_IntegerVector& Right) {
162
163 Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
164
165 Standard_Integer I = Right.FirstIndex;
166 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
167 Array(Index) = Array(Index) + Right.Array(I);
168 I++;
169 }
170}
171
172
173void math_IntegerVector::Subtract(const math_IntegerVector& Right) {
174
175 Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
176 Standard_Integer I = Right.FirstIndex;
177 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
178 Array(Index) = Array(Index) - Right.Array(I);
179 I++;
180 }
181}
182
183
184math_IntegerVector math_IntegerVector::Slice(const Standard_Integer I1,
185 const Standard_Integer I2) const {
186
187 Standard_DimensionError_Raise_if((I1 < FirstIndex) || (I1 > LastIndex) ||
188 (I2 < FirstIndex) || (I2 > LastIndex),
189 " ");
190
191 if(I2 >= I1) {
192 math_IntegerVector Result(I1, I2);
193 for(Standard_Integer Index = I1; Index <= I2; Index++) {
194 Result.Array(Index) = Array(Index);
195 }
196 return Result;
197 }
198 else {
199 math_IntegerVector Result(I2, I1);
200 for(Standard_Integer Index = I1; Index >= I2; Index--) {
201 Result.Array(Index) = Array(Index);
202 }
203 return Result;
204 }
205}
206
207Standard_Integer math_IntegerVector::Multiplied (const math_IntegerVector& Right) const {
208
209 Standard_Integer Result = 0;
210
211 Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
212
213 Standard_Integer I = Right.FirstIndex;
214 for(Standard_Integer Index = 0; Index < Length(); Index++) {
215 Result = Result + Array(Index) * Right.Array(I);
216 I++;
217 }
218 return Result;
219}
220
221
222math_IntegerVector math_IntegerVector::Multiplied (const Standard_Integer Right)const {
223
224 math_IntegerVector Result(FirstIndex, LastIndex);
225
226 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
227 Result.Array(Index) = Array(Index) * Right;
228 }
229 return Result;
230}
231
232math_IntegerVector math_IntegerVector::TMultiplied (const Standard_Integer Right)const {
233
234 math_IntegerVector Result(FirstIndex, LastIndex);
235
236 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
237 Result.Array(Index) = Array(Index) * Right;
238 }
239 return Result;
240}
241
242
243math_IntegerVector math_IntegerVector::Added (const math_IntegerVector& Right) const {
244
245 Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
246
247 math_IntegerVector Result(FirstIndex, LastIndex);
248
249 Standard_Integer I = Right.FirstIndex;
250 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
251 Result.Array(Index) = Array(Index) + Right.Array(I);
252 I++;
253 }
254 return Result;
255}
256
257
258
259math_IntegerVector math_IntegerVector::Opposite() {
260
261 math_IntegerVector Result(FirstIndex, LastIndex);
262
263 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
264 Result.Array(Index) = - Array(Index);
265 }
266 return Result;
267}
268
269
270math_IntegerVector math_IntegerVector::Subtracted (const math_IntegerVector& Right) const {
271
272 Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
273
274 math_IntegerVector Result(FirstIndex, LastIndex);
275
276 Standard_Integer I = Right.FirstIndex;
277 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
278 Result.Array(Index) = Array(Index) - Right.Array(I);
279 I++;
280 }
281 return Result;
282}
283
284void math_IntegerVector::Add (const math_IntegerVector& Left,
285 const math_IntegerVector& Right) {
286
287 Standard_DimensionError_Raise_if((Length() != Right.Length()) ||
288 (Right.Length() != Left.Length()), " ");
289
290 Standard_Integer I = Left.FirstIndex;
291 Standard_Integer J = Right.FirstIndex;
292 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
293 Array(Index) = Left.Array(I) + Right.Array(J);
294 I++;
295 J++;
296 }
297}
298
299
300void math_IntegerVector::Subtract (const math_IntegerVector& Left,
301 const math_IntegerVector& Right) {
302
303 Standard_DimensionError_Raise_if((Length() != Right.Length()) ||
304 (Right.Length() != Left.Length()), " ");
305
306 Standard_Integer I = Left.FirstIndex;
307 Standard_Integer J = Right.FirstIndex;
308 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
309 Array(Index) = Left.Array(I) - Right.Array(J);
310 I++;
311 J++;
312 }
313}
314
315
316void math_IntegerVector::Multiply(const Standard_Integer Left,
317 const math_IntegerVector& Right)
318{
319 Standard_DimensionError_Raise_if((Length() != Right.Length()),
320 " ");
321 for(Standard_Integer I = FirstIndex; I <= LastIndex; I++) {
322 Array(I) = Left * Right.Array(I);
323 }
324}
325
326
327math_IntegerVector& math_IntegerVector::Initialized (const math_IntegerVector& Other) {
328
329 Standard_DimensionError_Raise_if(Length() != Other.Length(), " ");
330
331#ifdef DEB
332 Standard_Integer I = Other.FirstIndex;
333#endif
334 (Other.Array).Copy(Array);
335 return *this;
336}
337
338
339
340void math_IntegerVector::Dump(Standard_OStream& o) const
341{
342 o << "math_IntegerVector of Range = " << Length() << "\n";
343 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
344 o << "math_IntegerVector(" << Index << ") = " << Array(Index) << "\n";
345 }
346}
347
348
349
350
351
352