1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0030558: Coding - replace math_SingleTab with NCollection_LocalArray

math_Vector::Multiplied() - fixed modification of original array.

math_SVD::Solve(), math_SVD::PseudoInverse(), GeomFill_LocationGuide::InitX() - removed incorrect constness.

math_Vector, math_IntegerVector - math_SingleTab has been replaced by NCollection_LocalArray+NCollection_Array1.
Added accessors returning const value.
This commit is contained in:
kgv 2019-03-12 06:05:21 +03:00 committed by apn
parent 43c8661e5e
commit 18434846a3
12 changed files with 184 additions and 307 deletions

View File

@ -155,7 +155,7 @@ FEmTool_ProfileMatrix::FEmTool_ProfileMatrix(const TColStd_Array1OfInteger& Firs
Standard_Real * x = &X(X.Lower()); Standard_Real * x = &X(X.Lower());
x--; x--;
Standard_Real * b = &B(B.Lower()); const Standard_Real * b = &B(B.Lower());
b--; b--;
const Standard_Real * SMA = &SMatrix->Value(1); const Standard_Real * SMA = &SMatrix->Value(1);
SMA --; SMA --;
@ -207,7 +207,7 @@ FEmTool_ProfileMatrix::FEmTool_ProfileMatrix(const TColStd_Array1OfInteger& Firs
Standard_Integer i, j, jj, DiagAddr, CurrAddr; Standard_Integer i, j, jj, DiagAddr, CurrAddr;
Standard_Real * m = &MX(MX.Lower()); Standard_Real * m = &MX(MX.Lower());
m--; m--;
Standard_Real * x = &X(X.Lower()); const Standard_Real * x = &X(X.Lower());
x--; x--;
const Standard_Real * PM = &ProfileMatrix->Value(1); const Standard_Real * PM = &ProfileMatrix->Value(1);
PM--; PM--;

View File

@ -1381,7 +1381,7 @@ void GeomFill_LocationGuide::Resolution (const Standard_Integer ,
//Function : InitX //Function : InitX
//Purpose : recherche par interpolation d'une valeur initiale //Purpose : recherche par interpolation d'une valeur initiale
//================================================================== //==================================================================
void GeomFill_LocationGuide::InitX(const Standard_Real Param) const void GeomFill_LocationGuide::InitX(const Standard_Real Param)
{ {
Standard_Integer Ideb = 1, Ifin = myPoles2d->RowLength(), Idemi; Standard_Integer Ideb = 1, Ifin = myPoles2d->RowLength(), Idemi;

View File

@ -186,7 +186,7 @@ private:
Standard_EXPORT void SetRotation (const Standard_Real PrecAngle, Standard_Real& LastAngle); Standard_EXPORT void SetRotation (const Standard_Real PrecAngle, Standard_Real& LastAngle);
Standard_EXPORT void InitX (const Standard_Real Param) const; Standard_EXPORT void InitX (const Standard_Real Param);
Handle(GeomFill_TrihedronWithGuide) myLaw; Handle(GeomFill_TrihedronWithGuide) myLaw;
Handle(GeomFill_SectionLaw) mySec; Handle(GeomFill_SectionLaw) mySec;

View File

@ -111,7 +111,6 @@ math_PSOParticlesPool.cxx
math_PSOParticlesPool.hxx math_PSOParticlesPool.hxx
math_Recipes.cxx math_Recipes.cxx
math_Recipes.hxx math_Recipes.hxx
math_SingleTab.hxx
math_SingularMatrix.hxx math_SingularMatrix.hxx
math_Status.hxx math_Status.hxx
math_SVD.cxx math_SVD.cxx

View File

@ -12,40 +12,31 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
#include <math_IntegerVector.hxx> #include <math_IntegerVector.hxx>
#include <Standard_DimensionError.hxx> #include <Standard_DimensionError.hxx>
#include <Standard_RangeError.hxx> #include <Standard_RangeError.hxx>
math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast) : math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast)
FirstIndex(theFirst), : myLocArray (theLast - theFirst + 1),
LastIndex(theLast), Array (myLocArray[0], theFirst, theLast)
Array(theFirst, theLast)
{ {
Standard_RangeError_Raise_if(theFirst > theLast, " "); //
} }
math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst, math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst,
const Standard_Integer theLast, const Standard_Integer theLast,
const Standard_Integer theInitialValue) : const Standard_Integer theInitialValue)
FirstIndex(theFirst), : myLocArray (theLast - theFirst + 1),
LastIndex(theLast), Array (myLocArray[0], theFirst, theLast)
Array(theFirst, theLast)
{ {
Standard_RangeError_Raise_if(theFirst > theLast, " ");
Array.Init(theInitialValue); Array.Init(theInitialValue);
} }
math_IntegerVector::math_IntegerVector(const Standard_Address theTab, math_IntegerVector::math_IntegerVector(const Standard_Integer* theTab,
const Standard_Integer theFirst, const Standard_Integer theFirst,
const Standard_Integer theLast) : const Standard_Integer theLast)
FirstIndex(theFirst), : Array (*theTab, theFirst, theLast)
LastIndex(theLast),
Array(theTab, theFirst, theLast)
{ {
Standard_RangeError_Raise_if(theFirst > theLast, " "); Standard_RangeError_Raise_if(theFirst > theLast, " ");
} }
@ -55,24 +46,22 @@ void math_IntegerVector::Init(const Standard_Integer theInitialValue)
Array.Init(theInitialValue); Array.Init(theInitialValue);
} }
math_IntegerVector::math_IntegerVector(const math_IntegerVector& theOther) : math_IntegerVector::math_IntegerVector (const math_IntegerVector& theOther)
FirstIndex(theOther.FirstIndex), : myLocArray (theOther.Length()),
LastIndex(theOther.LastIndex), Array (myLocArray[0], theOther.Lower(), theOther.Upper())
Array(theOther.Array)
{ {
memcpy (&myLocArray[0], &theOther.Array.First(), sizeof(Standard_Integer) * theOther.Length());
} }
void math_IntegerVector::SetFirst(const Standard_Integer theFirst) void math_IntegerVector::SetFirst(const Standard_Integer theFirst)
{ {
Array.SetLower(theFirst); Array.Resize (theFirst, Array.Upper() - Array.Lower() + theFirst, Standard_False);
LastIndex = LastIndex - FirstIndex + theFirst;
FirstIndex = theFirst;
} }
Standard_Real math_IntegerVector::Norm() const Standard_Real math_IntegerVector::Norm() const
{ {
Standard_Real Result = 0; Standard_Real Result = 0;
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result = Result + Array(Index) * Array(Index); Result = Result + Array(Index) * Array(Index);
} }
@ -82,7 +71,7 @@ Standard_Real math_IntegerVector::Norm() const
Standard_Real math_IntegerVector::Norm2() const Standard_Real math_IntegerVector::Norm2() const
{ {
Standard_Real Result = 0; Standard_Real Result = 0;
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result = Result + Array(Index) * Array(Index); Result = Result + Array(Index) * Array(Index);
} }
@ -93,7 +82,7 @@ Standard_Integer math_IntegerVector::Max() const
{ {
Standard_Integer I=0; Standard_Integer I=0;
Standard_Real X = RealFirst(); Standard_Real X = RealFirst();
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
if(Array(Index) > X) if(Array(Index) > X)
{ {
@ -108,7 +97,7 @@ Standard_Integer math_IntegerVector::Min() const
{ {
Standard_Integer I=0; Standard_Integer I=0;
Standard_Real X = RealLast(); Standard_Real X = RealLast();
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
if(Array(Index) < X) if(Array(Index) < X)
{ {
@ -124,9 +113,9 @@ void math_IntegerVector::Invert()
Standard_Integer J; Standard_Integer J;
Standard_Integer Temp; Standard_Integer Temp;
for(Standard_Integer Index = FirstIndex; Index <= FirstIndex + Length() / 2 ; Index++) for(Standard_Integer Index = Lower(); Index <= Lower() + Length() / 2 ; Index++)
{ {
J = LastIndex + FirstIndex - Index; J = Upper() + Lower() - Index;
Temp = Array(Index); Temp = Array(Index);
Array(Index) = Array(J); Array(Index) = Array(J);
Array(J) = Temp; Array(J) = Temp;
@ -144,7 +133,7 @@ void math_IntegerVector::Set(const Standard_Integer theI1,
const Standard_Integer theI2, const Standard_Integer theI2,
const math_IntegerVector &theV) const math_IntegerVector &theV)
{ {
Standard_DimensionError_Raise_if((theI1 < FirstIndex) || (theI2 > LastIndex) || Standard_DimensionError_Raise_if((theI1 < Lower()) || (theI2 > Upper()) ||
(theI1 > theI2) || (theI2 - theI1 + 1 != theV.Length()), " "); (theI1 > theI2) || (theI2 - theI1 + 1 != theV.Length()), " ");
Standard_Integer I = theV.Lower(); Standard_Integer I = theV.Lower();
@ -157,7 +146,7 @@ void math_IntegerVector::Set(const Standard_Integer theI1,
void math_IntegerVector::Multiply(const Standard_Integer theRight) void math_IntegerVector::Multiply(const Standard_Integer theRight)
{ {
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = Array(Index) * theRight; Array(Index) = Array(Index) * theRight;
} }
@ -167,8 +156,8 @@ void math_IntegerVector::Add(const math_IntegerVector& theRight)
{ {
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " "); Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
Standard_Integer I = theRight.FirstIndex; Standard_Integer I = theRight.Lower();
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = Array(Index) + theRight.Array(I); Array(Index) = Array(Index) + theRight.Array(I);
I++; I++;
@ -178,8 +167,8 @@ void math_IntegerVector::Add(const math_IntegerVector& theRight)
void math_IntegerVector::Subtract(const math_IntegerVector& theRight) void math_IntegerVector::Subtract(const math_IntegerVector& theRight)
{ {
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " "); Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
Standard_Integer I = theRight.FirstIndex; Standard_Integer I = theRight.Lower();
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = Array(Index) - theRight.Array(I); Array(Index) = Array(Index) - theRight.Array(I);
I++; I++;
@ -189,8 +178,8 @@ void math_IntegerVector::Subtract(const math_IntegerVector& theRight)
math_IntegerVector math_IntegerVector::Slice(const Standard_Integer theI1, math_IntegerVector math_IntegerVector::Slice(const Standard_Integer theI1,
const Standard_Integer theI2) const const Standard_Integer theI2) const
{ {
Standard_DimensionError_Raise_if((theI1 < FirstIndex) || (theI1 > LastIndex) || Standard_DimensionError_Raise_if((theI1 < Lower()) || (theI1 > Upper()) ||
(theI2 < FirstIndex) || (theI2 > LastIndex), " "); (theI2 < Lower()) || (theI2 > Upper()), " ");
if(theI2 >= theI1) if(theI2 >= theI1)
{ {
@ -218,7 +207,7 @@ Standard_Integer math_IntegerVector::Multiplied (const math_IntegerVector& theRi
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " "); Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
Standard_Integer I = theRight.FirstIndex; Standard_Integer I = theRight.Lower();
for(Standard_Integer Index = 0; Index < Length(); Index++) for(Standard_Integer Index = 0; Index < Length(); Index++)
{ {
Result = Result + Array(Index) * theRight.Array(I); Result = Result + Array(Index) * theRight.Array(I);
@ -229,9 +218,9 @@ Standard_Integer math_IntegerVector::Multiplied (const math_IntegerVector& theRi
math_IntegerVector math_IntegerVector::Multiplied (const Standard_Integer theRight)const math_IntegerVector math_IntegerVector::Multiplied (const Standard_Integer theRight)const
{ {
math_IntegerVector Result(FirstIndex, LastIndex); math_IntegerVector Result(Lower(), Upper());
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result.Array(Index) = Array(Index) * theRight; Result.Array(Index) = Array(Index) * theRight;
} }
@ -240,9 +229,9 @@ math_IntegerVector math_IntegerVector::Multiplied (const Standard_Integer theRig
math_IntegerVector math_IntegerVector::TMultiplied (const Standard_Integer theRight) const math_IntegerVector math_IntegerVector::TMultiplied (const Standard_Integer theRight) const
{ {
math_IntegerVector Result(FirstIndex, LastIndex); math_IntegerVector Result(Lower(), Upper());
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result.Array(Index) = Array(Index) * theRight; Result.Array(Index) = Array(Index) * theRight;
} }
@ -253,10 +242,10 @@ math_IntegerVector math_IntegerVector::Added (const math_IntegerVector& theRight
{ {
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " "); Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
math_IntegerVector Result(FirstIndex, LastIndex); math_IntegerVector Result(Lower(), Upper());
Standard_Integer I = theRight.FirstIndex; Standard_Integer I = theRight.Lower();
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result.Array(Index) = Array(Index) + theRight.Array(I); Result.Array(Index) = Array(Index) + theRight.Array(I);
I++; I++;
@ -266,9 +255,9 @@ math_IntegerVector math_IntegerVector::Added (const math_IntegerVector& theRight
math_IntegerVector math_IntegerVector::Opposite() math_IntegerVector math_IntegerVector::Opposite()
{ {
math_IntegerVector Result(FirstIndex, LastIndex); math_IntegerVector Result(Lower(), Upper());
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result.Array(Index) = - Array(Index); Result.Array(Index) = - Array(Index);
} }
@ -279,10 +268,10 @@ math_IntegerVector math_IntegerVector::Subtracted (const math_IntegerVector& the
{ {
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " "); Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
math_IntegerVector Result(FirstIndex, LastIndex); math_IntegerVector Result(Lower(), Upper());
Standard_Integer I = theRight.FirstIndex; Standard_Integer I = theRight.Lower();
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result.Array(Index) = Array(Index) - theRight.Array(I); Result.Array(Index) = Array(Index) - theRight.Array(I);
I++; I++;
@ -295,9 +284,9 @@ void math_IntegerVector::Add (const math_IntegerVector& theLeft, const math_Inte
Standard_DimensionError_Raise_if((Length() != theRight.Length()) || Standard_DimensionError_Raise_if((Length() != theRight.Length()) ||
(theRight.Length() != theLeft.Length()), " "); (theRight.Length() != theLeft.Length()), " ");
Standard_Integer I = theLeft.FirstIndex; Standard_Integer I = theLeft.Lower();
Standard_Integer J = theRight.FirstIndex; Standard_Integer J = theRight.Lower();
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = theLeft.Array(I) + theRight.Array(J); Array(Index) = theLeft.Array(I) + theRight.Array(J);
I++; I++;
@ -311,9 +300,9 @@ void math_IntegerVector::Subtract (const math_IntegerVector& theLeft,
Standard_DimensionError_Raise_if((Length() != theRight.Length()) || Standard_DimensionError_Raise_if((Length() != theRight.Length()) ||
(theRight.Length() != theLeft.Length()), " "); (theRight.Length() != theLeft.Length()), " ");
Standard_Integer I = theLeft.FirstIndex; Standard_Integer I = theLeft.Lower();
Standard_Integer J = theRight.FirstIndex; Standard_Integer J = theRight.Lower();
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = theLeft.Array(I) - theRight.Array(J); Array(Index) = theLeft.Array(I) - theRight.Array(J);
I++; I++;
@ -324,7 +313,7 @@ void math_IntegerVector::Subtract (const math_IntegerVector& theLeft,
void math_IntegerVector::Multiply(const Standard_Integer theLeft, const math_IntegerVector& theRight) void math_IntegerVector::Multiply(const Standard_Integer theLeft, const math_IntegerVector& theRight)
{ {
Standard_DimensionError_Raise_if((Length() != theRight.Length()), " "); Standard_DimensionError_Raise_if((Length() != theRight.Length()), " ");
for(Standard_Integer I = FirstIndex; I <= LastIndex; I++) for(Standard_Integer I = Lower(); I <= Upper(); I++)
{ {
Array(I) = theLeft * theRight.Array(I); Array(I) = theLeft * theRight.Array(I);
} }
@ -333,17 +322,15 @@ void math_IntegerVector::Multiply(const Standard_Integer theLeft, const math_Int
math_IntegerVector& math_IntegerVector::Initialized(const math_IntegerVector& theOther) math_IntegerVector& math_IntegerVector::Initialized(const math_IntegerVector& theOther)
{ {
Standard_DimensionError_Raise_if(Length() != theOther.Length(), " "); Standard_DimensionError_Raise_if(Length() != theOther.Length(), " ");
memmove (&Array.ChangeFirst(), &theOther.Array.First(), sizeof(Standard_Integer) * Array.Length());
(theOther.Array).Copy(Array);
return *this; return *this;
} }
void math_IntegerVector::Dump(Standard_OStream& theO) const void math_IntegerVector::Dump(Standard_OStream& theO) const
{ {
theO << "math_IntegerVector of Range = " << Length() << "\n"; theO << "math_IntegerVector of Range = " << Length() << "\n";
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
theO << "math_IntegerVector(" << Index << ") = " << Array(Index) << "\n"; theO << "math_IntegerVector(" << Index << ") = " << Array(Index) << "\n";
} }
} }

View File

@ -15,7 +15,8 @@
#ifndef _math_IntegerVector_HeaderFile #ifndef _math_IntegerVector_HeaderFile
#define _math_IntegerVector_HeaderFile #define _math_IntegerVector_HeaderFile
#include <math_SingleTab.hxx> #include <NCollection_Array1.hxx>
#include <NCollection_LocalArray.hxx>
// resolve name collisions with X11 headers // resolve name collisions with X11 headers
#ifdef Opposite #ifdef Opposite
@ -70,7 +71,7 @@ public:
//! constructs an IntegerVector in the range [Lower..Upper] //! constructs an IntegerVector in the range [Lower..Upper]
//! which share the "c array" theTab. //! which share the "c array" theTab.
Standard_EXPORT math_IntegerVector(const Standard_Address theTab, const Standard_Integer theFirst, const Standard_Integer theLast); Standard_EXPORT math_IntegerVector(const Standard_Integer* theTab, const Standard_Integer theFirst, const Standard_Integer theLast);
//! constructs a copy for initialization. //! constructs a copy for initialization.
//! An exception is raised if the lengths of the IntegerVectors //! An exception is raised if the lengths of the IntegerVectors
@ -80,19 +81,19 @@ public:
//! returns the length of an IntegerVector //! returns the length of an IntegerVector
inline Standard_Integer Length() const inline Standard_Integer Length() const
{ {
return LastIndex - FirstIndex +1; return Array.Length();
} }
//! returns the value of the Lower index of an IntegerVector. //! returns the value of the Lower index of an IntegerVector.
inline Standard_Integer Lower() const inline Standard_Integer Lower() const
{ {
return FirstIndex; return Array.Lower();
} }
//! returns the value of the Upper index of an IntegerVector. //! returns the value of the Upper index of an IntegerVector.
inline Standard_Integer Upper() const inline Standard_Integer Upper() const
{ {
return LastIndex; return Array.Upper();
} }
//! returns the value of the norm of an IntegerVector. //! returns the value of the norm of an IntegerVector.
@ -176,14 +177,24 @@ public:
//! An exception is raised if the IntegerVectors have not the same length. //! An exception is raised if the IntegerVectors have not the same length.
Standard_EXPORT void Subtract(const math_IntegerVector& theLeft, const math_IntegerVector& theRight); Standard_EXPORT void Subtract(const math_IntegerVector& theLeft, const math_IntegerVector& theRight);
//! accesses (in read or write mode) the value of index theNum of an IntegerVector. //! accesses the value of index theNum of an IntegerVector.
inline Standard_Integer& Value(const Standard_Integer theNum) const const Standard_Integer& Value (const Standard_Integer theNum) const
{ {
Standard_RangeError_Raise_if(theNum < FirstIndex || theNum > LastIndex, " ");
return Array(theNum); return Array(theNum);
} }
Standard_Integer& operator()(const Standard_Integer theNum) const //! accesses (in read or write mode) the value of index theNum of an IntegerVector.
inline Standard_Integer& Value (const Standard_Integer theNum)
{
return Array(theNum);
}
const Standard_Integer& operator()(const Standard_Integer theNum) const
{
return Value(theNum);
}
Standard_Integer& operator()(const Standard_Integer theNum)
{ {
return Value(theNum); return Value(theNum);
} }
@ -252,9 +263,9 @@ protected:
private: private:
Standard_Integer FirstIndex; NCollection_LocalArray<Standard_Integer, 512> myLocArray;
Standard_Integer LastIndex; NCollection_Array1<Standard_Integer> Array;
math_SingleTab<Standard_Integer> Array;
}; };
#endif #endif

View File

@ -297,7 +297,7 @@ void math_Matrix::SetRow (const Standard_Integer Row,
Standard_DimensionError_Raise_if (ColNumber() != V.Length(), Standard_DimensionError_Raise_if (ColNumber() != V.Length(),
"math_Matrix::SetRow() - input vector has wrong dimensions"); "math_Matrix::SetRow() - input vector has wrong dimensions");
Standard_Integer I = V.LowerIndex; Standard_Integer I = V.Lower();
for(Standard_Integer Index = LowerColIndex; Index <= UpperColIndex; Index++) { for(Standard_Integer Index = LowerColIndex; Index <= UpperColIndex; Index++) {
Array(Row, Index) = V.Array(I); Array(Row, Index) = V.Array(I);
I++; I++;
@ -314,7 +314,7 @@ void math_Matrix::SetCol (const Standard_Integer Col,
Standard_DimensionError_Raise_if (RowNumber() != V.Length(), Standard_DimensionError_Raise_if (RowNumber() != V.Length(),
"math_Matrix::SetCol() - input vector has wrong dimensions"); "math_Matrix::SetCol() - input vector has wrong dimensions");
Standard_Integer I = V.LowerIndex; Standard_Integer I = V.Lower();
for(Standard_Integer Index = LowerRowIndex; Index <= UpperRowIndex; Index++) { for(Standard_Integer Index = LowerRowIndex; Index <= UpperRowIndex; Index++) {
Array(Index, Col) = V.Array(I); Array(Index, Col) = V.Array(I);
I++; I++;
@ -635,7 +635,7 @@ math_Vector math_Matrix::Multiplied(const math_Vector& Right)const
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) { for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Result.Array(I) = 0.0; Result.Array(I) = 0.0;
Standard_Integer II = Right.LowerIndex; Standard_Integer II = Right.Lower();
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) { for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Result.Array(I) = Result.Array(I) + Array(I, J) * Right.Array(II); Result.Array(I) = Result.Array(I) + Array(I, J) * Right.Array(II);
II++; II++;

View File

@ -40,7 +40,7 @@ math_SVD::math_SVD (const math_Matrix& A) :
void math_SVD::Solve (const math_Vector& B, void math_SVD::Solve (const math_Vector& B,
math_Vector& X, math_Vector& X,
const Standard_Real Eps) const const Standard_Real Eps)
{ {
StdFail_NotDone_Raise_if(!Done, " "); StdFail_NotDone_Raise_if(!Done, " ");
Standard_DimensionError_Raise_if((RowA != B.Length()) || Standard_DimensionError_Raise_if((RowA != B.Length()) ||
@ -58,7 +58,7 @@ void math_SVD::Solve (const math_Vector& B,
} }
void math_SVD::PseudoInverse (math_Matrix& Result, void math_SVD::PseudoInverse (math_Matrix& Result,
const Standard_Real Eps) const const Standard_Real Eps)
{ {
Standard_Integer i, j ; Standard_Integer i, j ;

View File

@ -61,14 +61,14 @@ public:
//! equal to the rowrange of A. //! equal to the rowrange of A.
//! Exception DimensionError is raised if the range of X is not //! Exception DimensionError is raised if the range of X is not
//! equal to the colrange of A. //! equal to the colrange of A.
Standard_EXPORT void Solve (const math_Vector& B, math_Vector& X, const Standard_Real Eps = 1.0e-6) const; Standard_EXPORT void Solve (const math_Vector& B, math_Vector& X, const Standard_Real Eps = 1.0e-6);
//! Computes the inverse Inv of matrix A such as A * Inverse = Identity. //! Computes the inverse Inv of matrix A such as A * Inverse = Identity.
//! Exceptions //! Exceptions
//! StdFail_NotDone if the algorithm fails (and IsDone returns false). //! StdFail_NotDone if the algorithm fails (and IsDone returns false).
//! Standard_DimensionError if the ranges of Inv are //! Standard_DimensionError if the ranges of Inv are
//! compatible with the ranges of A. //! compatible with the ranges of A.
Standard_EXPORT void PseudoInverse (math_Matrix& Inv, const Standard_Real Eps = 1.0e-6) const; Standard_EXPORT void PseudoInverse (math_Matrix& Inv, const Standard_Real Eps = 1.0e-6);
//! Prints information on the current state of the object. //! Prints information on the current state of the object.
//! Is used to redefine the operator <<. //! Is used to redefine the operator <<.

View File

@ -1,116 +0,0 @@
// Copyright (c) 1997-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _math_SingleTab_HeaderFile
#define _math_SingleTab_HeaderFile
#include <Standard_OutOfRange.hxx>
#include <Standard_Failure.hxx>
#include <string.h>
static const Standard_Integer aLengthOfBuf = 512;
template<class T> class math_SingleTab
{
public:
DEFINE_STANDARD_ALLOC
math_SingleTab(const Standard_Integer LowerIndex, const Standard_Integer UpperIndex) :
Addr(Buf),
isAllocated(UpperIndex - LowerIndex + 1 > aLengthOfBuf),
First(LowerIndex), Last(UpperIndex)
{
T* TheAddr = !isAllocated? Buf :
(T*) Standard::Allocate((Last-First+1) * sizeof(T));
Addr = (Standard_Address) (TheAddr - First);
}
math_SingleTab(const Standard_Address Tab, const Standard_Integer LowerIndex, const Standard_Integer UpperIndex) :
Addr((void*)((const T*)Tab - LowerIndex)),
isAllocated(Standard_False),
First(LowerIndex), Last(UpperIndex)
{
}
void Init(const T InitValue)
{
for(Standard_Integer i = First; i<= Last; i++)
{
((T*)Addr)[i] = InitValue;
}
}
math_SingleTab(const math_SingleTab& Other) :
isAllocated(Other.Last - Other.First + 1 > aLengthOfBuf),
First(Other.First),
Last(Other.Last)
{
T* TheAddr = !isAllocated? Buf : (T*) Standard::Allocate((Last-First+1) * sizeof(T));
Addr = (Standard_Address) (TheAddr - First);
T* TheOtherAddr = (T*) Other.Addr;
memmove((void*) TheAddr, (const void*) (TheOtherAddr + First), (size_t)(Last - First + 1) * sizeof(T));
}
inline void Copy(math_SingleTab& Other) const
{
memmove((void*) (((T*)Other.Addr) + Other.First),
(const void*) (((T*)Addr) + First),
(size_t)(Last - First + 1) * sizeof(T));
}
void SetLower(const Standard_Integer LowerIndex)
{
T* TheAddr = (T*) Addr;
Addr = (Standard_Address) (TheAddr + First - LowerIndex);
Last = Last - First + LowerIndex;
First = LowerIndex;
}
inline T& Value(const Standard_Integer Index) const
{
return ((T*)Addr)[Index];
}
T& operator()(const Standard_Integer Index) const
{
return Value(Index);
}
void Free()
{
if(isAllocated)
{
Standard_Address it = (Standard_Address)&((T*)Addr)[First];
Standard::Free(it);
Addr = 0;
}
}
~math_SingleTab()
{
Free();
}
private:
Standard_Address Addr;
T Buf[aLengthOfBuf];
Standard_Boolean isAllocated;
Standard_Integer First;
Standard_Integer Last;
};
#endif

View File

@ -22,48 +22,41 @@
#include <Standard_RangeError.hxx> #include <Standard_RangeError.hxx>
#include <Standard_NullValue.hxx> #include <Standard_NullValue.hxx>
math_Vector::math_Vector(const Standard_Integer theLower, const Standard_Integer theUpper) : math_Vector::math_Vector(const Standard_Integer theLower, const Standard_Integer theUpper)
LowerIndex(theLower), : myLocArray (theUpper - theLower + 1),
UpperIndex(theUpper), Array (myLocArray[0], theLower, theUpper)
Array(theLower,theUpper)
{ {
Standard_RangeError_Raise_if (theLower > theUpper, "math_Vector() - invalid dimensions"); //
} }
math_Vector::math_Vector(const Standard_Integer theLower, math_Vector::math_Vector(const Standard_Integer theLower,
const Standard_Integer theUpper, const Standard_Integer theUpper,
const Standard_Real theInitialValue): const Standard_Real theInitialValue)
LowerIndex(theLower), : myLocArray (theUpper - theLower + 1),
UpperIndex(theUpper), Array (myLocArray[0], theLower, theUpper)
Array(theLower,theUpper)
{ {
Standard_RangeError_Raise_if (theLower > theUpper, "math_Vector() - invalid dimensions");
Array.Init(theInitialValue); Array.Init(theInitialValue);
} }
math_Vector::math_Vector(const Standard_Address theTab, math_Vector::math_Vector(const Standard_Real* theTab,
const Standard_Integer theLower, const Standard_Integer theLower,
const Standard_Integer theUpper) : const Standard_Integer theUpper)
LowerIndex(theLower), : Array (*theTab, theLower, theUpper)
UpperIndex(theUpper),
Array(theTab, theLower,theUpper)
{ {
Standard_RangeError_Raise_if ((theLower > theUpper), "math_Vector() - invalid dimensions"); Standard_RangeError_Raise_if ((theLower > theUpper), "math_Vector() - invalid dimensions");
} }
math_Vector::math_Vector(const gp_XY& theOther): math_Vector::math_Vector (const gp_XY& theOther)
LowerIndex(1), : myLocArray (2),
UpperIndex(2), Array (myLocArray[0], 1,2)
Array(1,2)
{ {
Array(1) = theOther.X(); Array(1) = theOther.X();
Array(2) = theOther.Y(); Array(2) = theOther.Y();
} }
math_Vector::math_Vector(const gp_XYZ& theOther): math_Vector::math_Vector (const gp_XYZ& theOther)
LowerIndex(1), : myLocArray (3),
UpperIndex(3), Array (myLocArray[0], 1, 3)
Array(1, 3)
{ {
Array(1) = theOther.X(); Array(1) = theOther.X();
Array(2) = theOther.Y(); Array(2) = theOther.Y();
@ -75,25 +68,23 @@ void math_Vector::Init(const Standard_Real theInitialValue)
Array.Init(theInitialValue); Array.Init(theInitialValue);
} }
math_Vector::math_Vector(const math_Vector& theOther) : math_Vector::math_Vector (const math_Vector& theOther)
LowerIndex(theOther.LowerIndex), : myLocArray (theOther.Length()),
UpperIndex(theOther.UpperIndex), Array (myLocArray[0], theOther.Lower(), theOther.Upper())
Array(theOther.Array)
{ {
memcpy (&myLocArray[0], &theOther.Array.First(), sizeof(Standard_Real) * theOther.Length());
} }
void math_Vector::SetLower(const Standard_Integer theLower) void math_Vector::SetLower(const Standard_Integer theLower)
{ {
Array.SetLower(theLower); Array.Resize (theLower, Array.Upper() - Array.Lower() + theLower, Standard_False);
UpperIndex = UpperIndex - LowerIndex + theLower;
LowerIndex = theLower;
} }
Standard_Real math_Vector::Norm() const Standard_Real math_Vector::Norm() const
{ {
Standard_Real Result = 0; Standard_Real Result = 0;
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result = Result + Array(Index) * Array(Index); Result = Result + Array(Index) * Array(Index);
} }
@ -104,7 +95,7 @@ Standard_Real math_Vector::Norm2() const
{ {
Standard_Real Result = 0; Standard_Real Result = 0;
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result = Result + Array(Index) * Array(Index); Result = Result + Array(Index) * Array(Index);
} }
@ -116,7 +107,7 @@ Standard_Integer math_Vector::Max() const
Standard_Integer I=0; Standard_Integer I=0;
Standard_Real X = RealFirst(); Standard_Real X = RealFirst();
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
if(Array(Index) > X) if(Array(Index) > X)
{ {
@ -132,7 +123,7 @@ Standard_Integer math_Vector::Min() const
Standard_Integer I=0; Standard_Integer I=0;
Standard_Real X = RealLast(); Standard_Real X = RealLast();
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
if(Array(Index) < X) if(Array(Index) < X)
{ {
@ -147,7 +138,7 @@ void math_Vector::Set(const Standard_Integer theI1,
const Standard_Integer theI2, const Standard_Integer theI2,
const math_Vector &theV) const math_Vector &theV)
{ {
Standard_RangeError_Raise_if ((theI1 < LowerIndex) || (theI2 > UpperIndex) Standard_RangeError_Raise_if ((theI1 < Lower()) || (theI2 > Upper())
|| (theI1 > theI2) || (theI2 - theI1 + 1 != theV.Length()), || (theI1 > theI2) || (theI2 - theI1 + 1 != theV.Length()),
"math_Vector::Set() - invalid indices"); "math_Vector::Set() - invalid indices");
@ -164,7 +155,7 @@ void math_Vector::Normalize()
Standard_Real Result = Norm(); Standard_Real Result = Norm();
Standard_NullValue_Raise_if ((Result <= RealEpsilon()), Standard_NullValue_Raise_if ((Result <= RealEpsilon()),
"math_Vector::Normalize() - vector has zero norm"); "math_Vector::Normalize() - vector has zero norm");
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = Array(Index) / Result; Array(Index) = Array(Index) / Result;
} }
@ -180,14 +171,12 @@ math_Vector math_Vector::Normalized() const
void math_Vector::Invert() void math_Vector::Invert()
{ {
Standard_Integer J; for(Standard_Integer Index = Lower(); Index <= (Lower() + Length()) >> 1 ; Index++)
Standard_Real Temp;
for(Standard_Integer Index = LowerIndex; Index <= (LowerIndex + Length()) >> 1 ; Index++)
{ {
J = UpperIndex + LowerIndex - Index; Standard_Integer J = Upper() + Lower() - Index;
Temp = Array(Index); Standard_Real aTemp = Array(Index);
Array(Index) = Array(J); Array(Index) = Array(J);
Array(J) = Temp; Array(J) = aTemp;
} }
} }
@ -200,9 +189,8 @@ math_Vector math_Vector::Inverse() const
math_Vector math_Vector::Multiplied(const Standard_Real theRight) const math_Vector math_Vector::Multiplied(const Standard_Real theRight) const
{ {
math_Vector Result (LowerIndex, UpperIndex); math_Vector Result (Lower(), Upper());
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
{ {
Result.Array(Index) = Array(Index) * theRight; Result.Array(Index) = Array(Index) * theRight;
} }
@ -211,9 +199,8 @@ math_Vector math_Vector::Multiplied(const Standard_Real theRight) const
math_Vector math_Vector::TMultiplied(const Standard_Real theRight) const math_Vector math_Vector::TMultiplied(const Standard_Real theRight) const
{ {
math_Vector Result (LowerIndex, UpperIndex); math_Vector Result (Lower(), Upper());
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
{ {
Result.Array(Index) = Array(Index) * theRight; Result.Array(Index) = Array(Index) * theRight;
} }
@ -222,7 +209,7 @@ math_Vector math_Vector::TMultiplied(const Standard_Real theRight) const
void math_Vector::Multiply(const Standard_Real theRight) void math_Vector::Multiply(const Standard_Real theRight)
{ {
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = Array(Index) * theRight; Array(Index) = Array(Index) * theRight;
} }
@ -233,7 +220,7 @@ void math_Vector::Divide(const Standard_Real theRight)
Standard_DivideByZero_Raise_if (Abs(theRight) <= RealEpsilon(), Standard_DivideByZero_Raise_if (Abs(theRight) <= RealEpsilon(),
"math_Vector::Divide() - devisor is zero"); "math_Vector::Divide() - devisor is zero");
for(Standard_Integer Index =LowerIndex; Index <=UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = Array(Index) / theRight; Array(Index) = Array(Index) / theRight;
} }
@ -252,8 +239,8 @@ void math_Vector::Add(const math_Vector& theRight)
Standard_DimensionError_Raise_if (Length() != theRight.Length(), Standard_DimensionError_Raise_if (Length() != theRight.Length(),
"math_Vector::Add() - input vector has wrong dimensions"); "math_Vector::Add() - input vector has wrong dimensions");
Standard_Integer I = theRight.LowerIndex; Standard_Integer I = theRight.Lower();
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = Array(Index) + theRight.Array(I); Array(Index) = Array(Index) + theRight.Array(I);
I++; I++;
@ -265,10 +252,10 @@ math_Vector math_Vector::Added(const math_Vector& theRight) const
Standard_DimensionError_Raise_if (Length() != theRight.Length(), Standard_DimensionError_Raise_if (Length() != theRight.Length(),
"math_Vector::Added() - input vector has wrong dimensions"); "math_Vector::Added() - input vector has wrong dimensions");
math_Vector Result(LowerIndex, UpperIndex); math_Vector Result (Lower(), Upper());
Standard_Integer I = theRight.LowerIndex; Standard_Integer I = theRight.Lower();
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result.Array(Index) = Array(Index) + theRight.Array(I); Result.Array(Index) = Array(Index) + theRight.Array(I);
I++; I++;
@ -281,8 +268,8 @@ void math_Vector::Subtract(const math_Vector& theRight)
Standard_DimensionError_Raise_if (Length() != theRight.Length(), Standard_DimensionError_Raise_if (Length() != theRight.Length(),
"math_Vector::Subtract() - input vector has wrong dimensions"); "math_Vector::Subtract() - input vector has wrong dimensions");
Standard_Integer I = theRight.LowerIndex; Standard_Integer I = theRight.Lower();
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = Array(Index) - theRight.Array(I); Array(Index) = Array(Index) - theRight.Array(I);
I++; I++;
@ -294,10 +281,10 @@ math_Vector math_Vector::Subtracted (const math_Vector& theRight) const
Standard_DimensionError_Raise_if (Length() != theRight.Length(), Standard_DimensionError_Raise_if (Length() != theRight.Length(),
"math_Vector::Subtracted() - input vector has wrong dimensions"); "math_Vector::Subtracted() - input vector has wrong dimensions");
math_Vector Result(LowerIndex, UpperIndex); math_Vector Result(Lower(), Upper());
Standard_Integer I = theRight.LowerIndex; Standard_Integer I = theRight.Lower();
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result.Array(Index) = Array(Index) - theRight.Array(I); Result.Array(Index) = Array(Index) - theRight.Array(I);
I++; I++;
@ -307,7 +294,7 @@ math_Vector math_Vector::Subtracted (const math_Vector& theRight) const
math_Vector math_Vector::Slice(const Standard_Integer theI1, const Standard_Integer theI2) const math_Vector math_Vector::Slice(const Standard_Integer theI1, const Standard_Integer theI2) const
{ {
Standard_RangeError_Raise_if ((theI1 < LowerIndex) || (theI1 > UpperIndex) || (theI2 < LowerIndex) || (theI2 > UpperIndex), Standard_RangeError_Raise_if ((theI1 < Lower()) || (theI1 > Upper()) || (theI2 < Lower()) || (theI2 > Upper()),
"math_Vector::Slice() - invalid indices"); "math_Vector::Slice() - invalid indices");
if(theI2 >= theI1) if(theI2 >= theI1)
@ -335,9 +322,9 @@ void math_Vector::Add (const math_Vector& theLeft, const math_Vector& theRight)
Standard_DimensionError_Raise_if ((Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()), Standard_DimensionError_Raise_if ((Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()),
"math_Vector::Add() - input vectors have wrong dimensions"); "math_Vector::Add() - input vectors have wrong dimensions");
Standard_Integer I = theLeft.LowerIndex; Standard_Integer I = theLeft.Lower();
Standard_Integer J = theRight.LowerIndex; Standard_Integer J = theRight.Lower();
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = theLeft.Array(I) + theRight.Array(J); Array(Index) = theLeft.Array(I) + theRight.Array(J);
I++; I++;
@ -350,9 +337,9 @@ void math_Vector::Subtract (const math_Vector& theLeft, const math_Vector& theRi
Standard_DimensionError_Raise_if ((Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()), Standard_DimensionError_Raise_if ((Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()),
"math_Vector::Subtract() - input vectors have wrong dimensions"); "math_Vector::Subtract() - input vectors have wrong dimensions");
Standard_Integer I = theLeft.LowerIndex; Standard_Integer I = theLeft.Lower();
Standard_Integer J = theRight.LowerIndex; Standard_Integer J = theRight.Lower();
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Array(Index) = theLeft.Array(I) - theRight.Array(J); Array(Index) = theLeft.Array(I) - theRight.Array(J);
I++; I++;
@ -366,11 +353,11 @@ void math_Vector::Multiply(const math_Matrix& theLeft, const math_Vector& theRig
|| (theLeft.ColNumber() != theRight.Length()), || (theLeft.ColNumber() != theRight.Length()),
"math_Vector::Multiply() - input matrix and/or vector have wrong dimensions"); "math_Vector::Multiply() - input matrix and/or vector have wrong dimensions");
Standard_Integer Index = LowerIndex; Standard_Integer Index = Lower();
for(Standard_Integer I = theLeft.LowerRowIndex; I <= theLeft.UpperRowIndex; I++) for(Standard_Integer I = theLeft.LowerRowIndex; I <= theLeft.UpperRowIndex; I++)
{ {
Array(Index) = 0.0; Array(Index) = 0.0;
Standard_Integer K = theRight.LowerIndex; Standard_Integer K = theRight.Lower();
for(Standard_Integer J = theLeft.LowerColIndex; J <= theLeft.UpperColIndex; J++) for(Standard_Integer J = theLeft.LowerColIndex; J <= theLeft.UpperColIndex; J++)
{ {
Array(Index) = Array(Index) + theLeft.Array(I, J) * theRight.Array(K); Array(Index) = Array(Index) + theLeft.Array(I, J) * theRight.Array(K);
@ -386,11 +373,11 @@ void math_Vector::Multiply(const math_Vector& theLeft, const math_Matrix& theRig
|| (theLeft.Length() != theRight.RowNumber()), || (theLeft.Length() != theRight.RowNumber()),
"math_Vector::Multiply() - input matrix and/or vector have wrong dimensions"); "math_Vector::Multiply() - input matrix and/or vector have wrong dimensions");
Standard_Integer Index = LowerIndex; Standard_Integer Index = Lower();
for(Standard_Integer J = theRight.LowerColIndex; J <= theRight.UpperColIndex; J++) for(Standard_Integer J = theRight.LowerColIndex; J <= theRight.UpperColIndex; J++)
{ {
Array(Index) = 0.0; Array(Index) = 0.0;
Standard_Integer K = theLeft.LowerIndex; Standard_Integer K = theLeft.Lower();
for(Standard_Integer I = theRight.LowerRowIndex; I <= theRight.UpperRowIndex; I++) for(Standard_Integer I = theRight.LowerRowIndex; I <= theRight.UpperRowIndex; I++)
{ {
Array(Index) = Array(Index) + theLeft.Array(K) * theRight.Array(I, J); Array(Index) = Array(Index) + theLeft.Array(K) * theRight.Array(I, J);
@ -406,11 +393,11 @@ void math_Vector::TMultiply(const math_Matrix& theTLeft, const math_Vector& the
|| (theTLeft.RowNumber() != theRight.Length()), || (theTLeft.RowNumber() != theRight.Length()),
"math_Vector::TMultiply() - input matrix and/or vector have wrong dimensions"); "math_Vector::TMultiply() - input matrix and/or vector have wrong dimensions");
Standard_Integer Index = LowerIndex; Standard_Integer Index = Lower();
for(Standard_Integer I = theTLeft.LowerColIndex; I <= theTLeft.UpperColIndex; I++) for(Standard_Integer I = theTLeft.LowerColIndex; I <= theTLeft.UpperColIndex; I++)
{ {
Array(Index) = 0.0; Array(Index) = 0.0;
Standard_Integer K = theRight.LowerIndex; Standard_Integer K = theRight.Lower();
for(Standard_Integer J = theTLeft.LowerRowIndex; J <= theTLeft.UpperRowIndex; J++) for(Standard_Integer J = theTLeft.LowerRowIndex; J <= theTLeft.UpperRowIndex; J++)
{ {
Array(Index) = Array(Index) + theTLeft.Array(J, I) * theRight.Array(K); Array(Index) = Array(Index) + theTLeft.Array(J, I) * theRight.Array(K);
@ -426,11 +413,11 @@ void math_Vector::TMultiply(const math_Vector& theLeft, const math_Matrix& theT
|| (theLeft.Length() != theTRight.ColNumber()), || (theLeft.Length() != theTRight.ColNumber()),
"math_Vector::TMultiply() - input matrix and/or vector have wrong dimensions"); "math_Vector::TMultiply() - input matrix and/or vector have wrong dimensions");
Standard_Integer Index = LowerIndex; Standard_Integer Index = Lower();
for(Standard_Integer J = theTRight.LowerRowIndex; J <= theTRight.UpperRowIndex; J++) for(Standard_Integer J = theTRight.LowerRowIndex; J <= theTRight.UpperRowIndex; J++)
{ {
Array(Index) = 0.0; Array(Index) = 0.0;
Standard_Integer K = theLeft.LowerIndex; Standard_Integer K = theLeft.Lower();
for(Standard_Integer I = theTRight.LowerColIndex; for(Standard_Integer I = theTRight.LowerColIndex;
I <= theTRight.UpperColIndex; I++) I <= theTRight.UpperColIndex; I++)
{ {
@ -448,8 +435,8 @@ Standard_Real math_Vector::Multiplied(const math_Vector& theRight) const
Standard_DimensionError_Raise_if (Length() != theRight.Length(), Standard_DimensionError_Raise_if (Length() != theRight.Length(),
"math_Vector::Multiplied() - input vector has wrong dimensions"); "math_Vector::Multiplied() - input vector has wrong dimensions");
Standard_Integer I = theRight.LowerIndex; Standard_Integer I = theRight.Lower();
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
Result = Result + Array(Index) * theRight.Array(I); Result = Result + Array(Index) * theRight.Array(I);
I++; I++;
@ -459,9 +446,8 @@ Standard_Real math_Vector::Multiplied(const math_Vector& theRight) const
math_Vector math_Vector::Opposite() math_Vector math_Vector::Opposite()
{ {
math_Vector Result(LowerIndex, UpperIndex); math_Vector Result(Lower(), Upper());
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
{ {
Result.Array(Index) = - Array(Index); Result.Array(Index) = - Array(Index);
} }
@ -476,13 +462,13 @@ math_Vector math_Vector::Multiplied(const math_Matrix& theRight)const
math_Vector Result(theRight.LowerColIndex, theRight.UpperColIndex); math_Vector Result(theRight.LowerColIndex, theRight.UpperColIndex);
for(Standard_Integer J2 = theRight.LowerColIndex; J2 <= theRight.UpperColIndex; J2++) for(Standard_Integer J2 = theRight.LowerColIndex; J2 <= theRight.UpperColIndex; J2++)
{ {
Array(J2) = 0.0; Result.Array(J2) = 0.0;
Standard_Integer theI2 = theRight.LowerRowIndex; Standard_Integer theI2 = theRight.LowerRowIndex;
for(Standard_Integer I = LowerIndex; I <= UpperIndex; I++) for(Standard_Integer I = Lower(); I <= Upper(); I++)
{ {
Result.Array(J2) = Result.Array(J2) + Array(I) * theRight.Array(theI2, J2); Result.Array(J2) = Result.Array(J2) + Array(I) * theRight.Array(theI2, J2);
theI2++; theI2++;
} }
} }
return Result; return Result;
} }
@ -491,7 +477,7 @@ void math_Vector::Multiply(const Standard_Real theLeft, const math_Vector& theRi
{ {
Standard_DimensionError_Raise_if ((Length() != theRight.Length()), Standard_DimensionError_Raise_if ((Length() != theRight.Length()),
"math_Vector::Multiply() - input vector has wrong dimensions"); "math_Vector::Multiply() - input vector has wrong dimensions");
for(Standard_Integer I = LowerIndex; I <= UpperIndex; I++) for(Standard_Integer I = Lower(); I <= Upper(); I++)
{ {
Array(I) = theLeft * theRight.Array(I); Array(I) = theLeft * theRight.Array(I);
} }
@ -501,15 +487,14 @@ math_Vector& math_Vector::Initialized(const math_Vector& theOther)
{ {
Standard_DimensionError_Raise_if (Length() != theOther.Length(), Standard_DimensionError_Raise_if (Length() != theOther.Length(),
"math_Vector::Initialized() - input vector has wrong dimensions"); "math_Vector::Initialized() - input vector has wrong dimensions");
memmove (&Array.ChangeFirst(), &theOther.Array.First(), sizeof(Standard_Real) * Array.Length());
(theOther.Array).Copy(Array);
return *this; return *this;
} }
void math_Vector::Dump(Standard_OStream& theO) const void math_Vector::Dump(Standard_OStream& theO) const
{ {
theO << "math_Vector of Length = " << Length() << "\n"; theO << "math_Vector of Length = " << Length() << "\n";
for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{ {
theO << "math_Vector(" << Index << ") = " << Array(Index) << "\n"; theO << "math_Vector(" << Index << ") = " << Array(Index) << "\n";
} }

View File

@ -15,7 +15,8 @@
#ifndef _math_Vector_HeaderFile #ifndef _math_Vector_HeaderFile
#define _math_Vector_HeaderFile #define _math_Vector_HeaderFile
#include <math_SingleTab.hxx> #include <NCollection_Array1.hxx>
#include <NCollection_LocalArray.hxx>
#include <gp_XY.hxx> #include <gp_XY.hxx>
#include <gp_XYZ.hxx> #include <gp_XYZ.hxx>
@ -70,7 +71,7 @@ public:
//! Constructs a vector in the range [theLower..theUpper] //! Constructs a vector in the range [theLower..theUpper]
//! with the "c array" theTab. //! with the "c array" theTab.
Standard_EXPORT math_Vector(const Standard_Address theTab, const Standard_Integer theLower, const Standard_Integer theUpper); Standard_EXPORT math_Vector(const Standard_Real* theTab, const Standard_Integer theLower, const Standard_Integer theUpper);
//! Constructor for converting gp_XY to math_Vector //! Constructor for converting gp_XY to math_Vector
Standard_EXPORT math_Vector(const gp_XY& Other); Standard_EXPORT math_Vector(const gp_XY& Other);
@ -88,19 +89,19 @@ public:
//! Returns the length of a vector //! Returns the length of a vector
inline Standard_Integer Length() const inline Standard_Integer Length() const
{ {
return UpperIndex - LowerIndex +1; return Array.Length();
} }
//! Returns the value of the theLower index of a vector. //! Returns the value of the theLower index of a vector.
inline Standard_Integer Lower() const inline Standard_Integer Lower() const
{ {
return LowerIndex; return Array.Lower();
} }
//! Returns the value of the theUpper index of a vector. //! Returns the value of the theUpper index of a vector.
inline Standard_Integer Upper() const inline Standard_Integer Upper() const
{ {
return UpperIndex; return Array.Upper();
} }
//! Returns the value or the square of the norm of this vector. //! Returns the value or the square of the norm of this vector.
@ -241,14 +242,24 @@ public:
//! Subtract whenever possible. //! Subtract whenever possible.
Standard_EXPORT void Subtract(const math_Vector& theLeft,const math_Vector& theRight); Standard_EXPORT void Subtract(const math_Vector& theLeft,const math_Vector& theRight);
//! accesses (in read or write mode) the value of index "theNum" of a vector. //! accesses the value of index "theNum" of a vector.
inline Standard_Real& Value(const Standard_Integer theNum) const const Standard_Real& Value (const Standard_Integer theNum) const
{ {
Standard_RangeError_Raise_if(theNum < LowerIndex || theNum > UpperIndex, " ");
return Array(theNum); return Array(theNum);
} }
Standard_Real& operator()(const Standard_Integer theNum) const //! accesses (in read or write mode) the value of index "theNum" of a vector.
inline Standard_Real& Value (const Standard_Integer theNum)
{
return Array(theNum);
}
const Standard_Real& operator()(const Standard_Integer theNum) const
{
return Value(theNum);
}
Standard_Real& operator()(const Standard_Integer theNum)
{ {
return Value(theNum); return Value(theNum);
} }
@ -327,9 +338,9 @@ protected:
private: private:
Standard_Integer LowerIndex; NCollection_LocalArray<Standard_Real, 512> myLocArray;
Standard_Integer UpperIndex; NCollection_Array1<Standard_Real> Array;
math_SingleTab<Standard_Real> Array;
}; };
#endif #endif