2 #define No_Standard_RangeError
3 #define No_Standard_OutOfRange
4 #define No_Standard_DimensionError
9 #include <math_Vector.ixx>
10 #include <math_Matrix.hxx>
12 #include <Standard_DimensionError.hxx>
13 #include <Standard_DivideByZero.hxx>
14 #include <Standard_RangeError.hxx>
15 #include <Standard_NullValue.hxx>
18 math_Vector::math_Vector(const Standard_Integer Lower,
19 const Standard_Integer Upper):
24 Standard_RangeError_Raise_if(Lower > Upper, "");
27 math_Vector::math_Vector(const Standard_Integer Lower,
28 const Standard_Integer Upper,
29 const Standard_Real InitialValue):
35 Standard_RangeError_Raise_if(Lower > Upper, "");
36 Array.Init(InitialValue);
39 math_Vector::math_Vector(const Standard_Address Tab,
40 const Standard_Integer Lower,
41 const Standard_Integer Upper) :
45 Array(*((const Standard_Real *)Tab), Lower,Upper)
47 Standard_RangeError_Raise_if((Lower > Upper) , "");
50 void math_Vector::Init(const Standard_Real InitialValue) {
51 Array.Init(InitialValue);
54 math_Vector::math_Vector(const math_Vector& Other):
56 LowerIndex(Other.LowerIndex),
57 UpperIndex(Other.UpperIndex),
61 void math_Vector::SetLower(const Standard_Integer Lower) {
63 Array.SetLower(Lower);
64 UpperIndex = UpperIndex - LowerIndex + Lower;
68 Standard_Real math_Vector::Norm() const {
70 Standard_Real Result = 0;
72 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
73 Result = Result + Array(Index) * Array(Index);
78 Standard_Real math_Vector::Norm2() const {
80 Standard_Real Result = 0;
82 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
83 Result = Result + Array(Index) * Array(Index);
88 Standard_Integer math_Vector::Max() const {
91 Standard_Real X = RealFirst();
93 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
94 if(Array(Index) > X) {
102 Standard_Integer math_Vector::Min() const {
104 Standard_Integer I=0;
105 Standard_Real X = RealLast();
107 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
108 if(Array(Index) < X) {
116 void math_Vector::Set(const Standard_Integer I1,
117 const Standard_Integer I2,
118 const math_Vector &V) {
120 Standard_RangeError_Raise_if((I1 < LowerIndex) ||
123 (I2 - I1 + 1 != V.Length()), "");
125 Standard_Integer I = V.Lower();
126 for(Standard_Integer Index = I1; Index <= I2; Index++) {
127 Array(Index) = V.Array(I);
132 void math_Vector::Normalize() {
134 Standard_Real Result = Norm();
135 Standard_NullValue_Raise_if((Result <= RealEpsilon()), "");
136 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
137 Array(Index) = Array(Index) / Result;
141 math_Vector math_Vector::Normalized() const {
143 math_Vector Result = *this;
149 void math_Vector::Invert() {
152 for(Standard_Integer Index = LowerIndex;
153 // Index <= LowerIndex + (Length()) >> 1 ; Index++) {
154 Index <= (LowerIndex + Length()) >> 1 ; Index++) {
155 J = UpperIndex + LowerIndex - Index;
157 Array(Index) = Array(J);
162 math_Vector math_Vector::Inverse() const {
163 math_Vector Result = *this;
168 math_Vector math_Vector::Multiplied(const Standard_Real Right) const{
170 math_Vector Result (LowerIndex, UpperIndex);
172 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
173 Result.Array(Index) = Array(Index) * Right;
178 math_Vector math_Vector::TMultiplied(const Standard_Real Right) const{
180 math_Vector Result (LowerIndex, UpperIndex);
182 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
183 Result.Array(Index) = Array(Index) * Right;
189 void math_Vector::Multiply(const Standard_Real Right) {
191 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
192 Array(Index) = Array(Index) * Right;
197 void math_Vector::Divide(const Standard_Real Right) {
199 Standard_DivideByZero_Raise_if(Abs(Right) <= RealEpsilon(), "");
201 for(Standard_Integer Index =LowerIndex; Index <=UpperIndex; Index++) {
202 Array(Index) = Array(Index) / Right;
207 math_Vector math_Vector::Divided (const Standard_Real Right) const {
209 Standard_DivideByZero_Raise_if(Abs(Right) <= RealEpsilon(), "");
210 math_Vector temp = Multiplied(1./Right);
215 void math_Vector::Add(const math_Vector& Right) {
217 Standard_DimensionError_Raise_if(Length() != Right.Length(), "");
219 Standard_Integer I = Right.LowerIndex;
220 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
221 Array(Index) = Array(Index) + Right.Array(I);
226 math_Vector math_Vector::Added(const math_Vector& Right) const{
228 Standard_DimensionError_Raise_if(Length() != Right.Length(), "");
230 math_Vector Result(LowerIndex, UpperIndex);
232 Standard_Integer I = Right.LowerIndex;
233 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
234 Result.Array(Index) = Array(Index) + Right.Array(I);
242 void math_Vector::Subtract(const math_Vector& Right) {
244 Standard_DimensionError_Raise_if(Length() != Right.Length(), "");
246 Standard_Integer I = Right.LowerIndex;
247 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
248 Array(Index) = Array(Index) - Right.Array(I);
254 math_Vector math_Vector::Subtracted (const math_Vector& Right) const {
256 Standard_DimensionError_Raise_if(Length() != Right.Length(), "");
258 math_Vector Result(LowerIndex, UpperIndex);
260 Standard_Integer I = Right.LowerIndex;
261 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
262 Result.Array(Index) = Array(Index) - Right.Array(I);
269 math_Vector math_Vector::Slice(const Standard_Integer I1,
270 const Standard_Integer I2) const
273 Standard_RangeError_Raise_if((I1 < LowerIndex) ||
276 (I2 > UpperIndex) , "");
280 math_Vector Result(I1, I2);
281 for(Standard_Integer Index = I1; Index <= I2; Index++) {
282 Result.Array(Index) = Array(Index);
287 math_Vector Result(I2, I1);
288 for(Standard_Integer Index = I1; Index >= I2; Index--) {
289 Result.Array(Index) = Array(Index);
296 void math_Vector::Add (const math_Vector& Left, const math_Vector& Right) {
298 Standard_DimensionError_Raise_if((Length() != Right.Length()) ||
299 (Right.Length() != Left.Length()), "");
302 Standard_Integer I = Left.LowerIndex;
303 Standard_Integer J = Right.LowerIndex;
304 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
305 Array(Index) = Left.Array(I) + Right.Array(J);
311 void math_Vector::Subtract (const math_Vector& Left,
312 const math_Vector& Right) {
314 Standard_DimensionError_Raise_if((Length() != Right.Length()) ||
315 (Right.Length() != Left.Length()), "");
317 Standard_Integer I = Left.LowerIndex;
318 Standard_Integer J = Right.LowerIndex;
319 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
320 Array(Index) = Left.Array(I) - Right.Array(J);
326 void math_Vector::Multiply(const math_Matrix& Left,
327 const math_Vector& Right) {
329 Standard_DimensionError_Raise_if((Length() != Left.RowNumber()) ||
330 (Left.ColNumber() != Right.Length()),
333 Standard_Integer Index = LowerIndex;
334 for(Standard_Integer I = Left.LowerRowIndex; I <= Left.UpperRowIndex; I++) {
336 Standard_Integer K = Right.LowerIndex;
337 for(Standard_Integer J = Left.LowerColIndex; J <= Left.UpperColIndex; J++) {
338 Array(Index) = Array(Index) + Left.Array(I, J) * Right.Array(K);
345 void math_Vector::Multiply(const math_Vector& Left,
346 const math_Matrix& Right) {
348 Standard_DimensionError_Raise_if((Length() != Right.ColNumber()) ||
349 (Left.Length() != Right.RowNumber()),
352 Standard_Integer Index = LowerIndex;
353 for(Standard_Integer J = Right.LowerColIndex; J <= Right.UpperColIndex; J++) {
355 Standard_Integer K = Left.LowerIndex;
356 for(Standard_Integer I = Right.LowerRowIndex; I <= Right.UpperRowIndex; I++) {
357 Array(Index) = Array(Index) + Left.Array(K) * Right.Array(I, J);
364 void math_Vector::TMultiply(const math_Matrix& TLeft,
365 const math_Vector& Right) {
367 Standard_DimensionError_Raise_if((Length() != TLeft.ColNumber()) ||
368 (TLeft.RowNumber() != Right.Length()),
371 Standard_Integer Index = LowerIndex;
372 for(Standard_Integer I = TLeft.LowerColIndex; I <= TLeft.UpperColIndex; I++) {
374 Standard_Integer K = Right.LowerIndex;
375 for(Standard_Integer J = TLeft.LowerRowIndex; J <= TLeft.UpperRowIndex; J++) {
376 Array(Index) = Array(Index) + TLeft.Array(J, I) * Right.Array(K);
383 void math_Vector::TMultiply(const math_Vector& Left,
384 const math_Matrix& TRight) {
386 Standard_DimensionError_Raise_if((Length() != TRight.RowNumber()) ||
387 (Left.Length() != TRight.ColNumber()),
390 Standard_Integer Index = LowerIndex;
391 for(Standard_Integer J = TRight.LowerRowIndex; J <= TRight.UpperRowIndex; J++) {
393 Standard_Integer K = Left.LowerIndex;
394 for(Standard_Integer I = TRight.LowerColIndex;
395 I <= TRight.UpperColIndex; I++) {
396 Array(Index) = Array(Index) + Left.Array(K) * TRight.Array(J, I);
406 Standard_Real math_Vector::Multiplied(const math_Vector& Right) const{
407 Standard_Real Result = 0;
409 Standard_DimensionError_Raise_if(Length() != Right.Length(), "");
411 Standard_Integer I = Right.LowerIndex;
412 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
413 Result = Result + Array(Index) * Right.Array(I);
419 math_Vector math_Vector::Opposite() {
420 math_Vector Result(LowerIndex, UpperIndex);
422 for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
423 Result.Array(Index) = - Array(Index);
428 math_Vector math_Vector::Multiplied(const math_Matrix& Right)const {
429 Standard_DimensionError_Raise_if(Length() != Right.RowNumber(), "");
431 math_Vector Result(Right.LowerColIndex, Right.UpperColIndex);
432 for(Standard_Integer J2 = Right.LowerColIndex;
433 J2 <= Right.UpperColIndex; J2++) {
435 Standard_Integer I2 = Right.LowerRowIndex;
436 for(Standard_Integer I = LowerIndex; I <= UpperIndex; I++) {
437 Result.Array(J2) = Result.Array(J2) + Array(I) *
446 void math_Vector::Multiply(const Standard_Real Left,
447 const math_Vector& Right)
449 Standard_DimensionError_Raise_if((Length() != Right.Length()),
451 for(Standard_Integer I = LowerIndex; I <= UpperIndex; I++) {
452 Array(I) = Left * Right.Array(I);
457 math_Vector& math_Vector::Initialized(const math_Vector& Other) {
459 Standard_DimensionError_Raise_if(Length() != Other.Length(), "");
461 (Other.Array).Copy(Array);
467 void math_Vector::Dump(Standard_OStream& o) const
469 o << "math_Vector of Length = " << Length() << "\n";
470 for(Standard_Integer Index = LowerIndex;
471 Index <= UpperIndex; Index++) {
472 o << "math_Vector(" << Index << ") = " << Array(Index) << "\n";