mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0033370: Foundation Classes - Moving into STL and Boost functionality
NCollection containers update: - NCollection_Array1 - updated functionality - NCollection_Array2 - NCollection_Array1 as a wrapper for 2array - NCollection_Vector -> NCollection_DynamicArray was renamed and reworked. TCollection: - Use static empty string to avoid allocations on empty string NCollection allocators update: - NCollection_Allocator - allocator that used Standard::Allocate - NCollection_OccAllocator - allocator-wrapper that used OCC BaseAllocator objects - NCollection_IncAllocator - rework to increase performance Standard: - Rework functionality to use different allocation libs - Implement basic of new way to wrap allocations tools - Define 4 ways to allocation (defines in configure stage) Additional changes: - Hash function uses std::hash functionality - size_t as a hash value - New HashUtils with Murmur and FVN hash algo for x32 and x64 - Deprecated _0.cxx and .gxx DE classes reorganized - Create own utility for std memory - Update Standard_Transient to be more platform-independent Math TK changes: - math_Vector -> match_BaseVector<> - Buffer decreased to cash 32 elements instead of 512
This commit is contained in:
@@ -74,7 +74,6 @@ math_GlobOptMin.hxx
|
||||
math_Householder.cxx
|
||||
math_Householder.hxx
|
||||
math_Householder.lxx
|
||||
math_IntegerVector.cxx
|
||||
math_IntegerVector.hxx
|
||||
math_Jacobi.cxx
|
||||
math_Jacobi.hxx
|
||||
@@ -122,5 +121,6 @@ math_Uzawa.cxx
|
||||
math_Uzawa.hxx
|
||||
math_Uzawa.lxx
|
||||
math_ValueAndWeight.hxx
|
||||
math_Vector.cxx
|
||||
math_VectorBase.hxx
|
||||
math_VectorBase.lxx
|
||||
math_Vector.hxx
|
||||
|
@@ -1,336 +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.
|
||||
|
||||
#include <math_IntegerVector.hxx>
|
||||
|
||||
#include <Standard_DimensionError.hxx>
|
||||
#include <Standard_RangeError.hxx>
|
||||
|
||||
math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast)
|
||||
: myLocArray (theLast - theFirst + 1),
|
||||
Array (myLocArray[0], theFirst, theLast)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst,
|
||||
const Standard_Integer theLast,
|
||||
const Standard_Integer theInitialValue)
|
||||
: myLocArray (theLast - theFirst + 1),
|
||||
Array (myLocArray[0], theFirst, theLast)
|
||||
{
|
||||
Array.Init(theInitialValue);
|
||||
}
|
||||
|
||||
math_IntegerVector::math_IntegerVector(const Standard_Integer* theTab,
|
||||
const Standard_Integer theFirst,
|
||||
const Standard_Integer theLast)
|
||||
: Array (*theTab, theFirst, theLast)
|
||||
{
|
||||
Standard_RangeError_Raise_if(theFirst > theLast, " ");
|
||||
}
|
||||
|
||||
void math_IntegerVector::Init(const Standard_Integer theInitialValue)
|
||||
{
|
||||
Array.Init(theInitialValue);
|
||||
}
|
||||
|
||||
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.Resize (theFirst, Array.Upper() - Array.Lower() + theFirst, Standard_False);
|
||||
}
|
||||
|
||||
Standard_Real math_IntegerVector::Norm() const
|
||||
{
|
||||
Standard_Real Result = 0;
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result = Result + Array(Index) * Array(Index);
|
||||
}
|
||||
return Sqrt(Result);
|
||||
}
|
||||
|
||||
Standard_Real math_IntegerVector::Norm2() const
|
||||
{
|
||||
Standard_Real Result = 0;
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result = Result + Array(Index) * Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
Standard_Integer math_IntegerVector::Max() const
|
||||
{
|
||||
Standard_Integer I=0;
|
||||
Standard_Real X = RealFirst();
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
if(Array(Index) > X)
|
||||
{
|
||||
X = Array(Index);
|
||||
I = Index;
|
||||
}
|
||||
}
|
||||
return I;
|
||||
}
|
||||
|
||||
Standard_Integer math_IntegerVector::Min() const
|
||||
{
|
||||
Standard_Integer I=0;
|
||||
Standard_Real X = RealLast();
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
if(Array(Index) < X)
|
||||
{
|
||||
X = Array(Index);
|
||||
I = Index;
|
||||
}
|
||||
}
|
||||
return I;
|
||||
}
|
||||
|
||||
void math_IntegerVector::Invert()
|
||||
{
|
||||
Standard_Integer J;
|
||||
Standard_Integer Temp;
|
||||
|
||||
for(Standard_Integer Index = Lower(); Index <= Lower() + Length() / 2 ; Index++)
|
||||
{
|
||||
J = Upper() + Lower() - Index;
|
||||
Temp = Array(Index);
|
||||
Array(Index) = Array(J);
|
||||
Array(J) = Temp;
|
||||
}
|
||||
}
|
||||
|
||||
math_IntegerVector math_IntegerVector::Inverse() const
|
||||
{
|
||||
math_IntegerVector Result = *this;
|
||||
Result.Invert();
|
||||
return Result;
|
||||
}
|
||||
|
||||
void math_IntegerVector::Set(const Standard_Integer theI1,
|
||||
const Standard_Integer theI2,
|
||||
const math_IntegerVector &theV)
|
||||
{
|
||||
Standard_DimensionError_Raise_if((theI1 < Lower()) || (theI2 > Upper()) ||
|
||||
(theI1 > theI2) || (theI2 - theI1 + 1 != theV.Length()), " ");
|
||||
|
||||
Standard_Integer I = theV.Lower();
|
||||
for(Standard_Integer Index = theI1; Index <= theI2; Index++)
|
||||
{
|
||||
Array(Index) = theV.Array(I);
|
||||
I++;
|
||||
}
|
||||
}
|
||||
|
||||
void math_IntegerVector::Multiply(const Standard_Integer theRight)
|
||||
{
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Array(Index) = Array(Index) * theRight;
|
||||
}
|
||||
}
|
||||
|
||||
void math_IntegerVector::Add(const math_IntegerVector& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
|
||||
|
||||
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.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 < Lower()) || (theI1 > Upper()) ||
|
||||
(theI2 < Lower()) || (theI2 > Upper()), " ");
|
||||
|
||||
if(theI2 >= theI1)
|
||||
{
|
||||
math_IntegerVector Result(theI1, theI2);
|
||||
for(Standard_Integer Index = theI1; Index <= theI2; Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
math_IntegerVector Result(theI2, theI1);
|
||||
for(Standard_Integer Index = theI1; Index >= theI2; Index--)
|
||||
{
|
||||
Result.Array(Index) = Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
|
||||
Standard_Integer math_IntegerVector::Multiplied (const math_IntegerVector& theRight) const
|
||||
{
|
||||
Standard_Integer Result = 0;
|
||||
|
||||
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for(Standard_Integer Index = 0; Index < Length(); Index++)
|
||||
{
|
||||
Result = Result + Array(Index) * theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
math_IntegerVector math_IntegerVector::Multiplied (const Standard_Integer theRight)const
|
||||
{
|
||||
math_IntegerVector Result(Lower(), Upper());
|
||||
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) * theRight;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
math_IntegerVector math_IntegerVector::TMultiplied (const Standard_Integer theRight) const
|
||||
{
|
||||
math_IntegerVector Result(Lower(), Upper());
|
||||
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) * theRight;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
math_IntegerVector math_IntegerVector::Added (const math_IntegerVector& theRight) const
|
||||
{
|
||||
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
|
||||
|
||||
math_IntegerVector Result(Lower(), Upper());
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) + theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
math_IntegerVector math_IntegerVector::Opposite()
|
||||
{
|
||||
math_IntegerVector Result(Lower(), Upper());
|
||||
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = - Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
math_IntegerVector math_IntegerVector::Subtracted (const math_IntegerVector& theRight) const
|
||||
{
|
||||
Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
|
||||
|
||||
math_IntegerVector Result(Lower(), Upper());
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) - theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
void math_IntegerVector::Add (const math_IntegerVector& theLeft, const math_IntegerVector& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if((Length() != theRight.Length()) ||
|
||||
(theRight.Length() != theLeft.Length()), " ");
|
||||
|
||||
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++;
|
||||
J++;
|
||||
}
|
||||
}
|
||||
|
||||
void math_IntegerVector::Subtract (const math_IntegerVector& theLeft,
|
||||
const math_IntegerVector& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if((Length() != theRight.Length()) ||
|
||||
(theRight.Length() != theLeft.Length()), " ");
|
||||
|
||||
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++;
|
||||
J++;
|
||||
}
|
||||
}
|
||||
|
||||
void math_IntegerVector::Multiply(const Standard_Integer theLeft, const math_IntegerVector& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if((Length() != theRight.Length()), " ");
|
||||
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(), " ");
|
||||
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 = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
theO << "math_IntegerVector(" << Index << ") = " << Array(Index) << "\n";
|
||||
}
|
||||
}
|
@@ -15,13 +15,7 @@
|
||||
#ifndef _math_IntegerVector_HeaderFile
|
||||
#define _math_IntegerVector_HeaderFile
|
||||
|
||||
#include <NCollection_Array1.hxx>
|
||||
#include <NCollection_LocalArray.hxx>
|
||||
|
||||
// resolve name collisions with X11 headers
|
||||
#ifdef Opposite
|
||||
#undef Opposite
|
||||
#endif
|
||||
#include <math_VectorBase.hxx>
|
||||
|
||||
//! This class implements the real IntegerVector abstract data type.
|
||||
//! IntegerVectors can have an arbitrary range which must be define at
|
||||
@@ -52,221 +46,7 @@
|
||||
//! V3 = V1; // --> will raise DimensionError;
|
||||
//! V1.Add(V3) // --> will raise DimensionError;
|
||||
//! @endcode
|
||||
class math_IntegerVector
|
||||
{
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
//! constructs an IntegerVector in the range [Lower..Upper]
|
||||
Standard_EXPORT math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast);
|
||||
|
||||
//! constructs an IntegerVector in the range [Lower..Upper]
|
||||
//! with all the elements set to theInitialValue.
|
||||
Standard_EXPORT math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast, const Standard_Integer theInitialValue);
|
||||
|
||||
//! Initialize an IntegerVector with all the elements
|
||||
//! set to theInitialValue.
|
||||
Standard_EXPORT void Init(const Standard_Integer theInitialValue);
|
||||
|
||||
//! constructs an IntegerVector in the range [Lower..Upper]
|
||||
//! which share the "c array" theTab.
|
||||
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
|
||||
//! are different.
|
||||
Standard_EXPORT math_IntegerVector(const math_IntegerVector& theOther);
|
||||
|
||||
//! returns the length of an IntegerVector
|
||||
inline Standard_Integer Length() const
|
||||
{
|
||||
return Array.Length();
|
||||
}
|
||||
|
||||
//! returns the value of the Lower index of an IntegerVector.
|
||||
inline Standard_Integer Lower() const
|
||||
{
|
||||
return Array.Lower();
|
||||
}
|
||||
|
||||
//! returns the value of the Upper index of an IntegerVector.
|
||||
inline Standard_Integer Upper() const
|
||||
{
|
||||
return Array.Upper();
|
||||
}
|
||||
|
||||
//! returns the value of the norm of an IntegerVector.
|
||||
Standard_EXPORT Standard_Real Norm() const;
|
||||
|
||||
//! returns the value of the square of the norm of an IntegerVector.
|
||||
Standard_EXPORT Standard_Real Norm2() const;
|
||||
|
||||
//! returns the value of the Index of the maximum element of an IntegerVector.
|
||||
Standard_EXPORT Standard_Integer Max() const;
|
||||
|
||||
//! returns the value of the Index of the minimum element of an IntegerVector.
|
||||
Standard_EXPORT Standard_Integer Min() const;
|
||||
|
||||
//! inverses an IntegerVector.
|
||||
Standard_EXPORT void Invert();
|
||||
|
||||
//! returns the inverse IntegerVector of an IntegerVector.
|
||||
Standard_EXPORT math_IntegerVector Inverse() const;
|
||||
|
||||
//! sets an IntegerVector from "theI1" to "theI2" to the IntegerVector "theV";
|
||||
//! An exception is raised if "theI1" is less than "LowerIndex" or "theI2" is greater than "UpperIndex" or "theI1" is greater than "theI2".
|
||||
//! An exception is raised if "theI2-theI1+1" is different from the Length of "theV".
|
||||
Standard_EXPORT void Set(const Standard_Integer theI1, const Standard_Integer theI2, const math_IntegerVector& theV);
|
||||
|
||||
//! slices the values of the IntegerVector between "theI1" and "theI2":
|
||||
//! Example: [2, 1, 2, 3, 4, 5] becomes [2, 4, 3, 2, 1, 5] between 2 and 5.
|
||||
//! An exception is raised if "theI1" is less than "LowerIndex" or "theI2" is greater than "UpperIndex".
|
||||
Standard_EXPORT math_IntegerVector Slice(const Standard_Integer theI1, const Standard_Integer theI2) const;
|
||||
|
||||
//! returns the product of an IntegerVector by an integer value.
|
||||
Standard_EXPORT void Multiply(const Standard_Integer theRight);
|
||||
|
||||
void operator *=(const Standard_Integer theRight)
|
||||
{
|
||||
Multiply(theRight);
|
||||
}
|
||||
|
||||
//! returns the product of an IntegerVector by an integer value.
|
||||
Standard_NODISCARD Standard_EXPORT math_IntegerVector Multiplied(const Standard_Integer theRight) const;
|
||||
|
||||
Standard_NODISCARD math_IntegerVector operator*(const Standard_Integer theRight) const
|
||||
{
|
||||
return Multiplied(theRight);
|
||||
}
|
||||
|
||||
//! returns the product of a vector and a real value.
|
||||
Standard_NODISCARD Standard_EXPORT math_IntegerVector TMultiplied(const Standard_Integer theRight) const;
|
||||
|
||||
friend inline math_IntegerVector operator* (const Standard_Integer theLeft, const math_IntegerVector& theRight)
|
||||
{
|
||||
return theRight.Multiplied(theLeft);
|
||||
}
|
||||
|
||||
//! adds the IntegerVector "theRight" to an IntegerVector.
|
||||
//! An exception is raised if the IntegerVectors have not the same length.
|
||||
//! An exception is raised if the lengths are not equal.
|
||||
Standard_EXPORT void Add(const math_IntegerVector& theRight);
|
||||
|
||||
void operator +=(const math_IntegerVector& theRight)
|
||||
{
|
||||
Add(theRight);
|
||||
}
|
||||
|
||||
//! adds the IntegerVector "theRight" to an IntegerVector.
|
||||
//! An exception is raised if the IntegerVectors have not the same length.
|
||||
//! An exception is raised if the lengths are not equal.
|
||||
Standard_NODISCARD Standard_EXPORT math_IntegerVector Added(const math_IntegerVector& theRight) const;
|
||||
|
||||
Standard_NODISCARD math_IntegerVector operator+(const math_IntegerVector& theRight) const
|
||||
{
|
||||
return Added(theRight);
|
||||
}
|
||||
|
||||
//! sets an IntegerVector to the sum of the IntegerVector
|
||||
//! "theLeft" and the IntegerVector "theRight".
|
||||
//! An exception is raised if the lengths are different.
|
||||
Standard_EXPORT void Add(const math_IntegerVector& theLeft, const math_IntegerVector& theRight);
|
||||
|
||||
//! sets an IntegerVector to the substraction of "theRight" from "theLeft".
|
||||
//! 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
//! Initialises an IntegerVector by copying "theOther".
|
||||
//! An exception is raised if the Lengths are different.
|
||||
Standard_EXPORT math_IntegerVector& Initialized(const math_IntegerVector& theOther);
|
||||
|
||||
math_IntegerVector& operator=(const math_IntegerVector& theOther)
|
||||
{
|
||||
return Initialized(theOther);
|
||||
}
|
||||
|
||||
//! returns the inner product of 2 IntegerVectors.
|
||||
//! An exception is raised if the lengths are not equal.
|
||||
Standard_NODISCARD Standard_EXPORT Standard_Integer Multiplied(const math_IntegerVector& theRight) const;
|
||||
|
||||
Standard_NODISCARD Standard_Integer operator*(const math_IntegerVector& theRight) const
|
||||
{
|
||||
return Multiplied(theRight);
|
||||
}
|
||||
|
||||
//! returns the opposite of an IntegerVector.
|
||||
Standard_EXPORT math_IntegerVector Opposite();
|
||||
|
||||
math_IntegerVector operator-()
|
||||
{
|
||||
return Opposite();
|
||||
}
|
||||
|
||||
//! returns the subtraction of "theRight" from "me".
|
||||
//! An exception is raised if the IntegerVectors have not the same length.
|
||||
Standard_EXPORT void Subtract(const math_IntegerVector& theRight);
|
||||
|
||||
void operator-=(const math_IntegerVector& theRight)
|
||||
{
|
||||
Subtract(theRight);
|
||||
}
|
||||
|
||||
//! returns the subtraction of "theRight" from "me".
|
||||
//! An exception is raised if the IntegerVectors have not the same length.
|
||||
Standard_NODISCARD Standard_EXPORT math_IntegerVector Subtracted(const math_IntegerVector& theRight) const;
|
||||
|
||||
Standard_NODISCARD math_IntegerVector operator-(const math_IntegerVector& theRight) const
|
||||
{
|
||||
return Subtracted(theRight);
|
||||
}
|
||||
|
||||
//! returns the multiplication of an integer by an IntegerVector.
|
||||
Standard_EXPORT void Multiply(const Standard_Integer theLeft,const math_IntegerVector& theRight);
|
||||
|
||||
//! Prints on the stream theO information on the current state of the object.
|
||||
//! Is used to redefine the operator <<.
|
||||
Standard_EXPORT void Dump(Standard_OStream& theO) const;
|
||||
|
||||
friend inline Standard_OStream& operator<<(Standard_OStream& theO, const math_IntegerVector& theVec)
|
||||
{
|
||||
theVec.Dump(theO);
|
||||
return theO;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//! is used internally to set the Lower value of the IntegerVector.
|
||||
void SetFirst(const Standard_Integer theFirst);
|
||||
|
||||
private:
|
||||
|
||||
NCollection_LocalArray<Standard_Integer, 512> myLocArray;
|
||||
NCollection_Array1<Standard_Integer> Array;
|
||||
|
||||
};
|
||||
using math_IntegerVector = math_VectorBase<int>;
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -12,9 +12,10 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <math_Matrix.hxx>
|
||||
|
||||
#include <math_Gauss.hxx>
|
||||
#include <math_Matrix.hxx>
|
||||
#include <math_IntegerVector.hxx>
|
||||
#include <math_NotSquare.hxx>
|
||||
#include <math_SingularMatrix.hxx>
|
||||
#include <math_Vector.hxx>
|
||||
@@ -644,6 +645,15 @@ math_Vector math_Matrix::Multiplied(const math_Vector& Right)const
|
||||
return Result;
|
||||
}
|
||||
|
||||
//================================================================
|
||||
// Function : operator*
|
||||
// Purpose :
|
||||
//================================================================
|
||||
math_VectorBase<> math_Matrix::operator* (const math_VectorBase<>& Right) const
|
||||
{
|
||||
return Multiplied(Right);
|
||||
}
|
||||
|
||||
math_Matrix& math_Matrix::Initialized(const math_Matrix& Other)
|
||||
{
|
||||
Standard_DimensionError_Raise_if ((RowNumber() != Other.RowNumber())
|
||||
|
@@ -19,9 +19,9 @@
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_DefineAlloc.hxx>
|
||||
#include <NCollection_Allocator.hxx>
|
||||
|
||||
#include <math_DoubleTab.hxx>
|
||||
#include <math_Vector.hxx>
|
||||
#include <Standard_OStream.hxx>
|
||||
|
||||
// resolve name collisions with X11 headers
|
||||
@@ -29,6 +29,8 @@
|
||||
#undef Opposite
|
||||
#endif
|
||||
|
||||
template<typename T = double> class math_VectorBase;
|
||||
|
||||
//! This class implements the real matrix abstract data type.
|
||||
//! Matrixes can have an arbitrary range which must be defined
|
||||
//! at the declaration and cannot be changed after this declaration
|
||||
@@ -74,6 +76,7 @@ public:
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
friend class math_VectorBase<>;
|
||||
|
||||
//! Constructs a non-initialized matrix of range [LowerRow..UpperRow,
|
||||
//! LowerCol..UpperCol]
|
||||
@@ -278,24 +281,24 @@ Standard_NODISCARD math_Matrix operator- (const math_Matrix& Right) const
|
||||
//! An exception is raised if the dimensions are different.
|
||||
//! An exception is raises if <Row> is inferior to the lower
|
||||
//! row of the matrix or <Row> is superior to the upper row.
|
||||
Standard_EXPORT void SetRow (const Standard_Integer Row, const math_Vector& V);
|
||||
Standard_EXPORT void SetRow (const Standard_Integer Row, const math_VectorBase<>& V);
|
||||
|
||||
//! Sets the column of index Col of a matrix to the vector <V>.
|
||||
//! An exception is raised if the dimensions are different.
|
||||
//! An exception is raises if <Col> is inferior to the lower
|
||||
//! column of the matrix or <Col> is superior to the upper
|
||||
//! column.
|
||||
Standard_EXPORT void SetCol (const Standard_Integer Col, const math_Vector& V);
|
||||
Standard_EXPORT void SetCol (const Standard_Integer Col, const math_VectorBase<>& V);
|
||||
|
||||
//! Sets the diagonal of a matrix to the value <Value>.
|
||||
//! An exception is raised if the matrix is not square.
|
||||
Standard_EXPORT void SetDiag (const Standard_Real Value);
|
||||
|
||||
//! Returns the row of index Row of a matrix.
|
||||
Standard_EXPORT math_Vector Row (const Standard_Integer Row) const;
|
||||
Standard_EXPORT math_VectorBase<> Row (const Standard_Integer Row) const;
|
||||
|
||||
//! Returns the column of index <Col> of a matrix.
|
||||
Standard_EXPORT math_Vector Col (const Standard_Integer Col) const;
|
||||
Standard_EXPORT math_VectorBase<> Col (const Standard_Integer Col) const;
|
||||
|
||||
//! Swaps the rows of index Row1 and Row2.
|
||||
//! An exception is raised if <Row1> or <Row2> is out of range.
|
||||
@@ -322,7 +325,7 @@ Standard_NODISCARD math_Matrix operator- (const math_Matrix& Right) const
|
||||
//! Computes a matrix as the product of 2 vectors.
|
||||
//! An exception is raised if the dimensions are different.
|
||||
//! <me> = <Left> * <Right>.
|
||||
Standard_EXPORT void Multiply (const math_Vector& Left, const math_Vector& Right);
|
||||
Standard_EXPORT void Multiply (const math_VectorBase<>& Left, const math_VectorBase<>& Right);
|
||||
|
||||
//! Computes a matrix as the product of 2 matrixes.
|
||||
//! An exception is raised if the dimensions are different.
|
||||
@@ -374,11 +377,8 @@ Standard_NODISCARD math_Matrix operator* (const math_Matrix& Right) const
|
||||
|
||||
//! Returns the product of a matrix by a vector.
|
||||
//! An exception is raised if the dimensions are different.
|
||||
Standard_NODISCARD Standard_EXPORT math_Vector Multiplied (const math_Vector& Right) const;
|
||||
Standard_NODISCARD math_Vector operator* (const math_Vector& Right) const
|
||||
{
|
||||
return Multiplied(Right);
|
||||
}
|
||||
Standard_NODISCARD Standard_EXPORT math_VectorBase<> Multiplied (const math_VectorBase<>& Right) const;
|
||||
Standard_NODISCARD Standard_EXPORT math_VectorBase<> operator* (const math_VectorBase<>& Right) const;
|
||||
|
||||
//! Returns the opposite of a matrix.
|
||||
//! An exception is raised if the dimensions are different.
|
||||
@@ -392,10 +392,6 @@ math_Matrix operator-()
|
||||
//! Is used to redefine the operator <<.
|
||||
Standard_EXPORT void Dump (Standard_OStream& o) const;
|
||||
|
||||
|
||||
friend class math_Vector;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -409,7 +405,7 @@ protected:
|
||||
//! The new lower row of the matrix is set to <LowerRow>
|
||||
//! and the new lower column of the matrix is set to the column
|
||||
//! of range <LowerCol>.
|
||||
void SetLower (const Standard_Integer LowerRow, const Standard_Integer LowerCol);
|
||||
void SetLower (const Standard_Integer LowerRow, const Standard_Integer LowerCol);
|
||||
|
||||
|
||||
|
||||
|
@@ -15,7 +15,6 @@
|
||||
// lpa le 29/10/91
|
||||
|
||||
#include <Standard_DimensionError.hxx>
|
||||
#include <math_Vector.hxx>
|
||||
|
||||
inline Standard_OStream& operator<<(Standard_OStream& o,
|
||||
const math_Matrix& mat)
|
||||
|
@@ -17,8 +17,11 @@
|
||||
|
||||
#include <Message_ProgressRange.hxx>
|
||||
|
||||
class math_IntegerVector;
|
||||
class math_Vector;
|
||||
#include <NCollection_Allocator.hxx>
|
||||
|
||||
template<typename T> class math_VectorBase;
|
||||
using math_IntegerVector = math_VectorBase<int>;
|
||||
using math_Vector = math_VectorBase<double>;
|
||||
class math_Matrix;
|
||||
|
||||
const Standard_Integer math_Status_UserAborted = -1;
|
||||
|
@@ -1,502 +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.
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <math_Vector.hxx>
|
||||
#include <math_Matrix.hxx>
|
||||
|
||||
#include <Standard_DimensionError.hxx>
|
||||
#include <Standard_DivideByZero.hxx>
|
||||
#include <Standard_RangeError.hxx>
|
||||
#include <Standard_NullValue.hxx>
|
||||
|
||||
math_Vector::math_Vector(const Standard_Integer theLower, const Standard_Integer theUpper)
|
||||
: myLocArray (theUpper - theLower + 1),
|
||||
Array (myLocArray[0], theLower, theUpper)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
math_Vector::math_Vector(const Standard_Integer theLower,
|
||||
const Standard_Integer theUpper,
|
||||
const Standard_Real theInitialValue)
|
||||
: myLocArray (theUpper - theLower + 1),
|
||||
Array (myLocArray[0], theLower, theUpper)
|
||||
{
|
||||
Array.Init(theInitialValue);
|
||||
}
|
||||
|
||||
math_Vector::math_Vector(const Standard_Real* theTab,
|
||||
const Standard_Integer theLower,
|
||||
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)
|
||||
: myLocArray (2),
|
||||
Array (myLocArray[0], 1,2)
|
||||
{
|
||||
Array(1) = theOther.X();
|
||||
Array(2) = theOther.Y();
|
||||
}
|
||||
|
||||
math_Vector::math_Vector (const gp_XYZ& theOther)
|
||||
: myLocArray (3),
|
||||
Array (myLocArray[0], 1, 3)
|
||||
{
|
||||
Array(1) = theOther.X();
|
||||
Array(2) = theOther.Y();
|
||||
Array(3) = theOther.Z();
|
||||
}
|
||||
|
||||
void math_Vector::Init(const Standard_Real theInitialValue)
|
||||
{
|
||||
Array.Init(theInitialValue);
|
||||
}
|
||||
|
||||
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.Resize (theLower, Array.Upper() - Array.Lower() + theLower, Standard_False);
|
||||
}
|
||||
|
||||
Standard_Real math_Vector::Norm() const
|
||||
{
|
||||
Standard_Real Result = 0;
|
||||
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result = Result + Array(Index) * Array(Index);
|
||||
}
|
||||
return Sqrt(Result);
|
||||
}
|
||||
|
||||
Standard_Real math_Vector::Norm2() const
|
||||
{
|
||||
Standard_Real Result = 0;
|
||||
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result = Result + Array(Index) * Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
Standard_Integer math_Vector::Max() const
|
||||
{
|
||||
Standard_Integer I=0;
|
||||
Standard_Real X = RealFirst();
|
||||
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
if(Array(Index) > X)
|
||||
{
|
||||
X = Array(Index);
|
||||
I = Index;
|
||||
}
|
||||
}
|
||||
return I;
|
||||
}
|
||||
|
||||
Standard_Integer math_Vector::Min() const
|
||||
{
|
||||
Standard_Integer I=0;
|
||||
Standard_Real X = RealLast();
|
||||
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
if(Array(Index) < X)
|
||||
{
|
||||
X = Array(Index);
|
||||
I = Index;
|
||||
}
|
||||
}
|
||||
return I;
|
||||
}
|
||||
|
||||
void math_Vector::Set(const Standard_Integer theI1,
|
||||
const Standard_Integer theI2,
|
||||
const math_Vector &theV)
|
||||
{
|
||||
Standard_RangeError_Raise_if ((theI1 < Lower()) || (theI2 > Upper())
|
||||
|| (theI1 > theI2) || (theI2 - theI1 + 1 != theV.Length()),
|
||||
"math_Vector::Set() - invalid indices");
|
||||
|
||||
Standard_Integer I = theV.Lower();
|
||||
for(Standard_Integer Index = theI1; Index <= theI2; Index++)
|
||||
{
|
||||
Array(Index) = theV.Array(I);
|
||||
I++;
|
||||
}
|
||||
}
|
||||
|
||||
void math_Vector::Normalize()
|
||||
{
|
||||
Standard_Real Result = Norm();
|
||||
Standard_NullValue_Raise_if ((Result <= RealEpsilon()),
|
||||
"math_Vector::Normalize() - vector has zero norm");
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Array(Index) = Array(Index) / Result;
|
||||
}
|
||||
}
|
||||
|
||||
math_Vector math_Vector::Normalized() const
|
||||
{
|
||||
math_Vector Result = *this;
|
||||
|
||||
Result.Normalize();
|
||||
return Result;
|
||||
}
|
||||
|
||||
void math_Vector::Invert()
|
||||
{
|
||||
for(Standard_Integer Index = Lower(); Index <= (Lower() + Length()) >> 1 ; Index++)
|
||||
{
|
||||
Standard_Integer J = Upper() + Lower() - Index;
|
||||
Standard_Real aTemp = Array(Index);
|
||||
Array(Index) = Array(J);
|
||||
Array(J) = aTemp;
|
||||
}
|
||||
}
|
||||
|
||||
math_Vector math_Vector::Inverse() const
|
||||
{
|
||||
math_Vector Result = *this;
|
||||
Result.Invert();
|
||||
return Result;
|
||||
}
|
||||
|
||||
math_Vector math_Vector::Multiplied(const Standard_Real theRight) const
|
||||
{
|
||||
math_Vector Result (Lower(), Upper());
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) * theRight;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
math_Vector math_Vector::TMultiplied(const Standard_Real theRight) const
|
||||
{
|
||||
math_Vector Result (Lower(), Upper());
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) * theRight;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
void math_Vector::Multiply(const Standard_Real theRight)
|
||||
{
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Array(Index) = Array(Index) * theRight;
|
||||
}
|
||||
}
|
||||
|
||||
void math_Vector::Divide(const Standard_Real theRight)
|
||||
{
|
||||
Standard_DivideByZero_Raise_if (Abs(theRight) <= RealEpsilon(),
|
||||
"math_Vector::Divide() - devisor is zero");
|
||||
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Array(Index) = Array(Index) / theRight;
|
||||
}
|
||||
}
|
||||
|
||||
math_Vector math_Vector::Divided (const Standard_Real theRight) const
|
||||
{
|
||||
Standard_DivideByZero_Raise_if (Abs(theRight) <= RealEpsilon(),
|
||||
"math_Vector::Divided() - devisor is zero");
|
||||
math_Vector temp = Multiplied(1./theRight);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void math_Vector::Add(const math_Vector& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if (Length() != theRight.Length(),
|
||||
"math_Vector::Add() - input vector has wrong dimensions");
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Array(Index) = Array(Index) + theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
}
|
||||
|
||||
math_Vector math_Vector::Added(const math_Vector& theRight) const
|
||||
{
|
||||
Standard_DimensionError_Raise_if (Length() != theRight.Length(),
|
||||
"math_Vector::Added() - input vector has wrong dimensions");
|
||||
|
||||
math_Vector Result (Lower(), Upper());
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) + theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
void math_Vector::Subtract(const math_Vector& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if (Length() != theRight.Length(),
|
||||
"math_Vector::Subtract() - input vector has wrong dimensions");
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Array(Index) = Array(Index) - theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
}
|
||||
|
||||
math_Vector math_Vector::Subtracted (const math_Vector& theRight) const
|
||||
{
|
||||
Standard_DimensionError_Raise_if (Length() != theRight.Length(),
|
||||
"math_Vector::Subtracted() - input vector has wrong dimensions");
|
||||
|
||||
math_Vector Result(Lower(), Upper());
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) - theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
math_Vector math_Vector::Slice(const Standard_Integer theI1, const Standard_Integer theI2) const
|
||||
{
|
||||
Standard_RangeError_Raise_if ((theI1 < Lower()) || (theI1 > Upper()) || (theI2 < Lower()) || (theI2 > Upper()),
|
||||
"math_Vector::Slice() - invalid indices");
|
||||
|
||||
if(theI2 >= theI1)
|
||||
{
|
||||
math_Vector Result(theI1, theI2);
|
||||
for(Standard_Integer Index = theI1; Index <= theI2; Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
math_Vector Result(theI2, theI1);
|
||||
for(Standard_Integer Index = theI1; Index >= theI2; Index--)
|
||||
{
|
||||
Result.Array(Index) = Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
|
||||
void math_Vector::Add (const math_Vector& theLeft, const math_Vector& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if ((Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()),
|
||||
"math_Vector::Add() - input vectors have wrong dimensions");
|
||||
|
||||
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++;
|
||||
J++;
|
||||
}
|
||||
}
|
||||
|
||||
void math_Vector::Subtract (const math_Vector& theLeft, const math_Vector& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if ((Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()),
|
||||
"math_Vector::Subtract() - input vectors have wrong dimensions");
|
||||
|
||||
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++;
|
||||
J++;
|
||||
}
|
||||
}
|
||||
|
||||
void math_Vector::Multiply(const math_Matrix& theLeft, const math_Vector& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if ((Length() != theLeft.RowNumber())
|
||||
|| (theLeft.ColNumber() != theRight.Length()),
|
||||
"math_Vector::Multiply() - input matrix and/or vector have wrong dimensions");
|
||||
|
||||
Standard_Integer Index = Lower();
|
||||
for(Standard_Integer I = theLeft.LowerRowIndex; I <= theLeft.UpperRowIndex; I++)
|
||||
{
|
||||
Array(Index) = 0.0;
|
||||
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);
|
||||
K++;
|
||||
}
|
||||
Index++;
|
||||
}
|
||||
}
|
||||
|
||||
void math_Vector::Multiply(const math_Vector& theLeft, const math_Matrix& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if ((Length() != theRight.ColNumber())
|
||||
|| (theLeft.Length() != theRight.RowNumber()),
|
||||
"math_Vector::Multiply() - input matrix and/or vector have wrong dimensions");
|
||||
|
||||
Standard_Integer Index = Lower();
|
||||
for(Standard_Integer J = theRight.LowerColIndex; J <= theRight.UpperColIndex; J++)
|
||||
{
|
||||
Array(Index) = 0.0;
|
||||
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);
|
||||
K++;
|
||||
}
|
||||
Index++;
|
||||
}
|
||||
}
|
||||
|
||||
void math_Vector::TMultiply(const math_Matrix& theTLeft, const math_Vector& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if ((Length() != theTLeft.ColNumber())
|
||||
|| (theTLeft.RowNumber() != theRight.Length()),
|
||||
"math_Vector::TMultiply() - input matrix and/or vector have wrong dimensions");
|
||||
|
||||
Standard_Integer Index = Lower();
|
||||
for(Standard_Integer I = theTLeft.LowerColIndex; I <= theTLeft.UpperColIndex; I++)
|
||||
{
|
||||
Array(Index) = 0.0;
|
||||
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);
|
||||
K++;
|
||||
}
|
||||
Index++;
|
||||
}
|
||||
}
|
||||
|
||||
void math_Vector::TMultiply(const math_Vector& theLeft, const math_Matrix& theTRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if ((Length() != theTRight.RowNumber())
|
||||
|| (theLeft.Length() != theTRight.ColNumber()),
|
||||
"math_Vector::TMultiply() - input matrix and/or vector have wrong dimensions");
|
||||
|
||||
Standard_Integer Index = Lower();
|
||||
for(Standard_Integer J = theTRight.LowerRowIndex; J <= theTRight.UpperRowIndex; J++)
|
||||
{
|
||||
Array(Index) = 0.0;
|
||||
Standard_Integer K = theLeft.Lower();
|
||||
for(Standard_Integer I = theTRight.LowerColIndex;
|
||||
I <= theTRight.UpperColIndex; I++)
|
||||
{
|
||||
Array(Index) = Array(Index) + theLeft.Array(K) * theTRight.Array(J, I);
|
||||
K++;
|
||||
}
|
||||
Index++;
|
||||
}
|
||||
}
|
||||
|
||||
Standard_Real math_Vector::Multiplied(const math_Vector& theRight) const
|
||||
{
|
||||
Standard_Real Result = 0;
|
||||
|
||||
Standard_DimensionError_Raise_if (Length() != theRight.Length(),
|
||||
"math_Vector::Multiplied() - input vector has wrong dimensions");
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result = Result + Array(Index) * theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
math_Vector math_Vector::Opposite()
|
||||
{
|
||||
math_Vector Result(Lower(), Upper());
|
||||
for(Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = - Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
math_Vector math_Vector::Multiplied(const math_Matrix& theRight)const
|
||||
{
|
||||
Standard_DimensionError_Raise_if (Length() != theRight.RowNumber(),
|
||||
"math_Vector::Multiplied() - input matrix has wrong dimensions");
|
||||
|
||||
math_Vector Result(theRight.LowerColIndex, theRight.UpperColIndex);
|
||||
for(Standard_Integer J2 = theRight.LowerColIndex; J2 <= theRight.UpperColIndex; J2++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
void math_Vector::Multiply(const Standard_Real theLeft, const math_Vector& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if ((Length() != theRight.Length()),
|
||||
"math_Vector::Multiply() - input vector has wrong dimensions");
|
||||
for(Standard_Integer I = Lower(); I <= Upper(); I++)
|
||||
{
|
||||
Array(I) = theLeft * theRight.Array(I);
|
||||
}
|
||||
}
|
||||
|
||||
math_Vector& math_Vector::Initialized(const math_Vector& theOther)
|
||||
{
|
||||
Standard_DimensionError_Raise_if (Length() != theOther.Length(),
|
||||
"math_Vector::Initialized() - input vector has wrong dimensions");
|
||||
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 = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
theO << "math_Vector(" << Index << ") = " << Array(Index) << "\n";
|
||||
}
|
||||
}
|
||||
|
@@ -15,17 +15,7 @@
|
||||
#ifndef _math_Vector_HeaderFile
|
||||
#define _math_Vector_HeaderFile
|
||||
|
||||
#include <NCollection_Array1.hxx>
|
||||
#include <NCollection_LocalArray.hxx>
|
||||
#include <gp_XY.hxx>
|
||||
#include <gp_XYZ.hxx>
|
||||
|
||||
// resolve name collisions with X11 headers
|
||||
#ifdef Opposite
|
||||
#undef Opposite
|
||||
#endif
|
||||
|
||||
class math_Matrix;
|
||||
#include <math_VectorBase.hxx>
|
||||
|
||||
//! This class implements the real vector abstract data type.
|
||||
//! Vectors can have an arbitrary range which must be defined at
|
||||
@@ -55,292 +45,6 @@ class math_Matrix;
|
||||
//! V3 = V1; // --> will raise DimensionError;
|
||||
//! V1.Add(V3) // --> will raise DimensionError;
|
||||
//! @endcode
|
||||
class math_Vector
|
||||
{
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
|
||||
//! Constructs a non-initialized vector in the range [theLower..theUpper]
|
||||
//! "theLower" and "theUpper" are the indexes of the lower and upper bounds of the constructed vector.
|
||||
Standard_EXPORT math_Vector(const Standard_Integer theLower, const Standard_Integer theUpper);
|
||||
|
||||
//! Constructs a vector in the range [theLower..theUpper]
|
||||
//! whose values are all initialized with the value "theInitialValue"
|
||||
Standard_EXPORT math_Vector(const Standard_Integer theLower, const Standard_Integer theUpper, const Standard_Real theInitialValue);
|
||||
|
||||
//! Constructs a vector in the range [theLower..theUpper]
|
||||
//! with the "c array" theTab.
|
||||
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);
|
||||
|
||||
//! Constructor for converting gp_XYZ to math_Vector
|
||||
Standard_EXPORT math_Vector(const gp_XYZ& Other);
|
||||
|
||||
//! Initialize all the elements of a vector with "theInitialValue".
|
||||
Standard_EXPORT void Init(const Standard_Real theInitialValue);
|
||||
|
||||
//! Constructs a copy for initialization.
|
||||
//! An exception is raised if the lengths of the vectors are different.
|
||||
Standard_EXPORT math_Vector(const math_Vector& theOther);
|
||||
|
||||
//! Returns the length of a vector
|
||||
inline Standard_Integer Length() const
|
||||
{
|
||||
return Array.Length();
|
||||
}
|
||||
|
||||
//! Returns the value of the theLower index of a vector.
|
||||
inline Standard_Integer Lower() const
|
||||
{
|
||||
return Array.Lower();
|
||||
}
|
||||
|
||||
//! Returns the value of the theUpper index of a vector.
|
||||
inline Standard_Integer Upper() const
|
||||
{
|
||||
return Array.Upper();
|
||||
}
|
||||
|
||||
//! Returns the value or the square of the norm of this vector.
|
||||
Standard_EXPORT Standard_Real Norm() const;
|
||||
|
||||
//! Returns the value of the square of the norm of a vector.
|
||||
Standard_EXPORT Standard_Real Norm2() const;
|
||||
|
||||
//! Returns the value of the "Index" of the maximum element of a vector.
|
||||
Standard_EXPORT Standard_Integer Max() const;
|
||||
|
||||
//! Returns the value of the "Index" of the minimum element of a vector.
|
||||
Standard_EXPORT Standard_Integer Min() const;
|
||||
|
||||
//! Normalizes this vector (the norm of the result
|
||||
//! is equal to 1.0) and assigns the result to this vector
|
||||
//! Exceptions
|
||||
//! Standard_NullValue if this vector is null (i.e. if its norm is
|
||||
//! less than or equal to Standard_Real::RealEpsilon().
|
||||
Standard_EXPORT void Normalize();
|
||||
|
||||
//! Normalizes this vector (the norm of the result
|
||||
//! is equal to 1.0) and creates a new vector
|
||||
//! Exceptions
|
||||
//! Standard_NullValue if this vector is null (i.e. if its norm is
|
||||
//! less than or equal to Standard_Real::RealEpsilon().
|
||||
Standard_NODISCARD Standard_EXPORT math_Vector Normalized() const;
|
||||
|
||||
//! Inverts this vector and assigns the result to this vector.
|
||||
Standard_EXPORT void Invert();
|
||||
|
||||
//! Inverts this vector and creates a new vector.
|
||||
Standard_EXPORT math_Vector Inverse() const;
|
||||
|
||||
//! sets a vector from "theI1" to "theI2" to the vector "theV";
|
||||
//! An exception is raised if "theI1" is less than "LowerIndex" or "theI2" is greater than "UpperIndex" or "theI1" is greater than "theI2".
|
||||
//! An exception is raised if "theI2-theI1+1" is different from the "Length" of "theV".
|
||||
Standard_EXPORT void Set(const Standard_Integer theI1, const Standard_Integer theI2, const math_Vector& theV);
|
||||
|
||||
//!Creates a new vector by inverting the values of this vector
|
||||
//! between indexes "theI1" and "theI2".
|
||||
//! If the values of this vector were (1., 2., 3., 4.,5., 6.),
|
||||
//! by slicing it between indexes 2 and 5 the values
|
||||
//! of the resulting vector are (1., 5., 4., 3., 2., 6.)
|
||||
Standard_EXPORT math_Vector Slice(const Standard_Integer theI1, const Standard_Integer theI2) const;
|
||||
|
||||
//! returns the product of a vector and a real value.
|
||||
Standard_EXPORT void Multiply(const Standard_Real theRight);
|
||||
|
||||
void operator *=(const Standard_Real theRight)
|
||||
{
|
||||
Multiply(theRight);
|
||||
}
|
||||
|
||||
//! returns the product of a vector and a real value.
|
||||
Standard_NODISCARD Standard_EXPORT math_Vector Multiplied(const Standard_Real theRight) const;
|
||||
|
||||
Standard_NODISCARD math_Vector operator*(const Standard_Real theRight) const
|
||||
{
|
||||
return Multiplied(theRight);
|
||||
}
|
||||
|
||||
//! returns the product of a vector and a real value.
|
||||
Standard_NODISCARD Standard_EXPORT math_Vector TMultiplied(const Standard_Real theRight) const;
|
||||
|
||||
friend inline math_Vector operator* (const Standard_Real theLeft, const math_Vector& theRight)
|
||||
{
|
||||
return theRight.Multiplied(theLeft);
|
||||
}
|
||||
|
||||
//! divides a vector by the value "theRight".
|
||||
//! An exception is raised if "theRight" = 0.
|
||||
Standard_EXPORT void Divide(const Standard_Real theRight);
|
||||
|
||||
void operator /=(const Standard_Real theRight)
|
||||
{
|
||||
Divide(theRight);
|
||||
}
|
||||
|
||||
//! divides a vector by the value "theRight".
|
||||
//! An exception is raised if "theRight" = 0.
|
||||
Standard_NODISCARD Standard_EXPORT math_Vector Divided(const Standard_Real theRight) const;
|
||||
|
||||
Standard_NODISCARD math_Vector operator/(const Standard_Real theRight) const
|
||||
{
|
||||
return Divided(theRight);
|
||||
}
|
||||
|
||||
//! adds the vector "theRight" to a vector.
|
||||
//! An exception is raised if the vectors have not the same length.
|
||||
//! Warning
|
||||
//! In order to avoid time-consuming copying of vectors, it
|
||||
//! is preferable to use operator += or the function Add whenever possible.
|
||||
Standard_EXPORT void Add(const math_Vector& theRight);
|
||||
|
||||
void operator +=(const math_Vector& theRight)
|
||||
{
|
||||
Add(theRight);
|
||||
}
|
||||
|
||||
//! adds the vector theRight to a vector.
|
||||
//! An exception is raised if the vectors have not the same length.
|
||||
//! An exception is raised if the lengths are not equal.
|
||||
Standard_NODISCARD Standard_EXPORT math_Vector Added(const math_Vector& theRight) const;
|
||||
|
||||
Standard_NODISCARD math_Vector operator+(const math_Vector& theRight) const
|
||||
{
|
||||
return Added(theRight);
|
||||
}
|
||||
|
||||
//! sets a vector to the product of the vector "theLeft"
|
||||
//! with the matrix "theRight".
|
||||
Standard_EXPORT void Multiply(const math_Vector& theLeft, const math_Matrix& theRight);
|
||||
|
||||
//!sets a vector to the product of the matrix "theLeft"
|
||||
//! with the vector "theRight".
|
||||
Standard_EXPORT void Multiply(const math_Matrix& theLeft, const math_Vector& theRight);
|
||||
|
||||
//! sets a vector to the product of the transpose
|
||||
//! of the matrix "theTLeft" by the vector "theRight".
|
||||
Standard_EXPORT void TMultiply(const math_Matrix& theTLeft, const math_Vector& theRight);
|
||||
|
||||
//! sets a vector to the product of the vector
|
||||
//! "theLeft" by the transpose of the matrix "theTRight".
|
||||
Standard_EXPORT void TMultiply(const math_Vector& theLeft, const math_Matrix& theTRight);
|
||||
|
||||
//! sets a vector to the sum of the vector "theLeft"
|
||||
//! and the vector "theRight".
|
||||
//! An exception is raised if the lengths are different.
|
||||
Standard_EXPORT void Add(const math_Vector& theLeft, const math_Vector& theRight);
|
||||
|
||||
//! sets a vector to the Subtraction of the
|
||||
//! vector theRight from the vector theLeft.
|
||||
//! An exception is raised if the vectors have not the same length.
|
||||
//! Warning
|
||||
//! In order to avoid time-consuming copying of vectors, it
|
||||
//! is preferable to use operator -= or the function
|
||||
//! 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
//! Initialises a vector by copying "theOther".
|
||||
//! An exception is raised if the Lengths are different.
|
||||
Standard_EXPORT math_Vector& Initialized(const math_Vector& theOther);
|
||||
|
||||
math_Vector& operator=(const math_Vector& theOther)
|
||||
{
|
||||
return Initialized(theOther);
|
||||
}
|
||||
|
||||
//! returns the inner product of 2 vectors.
|
||||
//! An exception is raised if the lengths are not equal.
|
||||
Standard_NODISCARD Standard_EXPORT Standard_Real Multiplied(const math_Vector& theRight) const;
|
||||
Standard_NODISCARD Standard_Real operator*(const math_Vector& theRight) const
|
||||
{
|
||||
return Multiplied(theRight);
|
||||
}
|
||||
|
||||
//! returns the product of a vector by a matrix.
|
||||
Standard_NODISCARD Standard_EXPORT math_Vector Multiplied(const math_Matrix& theRight) const;
|
||||
|
||||
Standard_NODISCARD math_Vector operator*(const math_Matrix& theRight) const
|
||||
{
|
||||
return Multiplied(theRight);
|
||||
}
|
||||
|
||||
//! returns the opposite of a vector.
|
||||
Standard_EXPORT math_Vector Opposite();
|
||||
|
||||
math_Vector operator-()
|
||||
{
|
||||
return Opposite();
|
||||
}
|
||||
|
||||
//! returns the subtraction of "theRight" from "me".
|
||||
//! An exception is raised if the vectors have not the same length.
|
||||
Standard_EXPORT void Subtract(const math_Vector& theRight);
|
||||
|
||||
void operator-=(const math_Vector& theRight)
|
||||
{
|
||||
Subtract(theRight);
|
||||
}
|
||||
|
||||
//! returns the subtraction of "theRight" from "me".
|
||||
//! An exception is raised if the vectors have not the same length.
|
||||
Standard_NODISCARD Standard_EXPORT math_Vector Subtracted(const math_Vector& theRight) const;
|
||||
|
||||
Standard_NODISCARD math_Vector operator-(const math_Vector& theRight) const
|
||||
{
|
||||
return Subtracted(theRight);
|
||||
}
|
||||
|
||||
//! returns the multiplication of a real by a vector.
|
||||
//! "me" = "theLeft" * "theRight"
|
||||
Standard_EXPORT void Multiply(const Standard_Real theLeft,const math_Vector& theRight);
|
||||
|
||||
//! Prints information on the current state of the object.
|
||||
//! Is used to redefine the operator <<.
|
||||
Standard_EXPORT void Dump(Standard_OStream& theO) const;
|
||||
|
||||
friend inline Standard_OStream& operator<<(Standard_OStream& theO, const math_Vector& theVec)
|
||||
{
|
||||
theVec.Dump(theO);
|
||||
return theO;
|
||||
}
|
||||
|
||||
friend class math_Matrix;
|
||||
|
||||
protected:
|
||||
|
||||
//! Is used internally to set the "theLower" value of the vector.
|
||||
void SetLower(const Standard_Integer theLower);
|
||||
|
||||
private:
|
||||
|
||||
NCollection_LocalArray<Standard_Real, 512> myLocArray;
|
||||
NCollection_Array1<Standard_Real> Array;
|
||||
|
||||
};
|
||||
using math_Vector = math_VectorBase<double>;
|
||||
|
||||
#endif
|
||||
|
352
src/math/math_VectorBase.hxx
Normal file
352
src/math/math_VectorBase.hxx
Normal file
@@ -0,0 +1,352 @@
|
||||
// Copyright (c) 1997-1999 Matra Datavision
|
||||
// Copyright (c) 1999-2023 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_VectorBase_HeaderFile
|
||||
#define _math_VectorBase_HeaderFile
|
||||
|
||||
#include <NCollection_Array1.hxx>
|
||||
#include <gp_XY.hxx>
|
||||
#include <gp_XYZ.hxx>
|
||||
|
||||
// resolve name collisions with X11 headers
|
||||
#ifdef Opposite
|
||||
#undef Opposite
|
||||
#endif
|
||||
|
||||
#include <math_Matrix.hxx>
|
||||
|
||||
#include <array>
|
||||
|
||||
//! This class implements the real vector abstract data type.
|
||||
//! Vectors can have an arbitrary range which must be defined at
|
||||
//! the declaration and cannot be changed after this declaration.
|
||||
//! @code
|
||||
//! math_VectorBase<TheItemType> V1(-3, 5); // a vector with range [-3..5]
|
||||
//! @endcode
|
||||
//!
|
||||
//! Vector are copied through assignment:
|
||||
//! @code
|
||||
//! math_VectorBase<TheItemType> V2( 1, 9);
|
||||
//! ....
|
||||
//! V2 = V1;
|
||||
//! V1(1) = 2.0; // the vector V2 will not be modified.
|
||||
//! @endcode
|
||||
//!
|
||||
//! The Exception RangeError is raised when trying to access outside
|
||||
//! the range of a vector :
|
||||
//! @code
|
||||
//! V1(11) = 0.0 // --> will raise RangeError;
|
||||
//! @endcode
|
||||
//!
|
||||
//! The Exception DimensionError is raised when the dimensions of two
|
||||
//! vectors are not compatible :
|
||||
//! @code
|
||||
//! math_VectorBase<TheItemType> V3(1, 2);
|
||||
//! V3 = V1; // --> will raise DimensionError;
|
||||
//! V1.Add(V3) // --> will raise DimensionError;
|
||||
//! @endcode
|
||||
template<typename TheItemType>
|
||||
class math_VectorBase
|
||||
{
|
||||
static const int THE_BUFFER_SIZE = 32;
|
||||
|
||||
public:
|
||||
//! Memory allocation
|
||||
DEFINE_STANDARD_ALLOC;
|
||||
DEFINE_NCOLLECTION_ALLOC;
|
||||
public:
|
||||
|
||||
//! Constructs a non-initialized vector in the range [theLower..theUpper]
|
||||
//! "theLower" and "theUpper" are the indexes of the lower and upper bounds of the constructed vector.
|
||||
inline math_VectorBase(const Standard_Integer theLower, const Standard_Integer theUpper);
|
||||
|
||||
//! Constructs a vector in the range [theLower..theUpper]
|
||||
//! whose values are all initialized with the value "theInitialValue"
|
||||
inline math_VectorBase(const Standard_Integer theLower, const Standard_Integer theUpper, const TheItemType theInitialValue);
|
||||
|
||||
//! Constructs a vector in the range [theLower..theUpper]
|
||||
//! whose values are all initialized with the value "theInitialValue"
|
||||
inline math_VectorBase(const TheItemType* theTab, const Standard_Integer theLower, const Standard_Integer theUpper);
|
||||
|
||||
//! Constructor for converting gp_XY to math_VectorBase
|
||||
inline math_VectorBase(const gp_XY& Other);
|
||||
|
||||
//! Constructor for converting gp_XYZ to math_VectorBase
|
||||
inline math_VectorBase(const gp_XYZ& Other);
|
||||
|
||||
//! Initialize all the elements of a vector with "theInitialValue".
|
||||
void Init(const TheItemType theInitialValue);
|
||||
|
||||
//! Constructs a copy for initialization.
|
||||
//! An exception is raised if the lengths of the vectors are different.
|
||||
inline math_VectorBase(const math_VectorBase& theOther);
|
||||
|
||||
//! Returns the length of a vector
|
||||
inline Standard_Integer Length() const
|
||||
{
|
||||
return Array.Length();
|
||||
}
|
||||
|
||||
//! Returns the lower index of the vector
|
||||
inline Standard_Integer Lower() const
|
||||
{
|
||||
return Array.Lower();
|
||||
}
|
||||
|
||||
//! Returns the upper index of the vector
|
||||
inline Standard_Integer Upper() const
|
||||
{
|
||||
return Array.Upper();
|
||||
}
|
||||
|
||||
//! Returns the value or the square of the norm of this vector.
|
||||
inline Standard_Real Norm() const;
|
||||
|
||||
//! Returns the value of the square of the norm of a vector.
|
||||
inline Standard_Real Norm2() const;
|
||||
|
||||
//! Returns the index of the maximum element of a vector. (first found)
|
||||
inline Standard_Integer Max() const;
|
||||
|
||||
//! Returns the index of the minimum element of a vector. (first found)
|
||||
inline Standard_Integer Min() const;
|
||||
|
||||
//! Normalizes this vector (the norm of the result
|
||||
//! is equal to 1.0) and assigns the result to this vector
|
||||
//! Exceptions
|
||||
//! Standard_NullValue if this vector is null (i.e. if its norm is
|
||||
//! less than or equal to Standard_Real::RealEpsilon().
|
||||
inline void Normalize();
|
||||
|
||||
//! Normalizes this vector (the norm of the result
|
||||
//! is equal to 1.0) and creates a new vector
|
||||
//! Exceptions
|
||||
//! Standard_NullValue if this vector is null (i.e. if its norm is
|
||||
//! less than or equal to Standard_Real::RealEpsilon().
|
||||
Standard_NODISCARD inline math_VectorBase Normalized() const;
|
||||
|
||||
//! Inverts this vector and assigns the result to this vector.
|
||||
inline void Invert();
|
||||
|
||||
//! Inverts this vector and creates a new vector.
|
||||
inline math_VectorBase Inverse() const;
|
||||
|
||||
//! sets a vector from "theI1" to "theI2" to the vector "theV";
|
||||
//! An exception is raised if "theI1" is less than "LowerIndex" or "theI2" is greater than "UpperIndex" or "theI1" is greater than "theI2".
|
||||
//! An exception is raised if "theI2-theI1+1" is different from the "Length" of "theV".
|
||||
inline void Set(const Standard_Integer theI1, const Standard_Integer theI2, const math_VectorBase& theV);
|
||||
|
||||
//!Creates a new vector by inverting the values of this vector
|
||||
//! between indexes "theI1" and "theI2".
|
||||
//! If the values of this vector were (1., 2., 3., 4.,5., 6.),
|
||||
//! by slicing it between indexes 2 and 5 the values
|
||||
//! of the resulting vector are (1., 5., 4., 3., 2., 6.)
|
||||
inline math_VectorBase Slice(const Standard_Integer theI1, const Standard_Integer theI2) const;
|
||||
|
||||
//! Updates current vector by multiplying each element on current value.
|
||||
inline void Multiply(const TheItemType theRight);
|
||||
|
||||
void operator *=(const TheItemType theRight)
|
||||
{
|
||||
Multiply(theRight);
|
||||
}
|
||||
|
||||
//! returns the product of a vector and a real value.
|
||||
Standard_NODISCARD inline math_VectorBase Multiplied(const TheItemType theRight) const;
|
||||
|
||||
Standard_NODISCARD math_VectorBase operator*(const TheItemType theRight) const
|
||||
{
|
||||
return Multiplied(theRight);
|
||||
}
|
||||
|
||||
//! returns the product of a vector and a real value.
|
||||
Standard_NODISCARD inline math_VectorBase TMultiplied(const TheItemType theRight) const;
|
||||
|
||||
friend inline math_VectorBase operator* (const TheItemType theLeft, const math_VectorBase& theRight)
|
||||
{
|
||||
return theRight.Multiplied(theLeft);
|
||||
}
|
||||
|
||||
//! divides a vector by the value "theRight".
|
||||
//! An exception is raised if "theRight" = 0.
|
||||
inline void Divide(const TheItemType theRight);
|
||||
|
||||
void operator /=(const TheItemType theRight)
|
||||
{
|
||||
Divide(theRight);
|
||||
}
|
||||
|
||||
//! Returns new vector as dividing current vector with the value "theRight".
|
||||
//! An exception is raised if "theRight" = 0.
|
||||
Standard_NODISCARD inline math_VectorBase Divided(const TheItemType theRight) const;
|
||||
|
||||
Standard_NODISCARD math_VectorBase operator/(const TheItemType theRight) const
|
||||
{
|
||||
return Divided(theRight);
|
||||
}
|
||||
|
||||
//! adds the vector "theRight" to a vector.
|
||||
//! An exception is raised if the vectors have not the same length.
|
||||
//! Warning
|
||||
//! In order to avoid time-consuming copying of vectors, it
|
||||
//! is preferable to use operator += or the function Add whenever possible.
|
||||
inline void Add(const math_VectorBase& theRight);
|
||||
|
||||
void operator +=(const math_VectorBase& theRight)
|
||||
{
|
||||
Add(theRight);
|
||||
}
|
||||
|
||||
//! Returns new vector as adding curent vector with the value "theRight".
|
||||
//! An exception is raised if the vectors have not the same length.
|
||||
//! An exception is raised if the lengths are not equal.
|
||||
Standard_NODISCARD inline math_VectorBase Added(const math_VectorBase& theRight) const;
|
||||
|
||||
Standard_NODISCARD math_VectorBase operator+(const math_VectorBase& theRight) const
|
||||
{
|
||||
return Added(theRight);
|
||||
}
|
||||
|
||||
//! sets a vector to the product of the vector "theLeft"
|
||||
//! with the matrix "theRight".
|
||||
inline void Multiply(const math_VectorBase& theLeft, const math_Matrix& theRight);
|
||||
|
||||
//!sets a vector to the product of the matrix "theLeft"
|
||||
//! with the vector "theRight".
|
||||
inline void Multiply(const math_Matrix& theLeft, const math_VectorBase& theRight);
|
||||
|
||||
//! sets a vector to the product of the transpose
|
||||
//! of the matrix "theTLeft" by the vector "theRight".
|
||||
inline void TMultiply(const math_Matrix& theTLeft, const math_VectorBase& theRight);
|
||||
|
||||
//! sets a vector to the product of the vector
|
||||
//! "theLeft" by the transpose of the matrix "theTRight".
|
||||
inline void TMultiply(const math_VectorBase& theLeft, const math_Matrix& theTRight);
|
||||
|
||||
//! sets a vector to the sum of the vector "theLeft"
|
||||
//! and the vector "theRight".
|
||||
//! An exception is raised if the lengths are different.
|
||||
inline void Add(const math_VectorBase& theLeft, const math_VectorBase& theRight);
|
||||
|
||||
//! sets a vector to the Subtraction of the
|
||||
//! vector theRight from the vector theLeft.
|
||||
//! An exception is raised if the vectors have not the same length.
|
||||
//! Warning
|
||||
//! In order to avoid time-consuming copying of vectors, it
|
||||
//! is preferable to use operator -= or the function
|
||||
//! Subtract whenever possible.
|
||||
inline void Subtract(const math_VectorBase& theLeft, const math_VectorBase& theRight);
|
||||
|
||||
//! accesses the value of index "theNum" of a vector.
|
||||
const TheItemType& Value(const Standard_Integer theNum) const
|
||||
{
|
||||
return Array(theNum);
|
||||
}
|
||||
|
||||
//! accesses (in read or write mode) the value of index "theNum" of a vector.
|
||||
inline TheItemType& Value(const Standard_Integer theNum)
|
||||
{
|
||||
return Array(theNum);
|
||||
}
|
||||
|
||||
const TheItemType& operator()(const Standard_Integer theNum) const
|
||||
{
|
||||
return Value(theNum);
|
||||
}
|
||||
|
||||
TheItemType& operator()(const Standard_Integer theNum)
|
||||
{
|
||||
return Value(theNum);
|
||||
}
|
||||
|
||||
//! Initialises a vector by copying "theOther".
|
||||
//! An exception is raised if the Lengths are different.
|
||||
inline math_VectorBase& Initialized(const math_VectorBase& theOther);
|
||||
|
||||
math_VectorBase& operator=(const math_VectorBase& theOther)
|
||||
{
|
||||
return Initialized(theOther);
|
||||
}
|
||||
|
||||
//! returns the inner product of 2 vectors.
|
||||
//! An exception is raised if the lengths are not equal.
|
||||
Standard_NODISCARD inline TheItemType Multiplied(const math_VectorBase& theRight) const;
|
||||
Standard_NODISCARD inline TheItemType operator*(const math_VectorBase& theRight) const
|
||||
{
|
||||
return Multiplied(theRight);
|
||||
}
|
||||
|
||||
//! returns the product of a vector by a matrix.
|
||||
Standard_NODISCARD inline math_VectorBase Multiplied(const math_Matrix& theRight) const;
|
||||
|
||||
Standard_NODISCARD math_VectorBase operator*(const math_Matrix& theRight) const
|
||||
{
|
||||
return Multiplied(theRight);
|
||||
}
|
||||
|
||||
//! returns the opposite of a vector.
|
||||
inline math_VectorBase Opposite();
|
||||
|
||||
math_VectorBase operator-()
|
||||
{
|
||||
return Opposite();
|
||||
}
|
||||
|
||||
//! returns the subtraction of "theRight" from "me".
|
||||
//! An exception is raised if the vectors have not the same length.
|
||||
inline void Subtract(const math_VectorBase& theRight);
|
||||
|
||||
void operator-=(const math_VectorBase& theRight)
|
||||
{
|
||||
Subtract(theRight);
|
||||
}
|
||||
|
||||
//! returns the subtraction of "theRight" from "me".
|
||||
//! An exception is raised if the vectors have not the same length.
|
||||
Standard_NODISCARD inline math_VectorBase Subtracted(const math_VectorBase& theRight) const;
|
||||
|
||||
Standard_NODISCARD math_VectorBase operator-(const math_VectorBase& theRight) const
|
||||
{
|
||||
return Subtracted(theRight);
|
||||
}
|
||||
|
||||
//! returns the multiplication of a real by a vector.
|
||||
//! "me" = "theLeft" * "theRight"
|
||||
inline void Multiply(const TheItemType theLeft, const math_VectorBase& theRight);
|
||||
|
||||
//! Prints information on the current state of the object.
|
||||
//! Is used to redefine the operator <<.
|
||||
inline void Dump(Standard_OStream& theO) const;
|
||||
|
||||
friend inline Standard_OStream& operator<<(Standard_OStream& theO, const math_VectorBase& theVec)
|
||||
{
|
||||
theVec.Dump(theO);
|
||||
return theO;
|
||||
}
|
||||
|
||||
friend class math_Matrix;
|
||||
|
||||
protected:
|
||||
|
||||
//! Is used internally to set the "theLower" value of the vector.
|
||||
inline void SetLower(const Standard_Integer theLower);
|
||||
|
||||
private:
|
||||
std::array<TheItemType, THE_BUFFER_SIZE> myBuffer;
|
||||
NCollection_Array1<TheItemType> Array;
|
||||
};
|
||||
|
||||
#include <math_VectorBase.lxx>
|
||||
|
||||
#endif
|
524
src/math/math_VectorBase.lxx
Normal file
524
src/math/math_VectorBase.lxx
Normal file
@@ -0,0 +1,524 @@
|
||||
// Copyright (c) 1997-1999 Matra Datavision
|
||||
// Copyright (c) 1999-2023 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.
|
||||
|
||||
#include <Standard_DimensionError.hxx>
|
||||
#include <Standard_DivideByZero.hxx>
|
||||
#include <Standard_RangeError.hxx>
|
||||
#include <Standard_NullValue.hxx>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType>::math_VectorBase(const Standard_Integer theLower,
|
||||
const Standard_Integer theUpper) :
|
||||
Array(*myBuffer.data(), theLower, theUpper, (theUpper - theLower + 1 <= math_VectorBase::THE_BUFFER_SIZE))
|
||||
{}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType>::math_VectorBase(const Standard_Integer theLower,
|
||||
const Standard_Integer theUpper,
|
||||
const TheItemType theInitialValue) :
|
||||
Array(*myBuffer.data(), theLower, theUpper, (theUpper - theLower + 1 <= math_VectorBase::THE_BUFFER_SIZE))
|
||||
{
|
||||
Array.Init(theInitialValue);
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType>::math_VectorBase(const TheItemType* theTab,
|
||||
const Standard_Integer theLower,
|
||||
const Standard_Integer theUpper) :
|
||||
Array(*theTab, theLower, theUpper)
|
||||
{}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType>::math_VectorBase(const gp_XY& theOther) :
|
||||
Array(*myBuffer.data(), 1, 2)
|
||||
{
|
||||
Array(1) = static_cast<TheItemType>(theOther.X());
|
||||
Array(2) = static_cast<TheItemType>(theOther.Y());
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType>::math_VectorBase(const gp_XYZ& theOther) :
|
||||
Array(*myBuffer.data(), 1, 3)
|
||||
{
|
||||
Array(1) = static_cast<TheItemType>(theOther.X());
|
||||
Array(2) = static_cast<TheItemType>(theOther.Y());
|
||||
Array(3) = static_cast<TheItemType>(theOther.Z());
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Init(const TheItemType theInitialValue)
|
||||
{
|
||||
Array.Init(theInitialValue);
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType>::math_VectorBase(const math_VectorBase<TheItemType>& theOther) :
|
||||
Array(theOther.Array)
|
||||
{}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::SetLower(const Standard_Integer theLower)
|
||||
{
|
||||
Array.UpdateLowerBound(theLower);
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
Standard_Real math_VectorBase<TheItemType>::Norm() const
|
||||
{
|
||||
Standard_Real Result = 0;
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result = Result + Array(Index) * Array(Index);
|
||||
}
|
||||
return Sqrt(Result);
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
Standard_Real math_VectorBase<TheItemType>::Norm2() const
|
||||
{
|
||||
Standard_Real Result = 0;
|
||||
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result = Result + Array(Index) * Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
Standard_Integer math_VectorBase<TheItemType>::Max() const
|
||||
{
|
||||
Standard_Integer I = 0;
|
||||
Standard_Real X = RealFirst();
|
||||
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
if (Array(Index) > X)
|
||||
{
|
||||
X = Array(Index);
|
||||
I = Index;
|
||||
}
|
||||
}
|
||||
return I;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
Standard_Integer math_VectorBase<TheItemType>::Min() const
|
||||
{
|
||||
Standard_Integer I = 0;
|
||||
Standard_Real X = RealLast();
|
||||
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
if (Array(Index) < X)
|
||||
{
|
||||
X = Array(Index);
|
||||
I = Index;
|
||||
}
|
||||
}
|
||||
return I;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Set(const Standard_Integer theI1,
|
||||
const Standard_Integer theI2,
|
||||
const math_VectorBase<TheItemType>& theV)
|
||||
{
|
||||
Standard_RangeError_Raise_if((theI1 < Lower()) || (theI2 > Upper()) \
|
||||
|| (theI1 > theI2) || (theI2 - theI1 + 1 != theV.Length()), \
|
||||
"math_VectorBase::Set() - invalid indices");
|
||||
Standard_Integer I = theV.Lower();
|
||||
for (Standard_Integer Index = theI1; Index <= theI2; Index++)
|
||||
{
|
||||
Array(Index) = theV.Array(I);
|
||||
I++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Normalize()
|
||||
{
|
||||
Standard_Real Result = Norm();
|
||||
Standard_NullValue_Raise_if((Result <= RealEpsilon()), \
|
||||
"math_VectorBase::Normalize() - vector has zero norm");
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Array(Index) = Array(Index) / Result;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Normalized() const
|
||||
{
|
||||
math_VectorBase Result = *this;
|
||||
Result.Normalize();
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Invert()
|
||||
{
|
||||
for (Standard_Integer Index = Lower(); Index <= (Lower() + Length()) >> 1; Index++)
|
||||
{
|
||||
Standard_Integer J = Upper() + Lower() - Index;
|
||||
TheItemType aTemp = Array(Index);
|
||||
Array(Index) = Array(J);
|
||||
Array(J) = aTemp;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Inverse() const
|
||||
{
|
||||
math_VectorBase Result = *this;
|
||||
Result.Invert();
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Multiplied(const TheItemType theRight) const
|
||||
{
|
||||
math_VectorBase Result(Lower(), Upper());
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) * theRight;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType> math_VectorBase<TheItemType>::TMultiplied(const TheItemType theRight) const
|
||||
{
|
||||
math_VectorBase Result(Lower(), Upper());
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) * theRight;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Multiply(const TheItemType theRight)
|
||||
{
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Array(Index) = Array(Index) * theRight;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Divide(const TheItemType theRight)
|
||||
{
|
||||
Standard_DivideByZero_Raise_if(Abs(theRight) <= RealEpsilon(), \
|
||||
"math_VectorBase::Divide() - devisor is zero");
|
||||
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Array(Index) = Array(Index) / theRight;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Divided(const TheItemType theRight) const
|
||||
{
|
||||
Standard_DivideByZero_Raise_if(Abs(theRight) <= RealEpsilon(), \
|
||||
"math_VectorBase::Divided() - devisor is zero");
|
||||
math_VectorBase temp = Multiplied(1. / theRight);
|
||||
return temp;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Add(const math_VectorBase<TheItemType>& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if(Length() != theRight.Length(), \
|
||||
"math_VectorBase::Add() - input vector has wrong dimensions");
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Array(Index) = Array(Index) + theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Added(const math_VectorBase<TheItemType>& theRight) const
|
||||
{
|
||||
Standard_DimensionError_Raise_if(Length() != theRight.Length(), \
|
||||
"math_VectorBase::Added() - input vector has wrong dimensions");
|
||||
|
||||
math_VectorBase Result(Lower(), Upper());
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) + theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Subtract(const math_VectorBase<TheItemType>& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if(Length() != theRight.Length(), \
|
||||
"math_VectorBase::Subtract() - input vector has wrong dimensions");
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Array(Index) = Array(Index) - theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Subtracted(const math_VectorBase<TheItemType>& theRight) const
|
||||
{
|
||||
Standard_DimensionError_Raise_if(Length() != theRight.Length(), \
|
||||
"math_VectorBase::Subtracted() - input vector has wrong dimensions");
|
||||
|
||||
math_VectorBase Result(Lower(), Upper());
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index) - theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Slice(const Standard_Integer theI1, const Standard_Integer theI2) const
|
||||
{
|
||||
Standard_RangeError_Raise_if((theI1 < Lower()) || (theI1 > Upper()) || (theI2 < Lower()) || (theI2 > Upper()), \
|
||||
"math_VectorBase::Slice() - invalid indices");
|
||||
|
||||
if (theI2 >= theI1)
|
||||
{
|
||||
math_VectorBase Result(theI1, theI2);
|
||||
for (Standard_Integer Index = theI1; Index <= theI2; Index++)
|
||||
{
|
||||
Result.Array(Index) = Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
math_VectorBase Result(theI2, theI1);
|
||||
for (Standard_Integer Index = theI1; Index >= theI2; Index--)
|
||||
{
|
||||
Result.Array(Index) = Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Add(const math_VectorBase<TheItemType>& theLeft, const math_VectorBase<TheItemType>& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if((Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()), \
|
||||
"math_VectorBase::Add() - input vectors have wrong dimensions");
|
||||
|
||||
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++;
|
||||
J++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Subtract(const math_VectorBase<TheItemType>& theLeft, const math_VectorBase<TheItemType>& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if((Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()), \
|
||||
"math_VectorBase::Subtract() - input vectors have wrong dimensions");
|
||||
|
||||
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++;
|
||||
J++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Multiply(const math_Matrix& theLeft, const math_VectorBase<TheItemType>& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if((Length() != theLeft.RowNumber()) \
|
||||
|| (theLeft.ColNumber() != theRight.Length()), \
|
||||
"math_VectorBase::Multiply() - input matrix and /or vector have wrong dimensions");
|
||||
|
||||
Standard_Integer Index = Lower();
|
||||
for (Standard_Integer I = theLeft.LowerRowIndex; I <= theLeft.UpperRowIndex; I++)
|
||||
{
|
||||
Array(Index) = 0.0;
|
||||
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);
|
||||
K++;
|
||||
}
|
||||
Index++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Multiply(const math_VectorBase<TheItemType>& theLeft, const math_Matrix& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if((Length() != theRight.ColNumber()) \
|
||||
|| (theLeft.Length() != theRight.RowNumber()), \
|
||||
"math_VectorBase::Multiply() - input matrix and /or vector have wrong dimensions");
|
||||
|
||||
Standard_Integer Index = Lower();
|
||||
for (Standard_Integer J = theRight.LowerColIndex; J <= theRight.UpperColIndex; J++)
|
||||
{
|
||||
Array(Index) = 0.0;
|
||||
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);
|
||||
K++;
|
||||
}
|
||||
Index++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::TMultiply(const math_Matrix& theTLeft, const math_VectorBase<TheItemType>& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if((Length() != theTLeft.ColNumber()) \
|
||||
|| (theTLeft.RowNumber() != theRight.Length()), \
|
||||
"math_VectorBase::TMultiply() - input matrix and /or vector have wrong dimensions");
|
||||
|
||||
Standard_Integer Index = Lower();
|
||||
for (Standard_Integer I = theTLeft.LowerColIndex; I <= theTLeft.UpperColIndex; I++)
|
||||
{
|
||||
Array(Index) = 0.0;
|
||||
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);
|
||||
K++;
|
||||
}
|
||||
Index++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::TMultiply(const math_VectorBase<TheItemType>& theLeft, const math_Matrix& theTRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if((Length() != theTRight.RowNumber()) \
|
||||
|| (theLeft.Length() != theTRight.ColNumber()), \
|
||||
"math_VectorBase::TMultiply() - input matrix and /or vector have wrong dimensions");
|
||||
|
||||
Standard_Integer Index = Lower();
|
||||
for (Standard_Integer J = theTRight.LowerRowIndex; J <= theTRight.UpperRowIndex; J++)
|
||||
{
|
||||
Array(Index) = 0.0;
|
||||
Standard_Integer K = theLeft.Lower();
|
||||
for (Standard_Integer I = theTRight.LowerColIndex;
|
||||
I <= theTRight.UpperColIndex; I++)
|
||||
{
|
||||
Array(Index) = Array(Index) + theLeft.Array(K) * theTRight.Array(J, I);
|
||||
K++;
|
||||
}
|
||||
Index++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
TheItemType math_VectorBase<TheItemType>::Multiplied(const math_VectorBase<TheItemType>& theRight) const
|
||||
{
|
||||
Standard_Real Result = 0;
|
||||
|
||||
Standard_DimensionError_Raise_if(Length() != theRight.Length(), \
|
||||
"math_VectorBase::Multiplied() - input vector has wrong dimensions");
|
||||
|
||||
Standard_Integer I = theRight.Lower();
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result = Result + Array(Index) * theRight.Array(I);
|
||||
I++;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Opposite()
|
||||
{
|
||||
math_VectorBase Result(Lower(), Upper());
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
Result.Array(Index) = -Array(Index);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType> math_VectorBase<TheItemType>::Multiplied(const math_Matrix& theRight)const
|
||||
{
|
||||
Standard_DimensionError_Raise_if(Length() != theRight.RowNumber(), \
|
||||
"math_VectorBase::Multiplied() - input matrix has wrong dimensions");
|
||||
|
||||
math_VectorBase Result(theRight.LowerColIndex, theRight.UpperColIndex);
|
||||
for (Standard_Integer J2 = theRight.LowerColIndex; J2 <= theRight.UpperColIndex; J2++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Multiply(const TheItemType theLeft, const math_VectorBase<TheItemType>& theRight)
|
||||
{
|
||||
Standard_DimensionError_Raise_if((Length() != theRight.Length()), \
|
||||
"math_VectorBase::Multiply() - input vector has wrong dimensions");
|
||||
for (Standard_Integer I = Lower(); I <= Upper(); I++)
|
||||
{
|
||||
Array(I) = theLeft * theRight.Array(I);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
math_VectorBase<TheItemType>& math_VectorBase<TheItemType>::Initialized(const math_VectorBase<TheItemType>& theOther)
|
||||
{
|
||||
Standard_DimensionError_Raise_if(Length() != theOther.Length(), \
|
||||
"math_VectorBase::Initialized() - input vector has wrong dimensions");
|
||||
memmove(&Array.ChangeFirst(), &theOther.Array.First(), sizeof(TheItemType) * Array.Length());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename TheItemType>
|
||||
void math_VectorBase<TheItemType>::Dump(Standard_OStream& theO) const
|
||||
{
|
||||
theO << "math_Vector of Length = " << Length() << "\n";
|
||||
for (Standard_Integer Index = Lower(); Index <= Upper(); Index++)
|
||||
{
|
||||
theO << "math_Vector(" << Index << ") = " << Array(Index) << "\n";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user