Warning, /include/opencascade/math_VectorBase.lxx is written in an unsupported language. File is not indexed.
0001 // Copyright (c) 1997-1999 Matra Datavision
0002 // Copyright (c) 1999-2023 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014
0015 #include <Standard_DimensionError.hxx>
0016 #include <Standard_DivideByZero.hxx>
0017 #include <Standard_RangeError.hxx>
0018 #include <Standard_NullValue.hxx>
0019
0020 #include <stdio.h>
0021
0022 template <typename TheItemType>
0023 math_VectorBase<TheItemType>::math_VectorBase(const int theLower, const int theUpper)
0024 : Array(theUpper - theLower + 1 <= math_VectorBase::THE_BUFFER_SIZE
0025 ? NCollection_Array1<TheItemType>(*myBuffer.data(), theLower, theUpper)
0026 : NCollection_Array1<TheItemType>(theLower, theUpper))
0027 {
0028 }
0029
0030 template <typename TheItemType>
0031 math_VectorBase<TheItemType>::math_VectorBase(const int theLower,
0032 const int theUpper,
0033 const TheItemType theInitialValue)
0034 : Array(theUpper - theLower + 1 <= math_VectorBase::THE_BUFFER_SIZE
0035 ? NCollection_Array1<TheItemType>(*myBuffer.data(), theLower, theUpper)
0036 : NCollection_Array1<TheItemType>(theLower, theUpper))
0037 {
0038 Array.Init(theInitialValue);
0039 }
0040
0041 template <typename TheItemType>
0042 math_VectorBase<TheItemType>::math_VectorBase(const TheItemType* theTab,
0043 const int theLower,
0044 const int theUpper)
0045 : Array(*theTab, theLower, theUpper)
0046 {
0047 }
0048
0049 template <typename TheItemType>
0050 math_VectorBase<TheItemType>::math_VectorBase(const gp_XY& theOther)
0051 : Array(*myBuffer.data(), 1, 2)
0052 {
0053 Array(1) = static_cast<TheItemType>(theOther.X());
0054 Array(2) = static_cast<TheItemType>(theOther.Y());
0055 }
0056
0057 template <typename TheItemType>
0058 math_VectorBase<TheItemType>::math_VectorBase(const gp_XYZ& theOther)
0059 : Array(*myBuffer.data(), 1, 3)
0060 {
0061 Array(1) = static_cast<TheItemType>(theOther.X());
0062 Array(2) = static_cast<TheItemType>(theOther.Y());
0063 Array(3) = static_cast<TheItemType>(theOther.Z());
0064 }
0065
0066 template <typename TheItemType>
0067 void math_VectorBase<TheItemType>::Init(const TheItemType theInitialValue)
0068 {
0069 Array.Init(theInitialValue);
0070 }
0071
0072 template <typename TheItemType>
0073 math_VectorBase<TheItemType>::math_VectorBase(const math_VectorBase<TheItemType>& theOther)
0074 : Array(theOther.Array)
0075 {
0076 }
0077
0078 template <typename TheItemType>
0079 math_VectorBase<TheItemType>::math_VectorBase(math_VectorBase<TheItemType>&& theOther) noexcept
0080 : myBuffer{},
0081 Array(theOther.Array.IsDeletable()
0082 ? std::move(theOther.Array)
0083 : (theOther.Length() <= math_VectorBase::THE_BUFFER_SIZE
0084 ? NCollection_Array1<TheItemType>(*myBuffer.data(),
0085 theOther.Lower(),
0086 theOther.Upper())
0087 : NCollection_Array1<TheItemType>(theOther.Lower(), theOther.Upper())))
0088 {
0089 if (!theOther.Array.IsEmpty())
0090 {
0091 Array.Assign(theOther.Array);
0092 }
0093 }
0094
0095 template <typename TheItemType>
0096 void math_VectorBase<TheItemType>::SetLower(const int theLower)
0097 {
0098 Array.UpdateLowerBound(theLower);
0099 }
0100
0101 template <typename TheItemType>
0102 double math_VectorBase<TheItemType>::Norm() const
0103 {
0104 const int aLen = Length();
0105 const TheItemType* aPtr = &Array(Lower());
0106 double aSum1 = 0.0, aSum2 = 0.0, aSum3 = 0.0, aSum4 = 0.0;
0107 int i = 0;
0108 int aLen4 = aLen - 3;
0109
0110 for (; i < aLen4; i += 4)
0111 {
0112 const double aVal0 = static_cast<double>(aPtr[i]);
0113 const double aVal1 = static_cast<double>(aPtr[i + 1]);
0114 const double aVal2 = static_cast<double>(aPtr[i + 2]);
0115 const double aVal3 = static_cast<double>(aPtr[i + 3]);
0116 aSum1 += aVal0 * aVal0;
0117 aSum2 += aVal1 * aVal1;
0118 aSum3 += aVal2 * aVal2;
0119 aSum4 += aVal3 * aVal3;
0120 }
0121
0122 for (; i < aLen; ++i)
0123 {
0124 const double aVal = static_cast<double>(aPtr[i]);
0125 aSum1 += aVal * aVal;
0126 }
0127
0128 return std::sqrt((aSum1 + aSum2) + (aSum3 + aSum4));
0129 }
0130
0131 template <typename TheItemType>
0132 double math_VectorBase<TheItemType>::Norm2() const
0133 {
0134 const int aLen = Length();
0135 const TheItemType* aPtr = &Array(Lower());
0136 double aSum1 = 0.0, aSum2 = 0.0, aSum3 = 0.0, aSum4 = 0.0;
0137 int i = 0;
0138 int aLen4 = aLen - 3;
0139
0140 for (; i < aLen4; i += 4)
0141 {
0142 const double aVal0 = static_cast<double>(aPtr[i]);
0143 const double aVal1 = static_cast<double>(aPtr[i + 1]);
0144 const double aVal2 = static_cast<double>(aPtr[i + 2]);
0145 const double aVal3 = static_cast<double>(aPtr[i + 3]);
0146 aSum1 += aVal0 * aVal0;
0147 aSum2 += aVal1 * aVal1;
0148 aSum3 += aVal2 * aVal2;
0149 aSum4 += aVal3 * aVal3;
0150 }
0151
0152 for (; i < aLen; ++i)
0153 {
0154 const double aVal = static_cast<double>(aPtr[i]);
0155 aSum1 += aVal * aVal;
0156 }
0157
0158 return (aSum1 + aSum2) + (aSum3 + aSum4);
0159 }
0160
0161 template <typename TheItemType>
0162 int math_VectorBase<TheItemType>::Max() const
0163 {
0164 int I = 0;
0165 double X = RealFirst();
0166
0167 for (int Index = Lower(); Index <= Upper(); Index++)
0168 {
0169 if (Array(Index) > X)
0170 {
0171 X = Array(Index);
0172 I = Index;
0173 }
0174 }
0175 return I;
0176 }
0177
0178 template <typename TheItemType>
0179 int math_VectorBase<TheItemType>::Min() const
0180 {
0181 int I = 0;
0182 double X = RealLast();
0183
0184 for (int Index = Lower(); Index <= Upper(); Index++)
0185 {
0186 if (Array(Index) < X)
0187 {
0188 X = Array(Index);
0189 I = Index;
0190 }
0191 }
0192 return I;
0193 }
0194
0195 template <typename TheItemType>
0196 void math_VectorBase<TheItemType>::Set(const int theI1,
0197 const int theI2,
0198 const math_VectorBase<TheItemType>& theV)
0199 {
0200 Standard_RangeError_Raise_if((theI1 < Lower()) || (theI2 > Upper()) || (theI1 > theI2)
0201 || (theI2 - theI1 + 1 != theV.Length()),
0202 "math_VectorBase::Set() - invalid indices");
0203 int I = theV.Lower();
0204 for (int Index = theI1; Index <= theI2; Index++)
0205 {
0206 Array(Index) = theV.Array(I);
0207 I++;
0208 }
0209 }
0210
0211 template <typename TheItemType>
0212 void math_VectorBase<TheItemType>::Normalize()
0213 {
0214 double Result = Norm();
0215 Standard_NullValue_Raise_if((Result <= RealEpsilon()),
0216 "math_VectorBase::Normalize() - vector has zero norm");
0217 for (int Index = Lower(); Index <= Upper(); Index++)
0218 {
0219 Array(Index) = Array(Index) / Result;
0220 }
0221 }
0222
0223 template <typename TheItemType>
0224 math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Normalized() const
0225 {
0226 math_VectorBase Result = *this;
0227 Result.Normalize();
0228 return Result;
0229 }
0230
0231 template <typename TheItemType>
0232 void math_VectorBase<TheItemType>::Invert()
0233 {
0234 for (int Index = Lower(); Index <= (Lower() + Length()) >> 1; Index++)
0235 {
0236 int J = Upper() + Lower() - Index;
0237 TheItemType aTemp = Array(Index);
0238 Array(Index) = Array(J);
0239 Array(J) = aTemp;
0240 }
0241 }
0242
0243 template <typename TheItemType>
0244 math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Inverse() const
0245 {
0246 math_VectorBase Result = *this;
0247 Result.Invert();
0248 return Result;
0249 }
0250
0251 template <typename TheItemType>
0252 math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Multiplied(
0253 const TheItemType theRight) const
0254 {
0255 math_VectorBase Result(Lower(), Upper());
0256 for (int Index = Lower(); Index <= Upper(); Index++)
0257 {
0258 Result.Array(Index) = Array(Index) * theRight;
0259 }
0260 return Result;
0261 }
0262
0263 template <typename TheItemType>
0264 math_VectorBase<TheItemType> math_VectorBase<TheItemType>::TMultiplied(
0265 const TheItemType theRight) const
0266 {
0267 math_VectorBase Result(Lower(), Upper());
0268 for (int Index = Lower(); Index <= Upper(); Index++)
0269 {
0270 Result.Array(Index) = Array(Index) * theRight;
0271 }
0272 return Result;
0273 }
0274
0275 template <typename TheItemType>
0276 void math_VectorBase<TheItemType>::Multiply(const TheItemType theRight)
0277 {
0278 for (int Index = Lower(); Index <= Upper(); Index++)
0279 {
0280 Array(Index) = Array(Index) * theRight;
0281 }
0282 }
0283
0284 template <typename TheItemType>
0285 void math_VectorBase<TheItemType>::Divide(const TheItemType theRight)
0286 {
0287 Standard_DivideByZero_Raise_if(std::abs(theRight) <= RealEpsilon(),
0288 "math_VectorBase::Divide() - devisor is zero");
0289
0290 for (int Index = Lower(); Index <= Upper(); Index++)
0291 {
0292 Array(Index) = Array(Index) / theRight;
0293 }
0294 }
0295
0296 template <typename TheItemType>
0297 math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Divided(const TheItemType theRight) const
0298 {
0299 Standard_DivideByZero_Raise_if(std::abs(theRight) <= RealEpsilon(),
0300 "math_VectorBase::Divided() - devisor is zero");
0301 math_VectorBase temp = Multiplied(1. / theRight);
0302 return temp;
0303 }
0304
0305 template <typename TheItemType>
0306 void math_VectorBase<TheItemType>::Add(const math_VectorBase<TheItemType>& theRight)
0307 {
0308 Standard_DimensionError_Raise_if(Length() != theRight.Length(),
0309 "math_VectorBase::Add() - input vector has wrong dimensions");
0310
0311 int I = theRight.Lower();
0312 for (int Index = Lower(); Index <= Upper(); Index++)
0313 {
0314 Array(Index) = Array(Index) + theRight.Array(I);
0315 I++;
0316 }
0317 }
0318
0319 template <typename TheItemType>
0320 math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Added(
0321 const math_VectorBase<TheItemType>& theRight) const
0322 {
0323 Standard_DimensionError_Raise_if(Length() != theRight.Length(),
0324 "math_VectorBase::Added() - input vector has wrong dimensions");
0325
0326 math_VectorBase Result(Lower(), Upper());
0327
0328 int I = theRight.Lower();
0329 for (int Index = Lower(); Index <= Upper(); Index++)
0330 {
0331 Result.Array(Index) = Array(Index) + theRight.Array(I);
0332 I++;
0333 }
0334 return Result;
0335 }
0336
0337 template <typename TheItemType>
0338 void math_VectorBase<TheItemType>::Subtract(const math_VectorBase<TheItemType>& theRight)
0339 {
0340 Standard_DimensionError_Raise_if(
0341 Length() != theRight.Length(),
0342 "math_VectorBase::Subtract() - input vector has wrong dimensions");
0343
0344 int I = theRight.Lower();
0345 for (int Index = Lower(); Index <= Upper(); Index++)
0346 {
0347 Array(Index) = Array(Index) - theRight.Array(I);
0348 I++;
0349 }
0350 }
0351
0352 template <typename TheItemType>
0353 math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Subtracted(
0354 const math_VectorBase<TheItemType>& theRight) const
0355 {
0356 Standard_DimensionError_Raise_if(
0357 Length() != theRight.Length(),
0358 "math_VectorBase::Subtracted() - input vector has wrong dimensions");
0359
0360 math_VectorBase Result(Lower(), Upper());
0361
0362 int I = theRight.Lower();
0363 for (int Index = Lower(); Index <= Upper(); Index++)
0364 {
0365 Result.Array(Index) = Array(Index) - theRight.Array(I);
0366 I++;
0367 }
0368 return Result;
0369 }
0370
0371 template <typename TheItemType>
0372 math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Slice(const int theI1,
0373 const int theI2) const
0374 {
0375 Standard_RangeError_Raise_if((theI1 < Lower()) || (theI1 > Upper()) || (theI2 < Lower())
0376 || (theI2 > Upper()),
0377 "math_VectorBase::Slice() - invalid indices");
0378
0379 if (theI2 >= theI1)
0380 {
0381 math_VectorBase Result(theI1, theI2);
0382 for (int Index = theI1; Index <= theI2; Index++)
0383 {
0384 Result.Array(Index) = Array(Index);
0385 }
0386 return Result;
0387 }
0388 else
0389 {
0390 math_VectorBase Result(theI2, theI1);
0391 for (int Index = theI1; Index >= theI2; Index--)
0392 {
0393 Result.Array(Index) = Array(Index);
0394 }
0395 return Result;
0396 }
0397 }
0398
0399 template <typename TheItemType>
0400 void math_VectorBase<TheItemType>::Add(const math_VectorBase<TheItemType>& theLeft,
0401 const math_VectorBase<TheItemType>& theRight)
0402 {
0403 Standard_DimensionError_Raise_if((Length() != theRight.Length())
0404 || (theRight.Length() != theLeft.Length()),
0405 "math_VectorBase::Add() - input vectors have wrong dimensions");
0406
0407 int I = theLeft.Lower();
0408 int J = theRight.Lower();
0409 for (int Index = Lower(); Index <= Upper(); Index++)
0410 {
0411 Array(Index) = theLeft.Array(I) + theRight.Array(J);
0412 I++;
0413 J++;
0414 }
0415 }
0416
0417 template <typename TheItemType>
0418 void math_VectorBase<TheItemType>::Subtract(const math_VectorBase<TheItemType>& theLeft,
0419 const math_VectorBase<TheItemType>& theRight)
0420 {
0421 Standard_DimensionError_Raise_if(
0422 (Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()),
0423 "math_VectorBase::Subtract() - input vectors have wrong dimensions");
0424
0425 int I = theLeft.Lower();
0426 int J = theRight.Lower();
0427 for (int Index = Lower(); Index <= Upper(); Index++)
0428 {
0429 Array(Index) = theLeft.Array(I) - theRight.Array(J);
0430 I++;
0431 J++;
0432 }
0433 }
0434
0435 template <typename TheItemType>
0436 void math_VectorBase<TheItemType>::Multiply(const math_Matrix& theLeft,
0437 const math_VectorBase<TheItemType>& theRight)
0438 {
0439 Standard_DimensionError_Raise_if(
0440 (Length() != theLeft.RowNumber()) || (theLeft.ColNumber() != theRight.Length()),
0441 "math_VectorBase::Multiply() - input matrix and /or vector have wrong dimensions");
0442
0443 // result[r] = sum_c theLeft(r, c) * theRight[c]
0444 const int aNRows = theLeft.RowNumber();
0445 const int aNCols = theLeft.ColNumber();
0446 const double* aMatData = &theLeft(theLeft.LowerRow(), theLeft.LowerCol());
0447 const TheItemType* aRightPtr = &theRight.Array(theRight.Lower());
0448 TheItemType* aResPtr = &Array(Lower());
0449
0450 for (int r = 0; r < aNRows; r++)
0451 {
0452 TheItemType aSum = 0.0;
0453 const double* aRowData = aMatData + r * aNCols;
0454 for (int c = 0; c < aNCols; c++)
0455 {
0456 aSum += aRowData[c] * aRightPtr[c];
0457 }
0458 aResPtr[r] = aSum;
0459 }
0460 }
0461
0462 template <typename TheItemType>
0463 void math_VectorBase<TheItemType>::Multiply(const math_VectorBase<TheItemType>& theLeft,
0464 const math_Matrix& theRight)
0465 {
0466 Standard_DimensionError_Raise_if(
0467 (Length() != theRight.ColNumber()) || (theLeft.Length() != theRight.RowNumber()),
0468 "math_VectorBase::Multiply() - input matrix and /or vector have wrong dimensions");
0469
0470 // result[c] = sum_r theLeft[r] * theRight(r, c)
0471 const int aNCols = theRight.ColNumber();
0472 const int aNRows = theRight.RowNumber();
0473 const double* aMatData = &theRight(theRight.LowerRow(), theRight.LowerCol());
0474 const TheItemType* aLeftPtr = &theLeft.Array(theLeft.Lower());
0475 TheItemType* aResPtr = &Array(Lower());
0476
0477 for (int c = 0; c < aNCols; c++)
0478 {
0479 TheItemType aSum = 0.0;
0480 for (int r = 0; r < aNRows; r++)
0481 {
0482 aSum += aLeftPtr[r] * aMatData[r * aNCols + c];
0483 }
0484 aResPtr[c] = aSum;
0485 }
0486 }
0487
0488 template <typename TheItemType>
0489 void math_VectorBase<TheItemType>::TMultiply(const math_Matrix& theTLeft,
0490 const math_VectorBase<TheItemType>& theRight)
0491 {
0492 Standard_DimensionError_Raise_if(
0493 (Length() != theTLeft.ColNumber()) || (theTLeft.RowNumber() != theRight.Length()),
0494 "math_VectorBase::TMultiply() - input matrix and /or vector have wrong dimensions");
0495
0496 // result[c] = sum_r theTLeft(r, c) * theRight[r] (transpose-multiply)
0497 const int aNCols = theTLeft.ColNumber();
0498 const int aNRows = theTLeft.RowNumber();
0499 const double* aMatData = &theTLeft(theTLeft.LowerRow(), theTLeft.LowerCol());
0500 const TheItemType* aRightPtr = &theRight.Array(theRight.Lower());
0501 TheItemType* aResPtr = &Array(Lower());
0502
0503 for (int c = 0; c < aNCols; c++)
0504 {
0505 TheItemType aSum = 0.0;
0506 for (int r = 0; r < aNRows; r++)
0507 {
0508 aSum += aMatData[r * aNCols + c] * aRightPtr[r];
0509 }
0510 aResPtr[c] = aSum;
0511 }
0512 }
0513
0514 template <typename TheItemType>
0515 void math_VectorBase<TheItemType>::TMultiply(const math_VectorBase<TheItemType>& theLeft,
0516 const math_Matrix& theTRight)
0517 {
0518 Standard_DimensionError_Raise_if(
0519 (Length() != theTRight.RowNumber()) || (theLeft.Length() != theTRight.ColNumber()),
0520 "math_VectorBase::TMultiply() - input matrix and /or vector have wrong dimensions");
0521
0522 // result[r] = sum_c theLeft[c] * theTRight(r, c)
0523 const int aNCols = theTRight.ColNumber();
0524 const int aNRows = theTRight.RowNumber();
0525 const double* aMatData = &theTRight(theTRight.LowerRow(), theTRight.LowerCol());
0526 const TheItemType* aLeftPtr = &theLeft.Array(theLeft.Lower());
0527 TheItemType* aResPtr = &Array(Lower());
0528
0529 for (int r = 0; r < aNRows; r++)
0530 {
0531 TheItemType aSum = 0.0;
0532 const double* aRowData = aMatData + r * aNCols;
0533 for (int c = 0; c < aNCols; c++)
0534 {
0535 aSum += aLeftPtr[c] * aRowData[c];
0536 }
0537 aResPtr[r] = aSum;
0538 }
0539 }
0540
0541 template <typename TheItemType>
0542 TheItemType math_VectorBase<TheItemType>::Multiplied(
0543 const math_VectorBase<TheItemType>& theRight) const
0544 {
0545 Standard_DimensionError_Raise_if(
0546 Length() != theRight.Length(),
0547 "math_VectorBase::Multiplied() - input vector has wrong dimensions");
0548
0549 const int aLen = Length();
0550 const TheItemType* aLeftPtr = &Array(Lower());
0551 const TheItemType* aRightPtr = &theRight.Array(theRight.Lower());
0552 TheItemType aResult = 0;
0553 for (int i = 0; i < aLen; i++)
0554 {
0555 aResult += aLeftPtr[i] * aRightPtr[i];
0556 }
0557 return aResult;
0558 }
0559
0560 template <typename TheItemType>
0561 math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Opposite()
0562 {
0563 math_VectorBase Result(Lower(), Upper());
0564 for (int Index = Lower(); Index <= Upper(); Index++)
0565 {
0566 Result.Array(Index) = -Array(Index);
0567 }
0568 return Result;
0569 }
0570
0571 template <typename TheItemType>
0572 math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Multiplied(
0573 const math_Matrix& theRight) const
0574 {
0575 Standard_DimensionError_Raise_if(
0576 Length() != theRight.RowNumber(),
0577 "math_VectorBase::Multiplied() - input matrix has wrong dimensions");
0578
0579 math_VectorBase Result(theRight.LowerCol(), theRight.UpperCol());
0580 for (int J2 = theRight.LowerCol(); J2 <= theRight.UpperCol(); J2++)
0581 {
0582 Result.Array(J2) = 0.0;
0583 int theI2 = theRight.LowerRow();
0584 for (int I = Lower(); I <= Upper(); I++)
0585 {
0586 Result.Array(J2) = Result.Array(J2) + Array(I) * theRight(theI2, J2);
0587 theI2++;
0588 }
0589 }
0590 return Result;
0591 }
0592
0593 template <typename TheItemType>
0594 void math_VectorBase<TheItemType>::Multiply(const TheItemType theLeft,
0595 const math_VectorBase<TheItemType>& theRight)
0596 {
0597 Standard_DimensionError_Raise_if(
0598 (Length() != theRight.Length()),
0599 "math_VectorBase::Multiply() - input vector has wrong dimensions");
0600 for (int I = Lower(); I <= Upper(); I++)
0601 {
0602 Array(I) = theLeft * theRight.Array(I);
0603 }
0604 }
0605
0606 template <typename TheItemType>
0607 math_VectorBase<TheItemType>& math_VectorBase<TheItemType>::Initialized(
0608 const math_VectorBase<TheItemType>& theOther)
0609 {
0610 Array.CopyValues(theOther.Array);
0611 return *this;
0612 }
0613
0614 template <typename TheItemType>
0615 math_VectorBase<TheItemType>& math_VectorBase<TheItemType>::operator=(
0616 math_VectorBase<TheItemType>&& theOther)
0617 {
0618 if (this == &theOther)
0619 {
0620 return *this;
0621 }
0622
0623 if (Array.IsDeletable() && theOther.Array.IsDeletable() && Lower() == theOther.Lower()
0624 && Length() == theOther.Length())
0625 {
0626 Array.Move(theOther.Array);
0627 }
0628 else
0629 {
0630 Initialized(theOther);
0631 }
0632 return *this;
0633 }
0634
0635 template <typename TheItemType>
0636 void math_VectorBase<TheItemType>::Dump(Standard_OStream& theO) const
0637 {
0638 theO << "math_Vector of Length = " << Length() << "\n";
0639 for (int Index = Lower(); Index <= Upper(); Index++)
0640 {
0641 theO << "math_Vector(" << Index << ") = " << Array(Index) << "\n";
0642 }
0643 }
0644
0645 template <typename TheItemType>
0646 void math_VectorBase<TheItemType>::Resize(const int theSize)
0647 {
0648 const int theLower = Array.Lower();
0649 const int theUpper = theLower + theSize - 1;
0650 const bool aNewFitsStack = theSize <= THE_BUFFER_SIZE;
0651 const bool aWasOnStack = !Array.IsDeletable();
0652
0653 if (aWasOnStack && aNewFitsStack)
0654 {
0655 // Stack -> Stack: data is already in myBuffer, just update Array bounds
0656 Array = NCollection_Array1<TheItemType>(*myBuffer.data(), theLower, theUpper);
0657 }
0658 else if (aNewFitsStack)
0659 {
0660 // Heap -> Stack: copy data to stack buffer
0661 const int aCopyLen = std::min(Array.Length(), theSize);
0662 for (int i = 0; i < aCopyLen; ++i)
0663 {
0664 myBuffer[i] = Array.Value(theLower + i);
0665 }
0666 Array = NCollection_Array1<TheItemType>(*myBuffer.data(), theLower, theUpper);
0667 }
0668 else
0669 {
0670 // Stack -> Heap or Heap -> Heap: Array.Resize handles data copy
0671 Array.Resize(theLower, theUpper, true);
0672 }
0673 }