1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #define No_Standard_RangeError
16 #define No_Standard_OutOfRange
17 #define No_Standard_DimensionError
19 #include <math_IntegerVector.hxx>
21 #include <Standard_DimensionError.hxx>
22 #include <Standard_RangeError.hxx>
24 math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast) :
27 Array(theFirst, theLast)
29 Standard_RangeError_Raise_if(theFirst > theLast, " ");
32 math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst,
33 const Standard_Integer theLast,
34 const Standard_Integer theInitialValue) :
37 Array(theFirst, theLast)
39 Standard_RangeError_Raise_if(theFirst > theLast, " ");
40 Array.Init(theInitialValue);
43 math_IntegerVector::math_IntegerVector(const Standard_Address theTab,
44 const Standard_Integer theFirst,
45 const Standard_Integer theLast) :
48 Array(theTab, theFirst, theLast)
50 Standard_RangeError_Raise_if(theFirst > theLast, " ");
53 void math_IntegerVector::Init(const Standard_Integer theInitialValue)
55 Array.Init(theInitialValue);
58 math_IntegerVector::math_IntegerVector(const math_IntegerVector& theOther) :
59 FirstIndex(theOther.FirstIndex),
60 LastIndex(theOther.LastIndex),
65 void math_IntegerVector::SetFirst(const Standard_Integer theFirst)
67 Array.SetLower(theFirst);
68 LastIndex = LastIndex - FirstIndex + theFirst;
69 FirstIndex = theFirst;
72 Standard_Real math_IntegerVector::Norm() const
74 Standard_Real Result = 0;
75 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
77 Result = Result + Array(Index) * Array(Index);
82 Standard_Real math_IntegerVector::Norm2() const
84 Standard_Real Result = 0;
85 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
87 Result = Result + Array(Index) * Array(Index);
92 Standard_Integer math_IntegerVector::Max() const
95 Standard_Real X = RealFirst();
96 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
107 Standard_Integer math_IntegerVector::Min() const
109 Standard_Integer I=0;
110 Standard_Real X = RealLast();
111 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
122 void math_IntegerVector::Invert()
125 Standard_Integer Temp;
127 for(Standard_Integer Index = FirstIndex; Index <= FirstIndex + Length() / 2 ; Index++)
129 J = LastIndex + FirstIndex - Index;
131 Array(Index) = Array(J);
136 math_IntegerVector math_IntegerVector::Inverse() const
138 math_IntegerVector Result = *this;
143 void math_IntegerVector::Set(const Standard_Integer theI1,
144 const Standard_Integer theI2,
145 const math_IntegerVector &theV)
147 Standard_DimensionError_Raise_if((theI1 < FirstIndex) || (theI2 > LastIndex) ||
148 (theI1 > theI2) || (theI2 - theI1 + 1 != theV.Length()), " ");
150 Standard_Integer I = theV.Lower();
151 for(Standard_Integer Index = theI1; Index <= theI2; Index++)
153 Array(Index) = theV.Array(I);
158 void math_IntegerVector::Multiply(const Standard_Integer theRight)
160 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
162 Array(Index) = Array(Index) * theRight;
166 void math_IntegerVector::Add(const math_IntegerVector& theRight)
168 Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
170 Standard_Integer I = theRight.FirstIndex;
171 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
173 Array(Index) = Array(Index) + theRight.Array(I);
178 void math_IntegerVector::Subtract(const math_IntegerVector& theRight)
180 Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
181 Standard_Integer I = theRight.FirstIndex;
182 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
184 Array(Index) = Array(Index) - theRight.Array(I);
189 math_IntegerVector math_IntegerVector::Slice(const Standard_Integer theI1,
190 const Standard_Integer theI2) const
192 Standard_DimensionError_Raise_if((theI1 < FirstIndex) || (theI1 > LastIndex) ||
193 (theI2 < FirstIndex) || (theI2 > LastIndex), " ");
197 math_IntegerVector Result(theI1, theI2);
198 for(Standard_Integer Index = theI1; Index <= theI2; Index++)
200 Result.Array(Index) = Array(Index);
206 math_IntegerVector Result(theI2, theI1);
207 for(Standard_Integer Index = theI1; Index >= theI2; Index--)
209 Result.Array(Index) = Array(Index);
215 Standard_Integer math_IntegerVector::Multiplied (const math_IntegerVector& theRight) const
217 Standard_Integer Result = 0;
219 Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
221 Standard_Integer I = theRight.FirstIndex;
222 for(Standard_Integer Index = 0; Index < Length(); Index++)
224 Result = Result + Array(Index) * theRight.Array(I);
230 math_IntegerVector math_IntegerVector::Multiplied (const Standard_Integer theRight)const
232 math_IntegerVector Result(FirstIndex, LastIndex);
234 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
236 Result.Array(Index) = Array(Index) * theRight;
241 math_IntegerVector math_IntegerVector::TMultiplied (const Standard_Integer theRight) const
243 math_IntegerVector Result(FirstIndex, LastIndex);
245 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
247 Result.Array(Index) = Array(Index) * theRight;
252 math_IntegerVector math_IntegerVector::Added (const math_IntegerVector& theRight) const
254 Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
256 math_IntegerVector Result(FirstIndex, LastIndex);
258 Standard_Integer I = theRight.FirstIndex;
259 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
261 Result.Array(Index) = Array(Index) + theRight.Array(I);
267 math_IntegerVector math_IntegerVector::Opposite()
269 math_IntegerVector Result(FirstIndex, LastIndex);
271 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
273 Result.Array(Index) = - Array(Index);
278 math_IntegerVector math_IntegerVector::Subtracted (const math_IntegerVector& theRight) const
280 Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
282 math_IntegerVector Result(FirstIndex, LastIndex);
284 Standard_Integer I = theRight.FirstIndex;
285 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
287 Result.Array(Index) = Array(Index) - theRight.Array(I);
293 void math_IntegerVector::Add (const math_IntegerVector& theLeft, const math_IntegerVector& theRight)
295 Standard_DimensionError_Raise_if((Length() != theRight.Length()) ||
296 (theRight.Length() != theLeft.Length()), " ");
298 Standard_Integer I = theLeft.FirstIndex;
299 Standard_Integer J = theRight.FirstIndex;
300 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
302 Array(Index) = theLeft.Array(I) + theRight.Array(J);
308 void math_IntegerVector::Subtract (const math_IntegerVector& theLeft,
309 const math_IntegerVector& theRight)
311 Standard_DimensionError_Raise_if((Length() != theRight.Length()) ||
312 (theRight.Length() != theLeft.Length()), " ");
314 Standard_Integer I = theLeft.FirstIndex;
315 Standard_Integer J = theRight.FirstIndex;
316 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
318 Array(Index) = theLeft.Array(I) - theRight.Array(J);
324 void math_IntegerVector::Multiply(const Standard_Integer theLeft, const math_IntegerVector& theRight)
326 Standard_DimensionError_Raise_if((Length() != theRight.Length()), " ");
327 for(Standard_Integer I = FirstIndex; I <= LastIndex; I++)
329 Array(I) = theLeft * theRight.Array(I);
333 math_IntegerVector& math_IntegerVector::Initialized(const math_IntegerVector& theOther)
335 Standard_DimensionError_Raise_if(Length() != theOther.Length(), " ");
337 (theOther.Array).Copy(Array);
341 void math_IntegerVector::Dump(Standard_OStream& theO) const
343 theO << "math_IntegerVector of Range = " << Length() << "\n";
344 for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
346 theO << "math_IntegerVector(" << Index << ") = " << Array(Index) << "\n";