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.
Standard_Real * x = &X(X.Lower());
x--;
- Standard_Real * b = &B(B.Lower());
+ const Standard_Real * b = &B(B.Lower());
b--;
const Standard_Real * SMA = &SMatrix->Value(1);
SMA --;
Standard_Integer i, j, jj, DiagAddr, CurrAddr;
Standard_Real * m = &MX(MX.Lower());
m--;
- Standard_Real * x = &X(X.Lower());
+ const Standard_Real * x = &X(X.Lower());
x--;
const Standard_Real * PM = &ProfileMatrix->Value(1);
PM--;
//Function : InitX
//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_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_SectionLaw) mySec;
math_PSOParticlesPool.hxx
math_Recipes.cxx
math_Recipes.hxx
-math_SingleTab.hxx
math_SingularMatrix.hxx
math_Status.hxx
math_SVD.cxx
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-#define No_Standard_RangeError
-#define No_Standard_OutOfRange
-#define No_Standard_DimensionError
-
#include <math_IntegerVector.hxx>
#include <Standard_DimensionError.hxx>
#include <Standard_RangeError.hxx>
-math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast) :
- FirstIndex(theFirst),
- LastIndex(theLast),
- Array(theFirst, theLast)
+math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast)
+: myLocArray (theLast - theFirst + 1),
+ Array (myLocArray[0], theFirst, theLast)
{
- Standard_RangeError_Raise_if(theFirst > theLast, " ");
+ //
}
math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst,
const Standard_Integer theLast,
- const Standard_Integer theInitialValue) :
- FirstIndex(theFirst),
- LastIndex(theLast),
- Array(theFirst, theLast)
+ const Standard_Integer theInitialValue)
+: myLocArray (theLast - theFirst + 1),
+ Array (myLocArray[0], theFirst, theLast)
{
- Standard_RangeError_Raise_if(theFirst > theLast, " ");
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 theLast) :
- FirstIndex(theFirst),
- LastIndex(theLast),
- Array(theTab, theFirst, theLast)
+ const Standard_Integer theLast)
+: Array (*theTab, theFirst, theLast)
{
Standard_RangeError_Raise_if(theFirst > theLast, " ");
}
Array.Init(theInitialValue);
}
-math_IntegerVector::math_IntegerVector(const math_IntegerVector& theOther) :
- FirstIndex(theOther.FirstIndex),
- LastIndex(theOther.LastIndex),
- Array(theOther.Array)
+math_IntegerVector::math_IntegerVector (const math_IntegerVector& theOther)
+: myLocArray (theOther.Length()),
+ Array (myLocArray[0], theOther.Lower(), theOther.Upper())
{
+ memcpy (&myLocArray[0], &theOther.Array.First(), sizeof(Standard_Integer) * theOther.Length());
}
void math_IntegerVector::SetFirst(const Standard_Integer theFirst)
{
- Array.SetLower(theFirst);
- LastIndex = LastIndex - FirstIndex + theFirst;
- FirstIndex = theFirst;
+ Array.Resize (theFirst, Array.Upper() - Array.Lower() + theFirst, Standard_False);
}
Standard_Real math_IntegerVector::Norm() const
{
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);
}
Standard_Real math_IntegerVector::Norm2() const
{
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);
}
{
Standard_Integer I=0;
Standard_Real X = RealFirst();
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
if(Array(Index) > X)
{
{
Standard_Integer I=0;
Standard_Real X = RealLast();
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
if(Array(Index) < X)
{
Standard_Integer J;
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);
Array(Index) = Array(J);
Array(J) = Temp;
const Standard_Integer theI2,
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()), " ");
Standard_Integer I = theV.Lower();
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;
}
{
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
- Standard_Integer I = theRight.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ Standard_Integer I = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Array(Index) = Array(Index) + theRight.Array(I);
I++;
void math_IntegerVector::Subtract(const math_IntegerVector& theRight)
{
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
- Standard_Integer I = theRight.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ Standard_Integer I = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Array(Index) = Array(Index) - theRight.Array(I);
I++;
math_IntegerVector math_IntegerVector::Slice(const Standard_Integer theI1,
const Standard_Integer theI2) const
{
- Standard_DimensionError_Raise_if((theI1 < FirstIndex) || (theI1 > LastIndex) ||
- (theI2 < FirstIndex) || (theI2 > LastIndex), " ");
+ Standard_DimensionError_Raise_if((theI1 < Lower()) || (theI1 > Upper()) ||
+ (theI2 < Lower()) || (theI2 > Upper()), " ");
if(theI2 >= theI1)
{
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++)
{
Result = Result + Array(Index) * theRight.Array(I);
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;
}
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;
}
{
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
- math_IntegerVector Result(FirstIndex, LastIndex);
+ math_IntegerVector Result(Lower(), Upper());
- Standard_Integer I = theRight.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ Standard_Integer I = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Result.Array(Index) = Array(Index) + theRight.Array(I);
I++;
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);
}
{
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
- math_IntegerVector Result(FirstIndex, LastIndex);
+ math_IntegerVector Result(Lower(), Upper());
- Standard_Integer I = theRight.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ Standard_Integer I = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Result.Array(Index) = Array(Index) - theRight.Array(I);
I++;
Standard_DimensionError_Raise_if((Length() != theRight.Length()) ||
(theRight.Length() != theLeft.Length()), " ");
- Standard_Integer I = theLeft.FirstIndex;
- Standard_Integer J = theRight.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ Standard_Integer I = theLeft.Lower();
+ Standard_Integer J = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Array(Index) = theLeft.Array(I) + theRight.Array(J);
I++;
Standard_DimensionError_Raise_if((Length() != theRight.Length()) ||
(theRight.Length() != theLeft.Length()), " ");
- Standard_Integer I = theLeft.FirstIndex;
- Standard_Integer J = theRight.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ Standard_Integer I = theLeft.Lower();
+ Standard_Integer J = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Array(Index) = theLeft.Array(I) - theRight.Array(J);
I++;
void math_IntegerVector::Multiply(const Standard_Integer theLeft, const math_IntegerVector& theRight)
{
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);
}
math_IntegerVector& math_IntegerVector::Initialized(const math_IntegerVector& theOther)
{
Standard_DimensionError_Raise_if(Length() != theOther.Length(), " ");
-
- (theOther.Array).Copy(Array);
+ memmove (&Array.ChangeFirst(), &theOther.Array.First(), sizeof(Standard_Integer) * Array.Length());
return *this;
}
void math_IntegerVector::Dump(Standard_OStream& theO) const
{
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";
}
}
-
#ifndef _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
#ifdef Opposite
//! constructs an IntegerVector in the range [Lower..Upper]
//! 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.
//! An exception is raised if the lengths of the IntegerVectors
//! returns the length of an IntegerVector
inline Standard_Integer Length() const
{
- return LastIndex - FirstIndex +1;
+ return Array.Length();
}
//! returns the value of the Lower index of an IntegerVector.
inline Standard_Integer Lower() const
{
- return FirstIndex;
+ return Array.Lower();
}
//! returns the value of the Upper index of an IntegerVector.
inline Standard_Integer Upper() const
{
- return LastIndex;
+ return Array.Upper();
}
//! returns the value of the norm of an IntegerVector.
//! An exception is raised if the IntegerVectors have not the same length.
Standard_EXPORT void Subtract(const math_IntegerVector& theLeft, const math_IntegerVector& theRight);
+ //! accesses the value of index theNum of an IntegerVector.
+ const Standard_Integer& Value (const Standard_Integer theNum) const
+ {
+ return Array(theNum);
+ }
+
//! accesses (in read or write mode) the value of index theNum of an IntegerVector.
- inline Standard_Integer& Value(const Standard_Integer theNum) const
+ inline Standard_Integer& Value (const Standard_Integer theNum)
{
- Standard_RangeError_Raise_if(theNum < FirstIndex || theNum > LastIndex, " ");
return Array(theNum);
}
- Standard_Integer& operator()(const Standard_Integer theNum) const
+ const Standard_Integer& operator()(const Standard_Integer theNum) const
+ {
+ return Value(theNum);
+ }
+
+ Standard_Integer& operator()(const Standard_Integer theNum)
{
return Value(theNum);
}
private:
- Standard_Integer FirstIndex;
- Standard_Integer LastIndex;
- math_SingleTab<Standard_Integer> Array;
+ NCollection_LocalArray<Standard_Integer, 512> myLocArray;
+ NCollection_Array1<Standard_Integer> Array;
+
};
#endif
Standard_DimensionError_Raise_if (ColNumber() != V.Length(),
"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++) {
Array(Row, Index) = V.Array(I);
I++;
Standard_DimensionError_Raise_if (RowNumber() != V.Length(),
"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++) {
Array(Index, Col) = V.Array(I);
I++;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Result.Array(I) = 0.0;
- Standard_Integer II = Right.LowerIndex;
+ Standard_Integer II = Right.Lower();
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Result.Array(I) = Result.Array(I) + Array(I, J) * Right.Array(II);
II++;
void math_SVD::Solve (const math_Vector& B,
math_Vector& X,
- const Standard_Real Eps) const
+ const Standard_Real Eps)
{
StdFail_NotDone_Raise_if(!Done, " ");
Standard_DimensionError_Raise_if((RowA != B.Length()) ||
}
void math_SVD::PseudoInverse (math_Matrix& Result,
- const Standard_Real Eps) const
+ const Standard_Real Eps)
{
Standard_Integer i, j ;
//! equal to the rowrange of A.
//! Exception DimensionError is raised if the range of X is not
//! 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.
//! Exceptions
//! StdFail_NotDone if the algorithm fails (and IsDone returns false).
//! Standard_DimensionError if the ranges of Inv are
//! 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.
//! Is used to redefine the operator <<.
+++ /dev/null
-// 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
#include <Standard_RangeError.hxx>
#include <Standard_NullValue.hxx>
-math_Vector::math_Vector(const Standard_Integer theLower, const Standard_Integer theUpper) :
- LowerIndex(theLower),
- UpperIndex(theUpper),
- Array(theLower,theUpper)
+math_Vector::math_Vector(const Standard_Integer theLower, const Standard_Integer theUpper)
+: myLocArray (theUpper - theLower + 1),
+ Array (myLocArray[0], theLower, theUpper)
{
- Standard_RangeError_Raise_if (theLower > theUpper, "math_Vector() - invalid dimensions");
+ //
}
math_Vector::math_Vector(const Standard_Integer theLower,
const Standard_Integer theUpper,
- const Standard_Real theInitialValue):
- LowerIndex(theLower),
- UpperIndex(theUpper),
- Array(theLower,theUpper)
+ const Standard_Real theInitialValue)
+: myLocArray (theUpper - theLower + 1),
+ Array (myLocArray[0], theLower, theUpper)
{
- Standard_RangeError_Raise_if (theLower > theUpper, "math_Vector() - invalid dimensions");
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 theUpper) :
- LowerIndex(theLower),
- UpperIndex(theUpper),
- Array(theTab, theLower,theUpper)
+ const Standard_Integer theUpper)
+: Array (*theTab, theLower, theUpper)
{
Standard_RangeError_Raise_if ((theLower > theUpper), "math_Vector() - invalid dimensions");
}
-math_Vector::math_Vector(const gp_XY& theOther):
- LowerIndex(1),
- UpperIndex(2),
- Array(1,2)
+math_Vector::math_Vector (const gp_XY& theOther)
+: myLocArray (2),
+ Array (myLocArray[0], 1,2)
{
Array(1) = theOther.X();
Array(2) = theOther.Y();
}
-math_Vector::math_Vector(const gp_XYZ& theOther):
- LowerIndex(1),
- UpperIndex(3),
- Array(1, 3)
+math_Vector::math_Vector (const gp_XYZ& theOther)
+: myLocArray (3),
+ Array (myLocArray[0], 1, 3)
{
Array(1) = theOther.X();
Array(2) = theOther.Y();
Array.Init(theInitialValue);
}
-math_Vector::math_Vector(const math_Vector& theOther) :
- LowerIndex(theOther.LowerIndex),
- UpperIndex(theOther.UpperIndex),
- Array(theOther.Array)
+math_Vector::math_Vector (const math_Vector& theOther)
+: myLocArray (theOther.Length()),
+ Array (myLocArray[0], theOther.Lower(), theOther.Upper())
{
+ memcpy (&myLocArray[0], &theOther.Array.First(), sizeof(Standard_Real) * theOther.Length());
}
void math_Vector::SetLower(const Standard_Integer theLower)
{
- Array.SetLower(theLower);
- UpperIndex = UpperIndex - LowerIndex + theLower;
- LowerIndex = theLower;
+ Array.Resize (theLower, Array.Upper() - Array.Lower() + theLower, Standard_False);
}
Standard_Real math_Vector::Norm() const
{
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);
}
{
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);
}
Standard_Integer I=0;
Standard_Real X = RealFirst();
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
if(Array(Index) > X)
{
Standard_Integer I=0;
Standard_Real X = RealLast();
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
if(Array(Index) < X)
{
const Standard_Integer theI2,
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()),
"math_Vector::Set() - invalid indices");
Standard_Real Result = Norm();
Standard_NullValue_Raise_if ((Result <= RealEpsilon()),
"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;
}
void math_Vector::Invert()
{
- Standard_Integer J;
- Standard_Real Temp;
- for(Standard_Integer Index = LowerIndex; Index <= (LowerIndex + Length()) >> 1 ; Index++)
+ for(Standard_Integer Index = Lower(); Index <= (Lower() + Length()) >> 1 ; Index++)
{
- J = UpperIndex + LowerIndex - Index;
- Temp = Array(Index);
+ Standard_Integer J = Upper() + Lower() - Index;
+ Standard_Real aTemp = Array(Index);
Array(Index) = Array(J);
- Array(J) = Temp;
+ Array(J) = aTemp;
}
}
math_Vector math_Vector::Multiplied(const Standard_Real theRight) const
{
- math_Vector Result (LowerIndex, UpperIndex);
-
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ math_Vector Result (Lower(), Upper());
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Result.Array(Index) = Array(Index) * theRight;
}
math_Vector math_Vector::TMultiplied(const Standard_Real theRight) const
{
- math_Vector Result (LowerIndex, UpperIndex);
-
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ math_Vector Result (Lower(), Upper());
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Result.Array(Index) = Array(Index) * 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;
}
Standard_DivideByZero_Raise_if (Abs(theRight) <= RealEpsilon(),
"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;
}
Standard_DimensionError_Raise_if (Length() != theRight.Length(),
"math_Vector::Add() - input vector has wrong dimensions");
- Standard_Integer I = theRight.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ Standard_Integer I = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Array(Index) = Array(Index) + theRight.Array(I);
I++;
Standard_DimensionError_Raise_if (Length() != theRight.Length(),
"math_Vector::Added() - input vector has wrong dimensions");
- math_Vector Result(LowerIndex, UpperIndex);
+ math_Vector Result (Lower(), Upper());
- Standard_Integer I = theRight.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ Standard_Integer I = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Result.Array(Index) = Array(Index) + theRight.Array(I);
I++;
Standard_DimensionError_Raise_if (Length() != theRight.Length(),
"math_Vector::Subtract() - input vector has wrong dimensions");
- Standard_Integer I = theRight.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ Standard_Integer I = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Array(Index) = Array(Index) - theRight.Array(I);
I++;
Standard_DimensionError_Raise_if (Length() != theRight.Length(),
"math_Vector::Subtracted() - input vector has wrong dimensions");
- math_Vector Result(LowerIndex, UpperIndex);
+ math_Vector Result(Lower(), Upper());
- Standard_Integer I = theRight.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ Standard_Integer I = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Result.Array(Index) = Array(Index) - theRight.Array(I);
I++;
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");
if(theI2 >= theI1)
Standard_DimensionError_Raise_if ((Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()),
"math_Vector::Add() - input vectors have wrong dimensions");
- Standard_Integer I = theLeft.LowerIndex;
- Standard_Integer J = theRight.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ Standard_Integer I = theLeft.Lower();
+ Standard_Integer J = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Array(Index) = theLeft.Array(I) + theRight.Array(J);
I++;
Standard_DimensionError_Raise_if ((Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()),
"math_Vector::Subtract() - input vectors have wrong dimensions");
- Standard_Integer I = theLeft.LowerIndex;
- Standard_Integer J = theRight.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ Standard_Integer I = theLeft.Lower();
+ Standard_Integer J = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Array(Index) = theLeft.Array(I) - theRight.Array(J);
I++;
|| (theLeft.ColNumber() != theRight.Length()),
"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++)
{
Array(Index) = 0.0;
- Standard_Integer K = theRight.LowerIndex;
+ Standard_Integer K = theRight.Lower();
for(Standard_Integer J = theLeft.LowerColIndex; J <= theLeft.UpperColIndex; J++)
{
Array(Index) = Array(Index) + theLeft.Array(I, J) * theRight.Array(K);
|| (theLeft.Length() != theRight.RowNumber()),
"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++)
{
Array(Index) = 0.0;
- Standard_Integer K = theLeft.LowerIndex;
+ Standard_Integer K = theLeft.Lower();
for(Standard_Integer I = theRight.LowerRowIndex; I <= theRight.UpperRowIndex; I++)
{
Array(Index) = Array(Index) + theLeft.Array(K) * theRight.Array(I, J);
|| (theTLeft.RowNumber() != theRight.Length()),
"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++)
{
Array(Index) = 0.0;
- Standard_Integer K = theRight.LowerIndex;
+ Standard_Integer K = theRight.Lower();
for(Standard_Integer J = theTLeft.LowerRowIndex; J <= theTLeft.UpperRowIndex; J++)
{
Array(Index) = Array(Index) + theTLeft.Array(J, I) * theRight.Array(K);
|| (theLeft.Length() != theTRight.ColNumber()),
"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++)
{
Array(Index) = 0.0;
- Standard_Integer K = theLeft.LowerIndex;
+ Standard_Integer K = theLeft.Lower();
for(Standard_Integer I = theTRight.LowerColIndex;
I <= theTRight.UpperColIndex; I++)
{
Standard_DimensionError_Raise_if (Length() != theRight.Length(),
"math_Vector::Multiplied() - input vector has wrong dimensions");
- Standard_Integer I = theRight.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ Standard_Integer I = theRight.Lower();
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Result = Result + Array(Index) * theRight.Array(I);
I++;
math_Vector math_Vector::Opposite()
{
- math_Vector Result(LowerIndex, UpperIndex);
-
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ math_Vector Result(Lower(), Upper());
+ for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
{
Result.Array(Index) = - Array(Index);
}
math_Vector Result(theRight.LowerColIndex, theRight.UpperColIndex);
for(Standard_Integer J2 = theRight.LowerColIndex; J2 <= theRight.UpperColIndex; J2++)
{
- Array(J2) = 0.0;
- Standard_Integer theI2 = theRight.LowerRowIndex;
- for(Standard_Integer I = LowerIndex; I <= UpperIndex; I++)
- {
- Result.Array(J2) = Result.Array(J2) + Array(I) * theRight.Array(theI2, J2);
- theI2++;
- }
+ Result.Array(J2) = 0.0;
+ Standard_Integer theI2 = theRight.LowerRowIndex;
+ for(Standard_Integer I = Lower(); I <= Upper(); I++)
+ {
+ Result.Array(J2) = Result.Array(J2) + Array(I) * theRight.Array(theI2, J2);
+ theI2++;
+ }
}
return Result;
}
{
Standard_DimensionError_Raise_if ((Length() != theRight.Length()),
"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);
}
{
Standard_DimensionError_Raise_if (Length() != theOther.Length(),
"math_Vector::Initialized() - input vector has wrong dimensions");
-
- (theOther.Array).Copy(Array);
+ memmove (&Array.ChangeFirst(), &theOther.Array.First(), sizeof(Standard_Real) * Array.Length());
return *this;
}
void math_Vector::Dump(Standard_OStream& theO) const
{
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";
}
#ifndef _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_XYZ.hxx>
//! Constructs a vector in the range [theLower..theUpper]
//! 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
Standard_EXPORT math_Vector(const gp_XY& Other);
//! Returns the length of a vector
inline Standard_Integer Length() const
{
- return UpperIndex - LowerIndex +1;
+ return Array.Length();
}
//! Returns the value of the theLower index of a vector.
inline Standard_Integer Lower() const
{
- return LowerIndex;
+ return Array.Lower();
}
//! Returns the value of the theUpper index of a vector.
inline Standard_Integer Upper() const
{
- return UpperIndex;
+ return Array.Upper();
}
//! Returns the value or the square of the norm of this vector.
//! Subtract whenever possible.
Standard_EXPORT void Subtract(const math_Vector& theLeft,const math_Vector& theRight);
+ //! accesses the value of index "theNum" of a vector.
+ const Standard_Real& Value (const Standard_Integer theNum) const
+ {
+ return Array(theNum);
+ }
+
//! accesses (in read or write mode) the value of index "theNum" of a vector.
- inline Standard_Real& Value(const Standard_Integer theNum) const
+ inline Standard_Real& Value (const Standard_Integer theNum)
{
- Standard_RangeError_Raise_if(theNum < LowerIndex || theNum > UpperIndex, " ");
return Array(theNum);
}
- Standard_Real& operator()(const Standard_Integer theNum) const
+ const Standard_Real& operator()(const Standard_Integer theNum) const
+ {
+ return Value(theNum);
+ }
+
+ Standard_Real& operator()(const Standard_Integer theNum)
{
return Value(theNum);
}
private:
- Standard_Integer LowerIndex;
- Standard_Integer UpperIndex;
- math_SingleTab<Standard_Real> Array;
+ NCollection_LocalArray<Standard_Real, 512> myLocArray;
+ NCollection_Array1<Standard_Real> Array;
+
};
#endif