- class "math_DoubleTab" was converted to the non-generic class. Some changes were made in the class "math_Matrix". And some stylish changes were made.
- class "math_SingleTab" was converted to the non-generic template class. And classes "math_Vector" and "math_IntegerVector" converted to the non-cdl, because they use template class "math_Vector". Some stylish changes were made.
math_Recipes.hxx
math_GaussPoints.hxx
math_Kronrod.cxx
+math_Vector.hxx
+math_Vector.cxx
+math_IntegerVector.hxx
+math_IntegerVector.cxx
+math_SingleTab.hxx
\ No newline at end of file
exception SingularMatrix inherits Failure;
- class Vector;
- class IntegerVector;
+ imported Vector;
+ imported IntegerVector;
class Matrix;
deferred class Function;
deferred class FunctionWithDerivative;
Array1OfValueAndWeight from math,
CompareOfValueAndWeight from math);
- generic class SingleTab;
- generic class DoubleTab;
-
- --- Instantiate classes:
- class SingleTabOfReal instantiates SingleTab(Real);
- class SingleTabOfInteger instantiates SingleTab(Integer);
- class DoubleTabOfReal instantiates DoubleTab(Real);
+ class DoubleTab;
--- Gauss Points
-- Alternatively, this file may be used under the terms of Open CASCADE
-- commercial license or contractual agreement.
-generic class DoubleTab from math (Item as any)
+class DoubleTab from math
uses Address from Standard
is
Create(LowerRow, UpperRow, LowerCol, UpperCol: Integer)
returns DoubleTab;
- Create(Tab : Item; LowerRow, UpperRow, LowerCol, UpperCol: Integer)
+ Create(Tab : Address; LowerRow, UpperRow, LowerCol, UpperCol: Integer)
returns DoubleTab;
- Init(me : in out; InitValue: Item) is static;
+ Init(me : in out; InitValue: Real) is static;
Create(Other: DoubleTab)
returns DoubleTab;
---C++: alias operator()
---C++: return &
---C++: inline
- returns Item
+ returns Real
is static;
Addr : Address;
AddrBuf : Address[32];
-Buf : Item[512];
+Buf : Real[512];
isAddrAllocated: Boolean;
isAllocated : Boolean;
LowR : Integer;
--- /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 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.
+
+// Lpa, le 7/02/92
+#include <math_DoubleTab.ixx>
+
+#include <math_Memory.hxx>
+#include <Standard_OutOfRange.hxx>
+#include <Standard_Failure.hxx>
+#include <Standard_Integer.hxx>
+
+// macro to get size of C array
+#define CARRAY_LENGTH(arr) (int)(sizeof(arr)/sizeof(arr[0]))
+
+void math_DoubleTab::Allocate()
+{
+ Standard_Integer RowNumber = UppR - LowR + 1;
+ Standard_Integer ColNumber = UppC - LowC + 1;
+
+ Standard_Real** TheAddr = !isAddrAllocated? (Standard_Real**)&AddrBuf :
+ (Standard_Real**) Standard::Allocate(RowNumber * sizeof(Standard_Real*));
+ Standard_Real* Address;
+ if(isAllocated)
+ Address = (Standard_Real*) Standard::Allocate(RowNumber * ColNumber * sizeof(Standard_Real));
+ else
+ Address = (Standard_Real*) Addr;
+ Address -= LowC;
+
+ for (Standard_Integer Index = 0; Index < RowNumber; Index++) {
+ TheAddr[Index] = Address;
+ Address += ColNumber;
+ }
+
+ TheAddr -= LowR;
+ Addr = (Standard_Address) TheAddr;
+}
+
+math_DoubleTab::math_DoubleTab(const Standard_Integer LowerRow,
+ const Standard_Integer UpperRow,
+ const Standard_Integer LowerCol,
+ const Standard_Integer UpperCol) :
+ Addr(Buf),
+ isAddrAllocated(UpperRow - LowerRow + 1 > CARRAY_LENGTH(AddrBuf)),
+ isAllocated((UpperRow - LowerRow + 1) * (UpperCol - LowerCol + 1) > CARRAY_LENGTH(Buf)),
+ LowR(LowerRow),
+ UppR(UpperRow),
+ LowC(LowerCol),
+ UppC(UpperCol)
+{
+ Allocate();
+}
+
+math_DoubleTab::math_DoubleTab(const Standard_Address Tab,
+ const Standard_Integer LowerRow,
+ const Standard_Integer UpperRow,
+ const Standard_Integer LowerCol,
+ const Standard_Integer UpperCol) :
+ Addr(Tab),
+ isAddrAllocated(UpperRow - LowerRow + 1 > CARRAY_LENGTH(AddrBuf)),
+ isAllocated(Standard_False),
+ LowR(LowerRow),
+ UppR(UpperRow),
+ LowC(LowerCol),
+ UppC(UpperCol)
+{
+ Allocate();
+}
+
+void math_DoubleTab::Init(const Standard_Real InitValue)
+{
+ for (Standard_Integer i = LowR; i <= UppR; i++) {
+ for (Standard_Integer j = LowC; j <= UppC; j++) {
+ ((Standard_Real**) Addr)[i][j] = InitValue;
+ }
+ }
+}
+
+math_DoubleTab::math_DoubleTab(const math_DoubleTab& Other) :
+ Addr(Buf),
+ isAddrAllocated(Other.UppR - Other.LowR + 1 > CARRAY_LENGTH(AddrBuf)),
+ isAllocated((Other.UppR - Other.LowR + 1) *
+ (Other.UppC - Other.LowC + 1) > CARRAY_LENGTH(Buf)),
+ LowR(Other.LowR),
+ UppR(Other.UppR),
+ LowC(Other.LowC),
+ UppC(Other.UppC)
+{
+ Allocate();
+
+ Standard_Address target = (Standard_Address) &Value(LowR,LowC);
+ Standard_Address source = (Standard_Address) &Other.Value(LowR,LowC);
+
+ memmove(target,source,
+ (int)((UppR - LowR + 1) * (UppC - LowC + 1) * sizeof(Standard_Real)));
+
+}
+
+void math_DoubleTab::Free()
+{
+ // free the data
+ if(isAllocated) {
+ Standard_Address it = (Standard_Address)&Value(LowR,LowC);
+ Standard::Free(it);
+ }
+ // free the pointers
+ if(isAddrAllocated) {
+ Standard_Address it = (Standard_Address)(((Standard_Real**)Addr) + LowR);
+ Standard::Free (it);
+ }
+ Addr = 0;
+}
+
+void math_DoubleTab::SetLowerRow(const Standard_Integer LowerRow)
+{
+ Standard_Real** TheAddr = (Standard_Real**)Addr;
+ Addr = (Standard_Address) (TheAddr + LowR - LowerRow);
+ UppR = UppR - LowR + LowerRow;
+ LowR = LowerRow;
+}
+
+void math_DoubleTab::SetLowerCol(const Standard_Integer LowerCol)
+{
+ Standard_Real** TheAddr = (Standard_Real**) Addr;
+ for (Standard_Integer Index = LowR; Index <= UppR; Index++) {
+ TheAddr[Index] = TheAddr[Index] + LowC - LowerCol;
+ }
+
+ UppC = UppC - LowC + LowerCol;
+ LowC = LowerCol;
+}
+
+++ /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 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.
-
-// Lpa, le 7/02/92
-
-
-#include <math_Memory.hxx>
-#include <Standard_OutOfRange.hxx>
-#include <Standard_Failure.hxx>
-#include <Standard_Integer.hxx>
-
-// macro to get size of C array
-#define CARRAY_LENGTH(arr) (int)(sizeof(arr)/sizeof(arr[0]))
-
-void math_DoubleTab::Allocate()
-{
- Standard_Integer RowNumber = UppR - LowR + 1;
- Standard_Integer ColNumber = UppC - LowC + 1;
-
- Item** TheAddr = !isAddrAllocated? (Item**)&AddrBuf :
- (Item**) Standard::Allocate(RowNumber * sizeof(Item*));
- Item* Address;
- if(isAllocated)
- Address = (Item*) Standard::Allocate(RowNumber * ColNumber * sizeof(Item));
- else
- Address = (Item*) Addr;
- Address -= LowC;
-
- for (Standard_Integer Index = 0; Index < RowNumber; Index++) {
- TheAddr[Index] = Address;
- Address += ColNumber;
- }
-
- TheAddr -= LowR;
- Addr = (Standard_Address) TheAddr;
-}
-
-math_DoubleTab::math_DoubleTab(const Standard_Integer LowerRow,
- const Standard_Integer UpperRow,
- const Standard_Integer LowerCol,
- const Standard_Integer UpperCol) :
- Addr(Buf),
- isAddrAllocated(UpperRow - LowerRow + 1 > CARRAY_LENGTH(AddrBuf)),
- isAllocated((UpperRow - LowerRow + 1) * (UpperCol - LowerCol + 1) > CARRAY_LENGTH(Buf)),
- LowR(LowerRow),
- UppR(UpperRow),
- LowC(LowerCol),
- UppC(UpperCol)
-{
- Allocate();
-}
-
-
-math_DoubleTab::math_DoubleTab(const Item& Tab,
- const Standard_Integer LowerRow,
- const Standard_Integer UpperRow,
- const Standard_Integer LowerCol,
- const Standard_Integer UpperCol) :
- Addr((void *) &Tab),
- isAddrAllocated(UpperRow - LowerRow + 1 > CARRAY_LENGTH(AddrBuf)),
- isAllocated(Standard_False),
- LowR(LowerRow),
- UppR(UpperRow),
- LowC(LowerCol),
- UppC(UpperCol)
-{
- Allocate();
-}
-
-void math_DoubleTab::Init(const Item& InitValue)
-{
- for (Standard_Integer i = LowR; i <= UppR; i++) {
- for (Standard_Integer j = LowC; j <= UppC; j++) {
- ((Item**) Addr)[i][j] = InitValue;
- }
- }
-}
-
-
-
-math_DoubleTab::math_DoubleTab(const math_DoubleTab& Other) :
- Addr(Buf),
- isAddrAllocated(Other.UppR - Other.LowR + 1 > CARRAY_LENGTH(AddrBuf)),
- isAllocated((Other.UppR - Other.LowR + 1) *
- (Other.UppC - Other.LowC + 1) > CARRAY_LENGTH(Buf)),
- LowR(Other.LowR),
- UppR(Other.UppR),
- LowC(Other.LowC),
- UppC(Other.UppC)
-{
- Allocate();
-
- Standard_Address target = (Standard_Address) &Value(LowR,LowC);
- Standard_Address source = (Standard_Address) &Other.Value(LowR,LowC);
-
- memmove(target,source,
- (int)((UppR - LowR + 1) * (UppC - LowC + 1) * sizeof(Item)));
-
-}
-
-
-void math_DoubleTab::Free()
-{
- // free the data
- if(isAllocated) {
- Standard_Address it = (Standard_Address)&Value(LowR,LowC);
- Standard::Free(it);
- }
- // free the pointers
- if(isAddrAllocated) {
- Standard_Address it = (Standard_Address)(((Item**)Addr) + LowR);
- Standard::Free (it);
- }
- Addr = 0;
-}
-
-
-
-void math_DoubleTab::SetLowerRow(const Standard_Integer LowerRow)
-{
- Item** TheAddr = (Item**)Addr;
- Addr = (Standard_Address) (TheAddr + LowR - LowerRow);
- UppR = UppR - LowR + LowerRow;
- LowR = LowerRow;
-}
-
-
-void math_DoubleTab::SetLowerCol(const Standard_Integer LowerCol)
-{
- Item** TheAddr = (Item**) Addr;
- for (Standard_Integer Index = LowR; Index <= UppR; Index++) {
- TheAddr[Index] = TheAddr[Index] + LowC - LowerCol;
- }
-
- UppC = UppC - LowC + LowerCol;
- LowC = LowerCol;
-}
-
#include <math_Memory.hxx>
#include <Standard_OutOfRange.hxx>
-inline Item& math_DoubleTab::Value (const Standard_Integer RowIndex,
+inline Standard_Real& math_DoubleTab::Value (const Standard_Integer RowIndex,
const Standard_Integer ColIndex) const
{
- return ((Item**)Addr)[RowIndex][ColIndex];
+ return ((Standard_Real**)Addr)[RowIndex][ColIndex];
}
{
memmove((void*)(& Other.Value(Other.LowR,Other.LowC)),
(void*) (& Value(LowR,LowC)),
- (int)((UppR - LowR + 1) * (UppC - LowC + 1) * sizeof(Item)));
+ (int)((UppR - LowR + 1) * (UppC - LowC + 1) * sizeof(Standard_Real)));
}
+++ /dev/null
--- Created on: 1991-05-06
--- Created by: Laurent PAINNOT
--- Copyright (c) 1991-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 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.
-
-class IntegerVector from math
-
- ---Purpose:
- -- This class implements the real IntegerVector abstract data type.
- -- IntegerVectors can have an arbitrary range which must be define at
- -- the declaration and cannot be changed after this declaration.
- -- Example: math_IntegerVector V1(-3, 5); // an IntegerVector with
- -- range [-3..5]
- --
- -- IntegerVector is copied through assignement :
- -- math_IntegerVector V2( 1, 9);
- -- ....
- -- V2 = V1;
- -- V1(1) = 2.0; // the IntegerVector V2 will not be modified.
- --
- -- The Exception RangeError is raised when trying to access outside
- -- the range of an IntegerVector :
- -- V1(11) = 0 // --> will raise RangeError;
- --
- -- The Exception DimensionError is raised when the dimensions of two
- -- IntegerVectors are not compatible :
- -- math_IntegerVector V3(1, 2);
- -- V3 = V1; // --> will raise DimensionError;
- -- V1.Add(V3) // --> will raise DimensionError;
-
-uses Matrix from math,
- SingleTabOfInteger from math,
- OStream from Standard
-
-raises DimensionError from Standard,
- DivideByZero from Standard,
- RangeError from Standard
-
-is
-
- Create(First, Last: Integer)
- ---Purpose: contructs an IntegerVector in the range [Lower..Upper]
-
- returns IntegerVector;
-
- Create(First, Last: Integer; InitialValue : Integer)
- ---Purpose: contructs an IntegerVector in the range [Lower..Upper]
- -- with all the elements set to InitialValue.
-
- returns IntegerVector;
-
-
- Init(me : in out; InitialValue: Integer);
- ---Purpose: Initialize an IntegerVector with all the elements
- -- set to InitialValue.
-
-
- Create(Tab : Address; First, Last: Integer)
- ---Purpose: constructs an IntegerVector in the range [Lower..Upper]
- -- which share the "c array" Tab.
-
- returns IntegerVector;
-
-
- Create(Other: IntegerVector)
- ---Purpose: constructs a copy for initialization.
- -- An exception is raised if the lengths of the IntegerVectors
- -- are different.
-
- returns IntegerVector
- raises DimensionError;
-
-
- SetFirst(me: in out; First: Integer)
- ---Purpose: is used internally to set the Lower value of the
- -- IntegerVector.
-
- is static protected;
-
-
- Length(me)
- ---Purpose: returns the length of an IntegerVector
- ---C++: inline
-
- returns Integer
- is static;
-
-
- Lower(me)
- ---Purpose: returns the value of the Lower index of an IntegerVector.
- ---C++: inline
-
- returns Integer
- is static;
-
-
- Upper(me)
- ---Purpose: returns the value of the Upper index of an IntegerVector.
- ---C++: inline
-
- returns Integer
- is static;
-
-
- Norm(me)
- ---Purpose: returns the value of the norm of an IntegerVector.
-
- returns Real
- is static;
-
-
- Norm2 (me)
- ---Purpose: returns the value of the square of the norm of an
- -- IntegerVector.
-
- returns Real
- is static;
-
-
- Max(me)
- ---Purpose: returns the value of the Index of the maximum element of
- -- an IntegerVector.
-
- returns Integer
- is static;
-
-
- Min(me)
- ---Purpose: returns the value of the Index of the minimum element
- -- of an IntegerVector.
-
- returns Integer
- is static;
-
-
- Invert(me: in out)
- ---Purpose: inverses an IntegerVector.
- ---Example: [1, 2, 3, 4] becomes [4, 3, 2, 1].
-
- is static;
-
-
- Inverse(me)
- ---Purpose: returns the inverse IntegerVector of an IntegerVector.
-
- returns IntegerVector
- is static;
-
-
- Set(me: in out; I1, I2: Integer; V: IntegerVector)
- ---Purpose: sets an IntegerVector from <I1> to <I2> to the
- -- IntegerVector <V>;
- -- An exception is raised if I1<LowerIndex or I2>UpperIndex or I1>I2.
- -- An exception is raised if I2-I1+1 is different from the Length of V.
-
- raises DimensionError
- is static;
-
-
- Slice(me; I1, I2: Integer)
- ---Purpose: slices the values of the IntegerVector between <I1> and
- -- <I2>:
- -- Example: [2, 1, 2, 3, 4, 5] becomes [2, 4, 3, 2, 1, 5] between 2 and 5.
- -- An exception is raised if I1<LowerIndex or I2>UpperIndex.
-
- returns IntegerVector
- raises DimensionError
- is static;
-
-
- Multiply (me: in out; Right: Integer)
- ---Purpose: returns the product of an IntegerVector by an integer value.
- ---C++: alias operator *=
-
- raises DimensionError from Standard
- is static;
-
-
- Multiplied (me; Right: Integer)
- ---Purpose: returns the product of an IntegerVector by an integer value.
- ---C++: alias operator*
-
- returns IntegerVector
- raises DimensionError from Standard
- is static;
-
- TMultiplied (me; Right: Integer)
- ---Purpose: returns the product of a vector and a real value.
- ---C++: alias "friend math_IntegerVector operator *(const Standard_Integer Left,const math_IntegerVector& Right);"
- returns IntegerVector
- is static;
-
- Add (me: in out; Right: IntegerVector)
- ---Purpose: adds the IntegerVector <Right> 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.
- ---C++: alias operator +=
-
- raises DimensionError
- is static;
-
-
- Added (me; Right: IntegerVector)
- ---Purpose: adds the IntegerVector <Right> 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.
- ---C++:alias operator+
-
- returns IntegerVector
- raises DimensionError
- is static;
-
-
-
- Add (me: in out; Left, Right: IntegerVector)
- ---Purpose: sets an IntegerVector to the sum of the IntegerVector
- -- <Left> and the IntegerVector <Right>.
- -- An exception is raised if the lengths are different.
-
- raises DimensionError
- is static;
-
-
- Subtract(me: in out; Left, Right: IntegerVector)
- ---Purpose: sets an IntegerVector to the substraction of
- -- <Right> from <Left>.
- -- An exception is raised if the IntegerVectors have not the same
- -- length.
-
- raises DimensionError
- is static;
-
-
- Value(me; Num: Integer)
- ---Purpose: accesses (in read or write mode) the value of index Num of
- -- an IntegerVector.
- ---C++: alias operator()
- ---C++: return &
- ---C++: inline
-
- returns Integer
- raises RangeError from Standard
- is static;
-
-
- Initialized(me: in out; Other: IntegerVector)
- ---Purpose: Initialises an IntegerVector by copying <Other>.
- -- An exception is raised if the Lengths are different.
- ---C++: alias operator=
- ---C++: return &
-
- returns IntegerVector
- raises DimensionError
- is static;
-
-
-
- Multiplied(me; Right: IntegerVector)
- ---Purpose: returns the inner product of 2 IntegerVectors.
- -- An exception is raised if the lengths are not equal.
- ---C++: alias operator*
-
- returns Integer
- raises DimensionError
- is static;
-
-
- Opposite(me: in out)
- ---Purpose: returns the opposite of an IntegerVector.
- ---C++: alias operator-
-
- returns IntegerVector
- is static;
-
-
- Subtract(me: in out; Right: IntegerVector)
- ---Purpose: returns the subtraction of <Right> from <me>.
- -- An exception is raised if the IntegerVectors have not the same length.
- ---C++: alias operator-=
-
- raises DimensionError
- is static;
-
-
- Subtracted(me; Right: IntegerVector)
- ---Purpose: returns the subtraction of <Right> from <me>.
- -- An exception is raised if the IntegerVectors have not the same length.
- ---C++: alias operator-
-
- returns IntegerVector
- raises DimensionError
- is static;
-
-
- Multiply(me: in out; Left: Integer; Right: IntegerVector)
- ---Purpose: returns the multiplication of an integer by an
- -- IntegerVector.
-
- raises DimensionError
- is static;
-
-
- Dump(me; o: in out OStream)
- ---Purpose: Prints on the stream o information on the current state
- -- of the object.
- -- Is used to redefine the operator <<.
-
- is static;
-
-
-fields
-
-FirstIndex: Integer;
-LastIndex: Integer;
-Array: SingleTabOfInteger;
-
-friends
-class Matrix from math
-
-
-end IntegerVector;
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
-//#endif
-#include <math_IntegerVector.ixx>
+#include <math_IntegerVector.hxx>
#include <Standard_DimensionError.hxx>
#include <Standard_RangeError.hxx>
-
-
-math_IntegerVector::math_IntegerVector(const Standard_Integer First,
- const Standard_Integer Last):
- FirstIndex(First),
- LastIndex(Last),
- Array(First, Last) {
-
- Standard_RangeError_Raise_if(First > Last, " ");
+math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast) :
+ FirstIndex(theFirst),
+ LastIndex(theLast),
+ Array(theFirst, theLast)
+{
+ Standard_RangeError_Raise_if(theFirst > theLast, " ");
}
-math_IntegerVector::math_IntegerVector(const Standard_Integer First,
- const Standard_Integer Last,
- const Standard_Integer InitialValue):
- FirstIndex(First),
- LastIndex(Last),
- Array(First, Last) {
-
- Standard_RangeError_Raise_if(First > Last, " ");
- Array.Init(InitialValue);
+math_IntegerVector::math_IntegerVector(const Standard_Integer theFirst,
+ const Standard_Integer theLast,
+ const Standard_Integer theInitialValue) :
+ FirstIndex(theFirst),
+ LastIndex(theLast),
+ Array(theFirst, theLast)
+{
+ Standard_RangeError_Raise_if(theFirst > theLast, " ");
+ Array.Init(theInitialValue);
}
-
-math_IntegerVector::math_IntegerVector(const Standard_Address Tab,
- const Standard_Integer First,
- const Standard_Integer Last) :
- FirstIndex(First),
- LastIndex(Last),
- Array(*((const Standard_Integer *)Tab),
- First, Last)
+math_IntegerVector::math_IntegerVector(const Standard_Address theTab,
+ const Standard_Integer theFirst,
+ const Standard_Integer theLast) :
+ FirstIndex(theFirst),
+ LastIndex(theLast),
+ Array(theTab, theFirst, theLast)
{
- Standard_RangeError_Raise_if(First > Last, " ");
+ Standard_RangeError_Raise_if(theFirst > theLast, " ");
}
-
-void math_IntegerVector::Init(const Standard_Integer InitialValue)
+void math_IntegerVector::Init(const Standard_Integer theInitialValue)
{
- Array.Init(InitialValue);
+ Array.Init(theInitialValue);
}
-
-math_IntegerVector::math_IntegerVector(const math_IntegerVector& Other):
-
- FirstIndex(Other.FirstIndex),
- LastIndex(Other.LastIndex),
- Array(Other.Array) {}
-
-
-
-void math_IntegerVector::SetFirst(const Standard_Integer First) {
-
- Array.SetLower(First);
- LastIndex = LastIndex - FirstIndex + First;
- FirstIndex = First;
+math_IntegerVector::math_IntegerVector(const math_IntegerVector& theOther) :
+ FirstIndex(theOther.FirstIndex),
+ LastIndex(theOther.LastIndex),
+ Array(theOther.Array)
+{
}
+void math_IntegerVector::SetFirst(const Standard_Integer theFirst)
+{
+ Array.SetLower(theFirst);
+ LastIndex = LastIndex - FirstIndex + theFirst;
+ FirstIndex = theFirst;
+}
-Standard_Real math_IntegerVector::Norm() const {
+Standard_Real math_IntegerVector::Norm() const
+{
Standard_Real Result = 0;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
Result = Result + Array(Index) * Array(Index);
}
return Sqrt(Result);
}
-
-Standard_Real math_IntegerVector::Norm2() const {
+Standard_Real math_IntegerVector::Norm2() const
+{
Standard_Real Result = 0;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
Result = Result + Array(Index) * Array(Index);
}
return Result;
}
-
-Standard_Integer math_IntegerVector::Max() const {
+Standard_Integer math_IntegerVector::Max() const
+{
Standard_Integer I=0;
Standard_Real X = RealFirst();
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- if(Array(Index) > X) {
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
+ if(Array(Index) > X)
+ {
X = Array(Index);
I = Index;
}
return I;
}
-
-Standard_Integer math_IntegerVector::Min() const {
+Standard_Integer math_IntegerVector::Min() const
+{
Standard_Integer I=0;
Standard_Real X = RealLast();
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- if(Array(Index) < X) {
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
+ if(Array(Index) < X)
+ {
X = Array(Index);
I = Index;
}
return I;
}
-
-void math_IntegerVector::Invert() {
-
+void math_IntegerVector::Invert()
+{
Standard_Integer J;
Standard_Integer Temp;
-
- for(Standard_Integer Index = FirstIndex;
- Index <= FirstIndex + Length() / 2 ; Index++) {
- J = LastIndex + FirstIndex - Index;
- Temp = Array(Index);
- Array(Index) = Array(J);
- Array(J) = Temp;
+
+ for(Standard_Integer Index = FirstIndex; Index <= FirstIndex + Length() / 2 ; Index++)
+ {
+ J = LastIndex + FirstIndex - Index;
+ Temp = Array(Index);
+ Array(Index) = Array(J);
+ Array(J) = Temp;
}
}
-
-math_IntegerVector math_IntegerVector::Inverse() const {
-
+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 < FirstIndex) || (theI2 > LastIndex) ||
+ (theI1 > theI2) || (theI2 - theI1 + 1 != theV.Length()), " ");
-void math_IntegerVector::Set(const Standard_Integer I1,
- const Standard_Integer I2,
- const math_IntegerVector &V) {
-
- Standard_DimensionError_Raise_if((I1 < FirstIndex) ||
- (I2 > LastIndex) ||
- (I1 > I2) ||
- (I2 - I1 + 1 != V.Length()), " ");
-
- Standard_Integer I = V.Lower();
- for(Standard_Integer Index = I1; Index <= I2; Index++) {
- Array(Index) = V.Array(I);
+ 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 Right) {
-
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- Array(Index) = Array(Index) * Right;
+void math_IntegerVector::Multiply(const Standard_Integer theRight)
+{
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
+ Array(Index) = Array(Index) * theRight;
}
}
+void math_IntegerVector::Add(const math_IntegerVector& theRight)
+{
+ Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
-void math_IntegerVector::Add(const math_IntegerVector& Right) {
-
- Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
-
- Standard_Integer I = Right.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- Array(Index) = Array(Index) + Right.Array(I);
+ Standard_Integer I = theRight.FirstIndex;
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
+ Array(Index) = Array(Index) + theRight.Array(I);
I++;
}
-}
-
+}
-void math_IntegerVector::Subtract(const math_IntegerVector& Right) {
-
- Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
- Standard_Integer I = Right.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- Array(Index) = Array(Index) - Right.Array(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++)
+ {
+ Array(Index) = Array(Index) - theRight.Array(I);
I++;
}
-}
-
-
-math_IntegerVector math_IntegerVector::Slice(const Standard_Integer I1,
- const Standard_Integer I2) const {
-
- Standard_DimensionError_Raise_if((I1 < FirstIndex) || (I1 > LastIndex) ||
- (I2 < FirstIndex) || (I2 > LastIndex),
- " ");
+}
- if(I2 >= I1) {
- math_IntegerVector Result(I1, I2);
- for(Standard_Integer Index = I1; Index <= I2; Index++) {
+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), " ");
+
+ if(theI2 >= theI1)
+ {
+ math_IntegerVector Result(theI1, theI2);
+ for(Standard_Integer Index = theI1; Index <= theI2; Index++)
+ {
Result.Array(Index) = Array(Index);
- }
- return Result;
+ }
+ return Result;
}
- else {
- math_IntegerVector Result(I2, I1);
- for(Standard_Integer Index = I1; Index >= I2; Index--) {
+ 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& Right) const {
-
+Standard_Integer math_IntegerVector::Multiplied (const math_IntegerVector& theRight) const
+{
Standard_Integer Result = 0;
-
- Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
- Standard_Integer I = Right.FirstIndex;
- for(Standard_Integer Index = 0; Index < Length(); Index++) {
- Result = Result + Array(Index) * Right.Array(I);
+ Standard_DimensionError_Raise_if(Length() != theRight.Length(), " ");
+
+ Standard_Integer I = theRight.FirstIndex;
+ 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 Right)const {
-
+math_IntegerVector math_IntegerVector::Multiplied (const Standard_Integer theRight)const
+{
math_IntegerVector Result(FirstIndex, LastIndex);
-
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- Result.Array(Index) = Array(Index) * Right;
+
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
+ Result.Array(Index) = Array(Index) * theRight;
}
return Result;
-}
-
-math_IntegerVector math_IntegerVector::TMultiplied (const Standard_Integer Right)const {
-
+}
+
+math_IntegerVector math_IntegerVector::TMultiplied (const Standard_Integer theRight) const
+{
math_IntegerVector Result(FirstIndex, LastIndex);
-
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- Result.Array(Index) = Array(Index) * Right;
+
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; 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 math_IntegerVector::Added (const math_IntegerVector& Right) const {
-
- Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
-
math_IntegerVector Result(FirstIndex, LastIndex);
-
- Standard_Integer I = Right.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- Result.Array(Index) = Array(Index) + Right.Array(I);
+
+ Standard_Integer I = theRight.FirstIndex;
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
+ Result.Array(Index) = Array(Index) + theRight.Array(I);
I++;
}
return Result;
-}
-
+}
-
-math_IntegerVector math_IntegerVector::Opposite() {
-
+math_IntegerVector math_IntegerVector::Opposite()
+{
math_IntegerVector Result(FirstIndex, LastIndex);
-
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
+
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; 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 math_IntegerVector::Subtracted (const math_IntegerVector& Right) const {
-
- Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
-
math_IntegerVector Result(FirstIndex, LastIndex);
-
- Standard_Integer I = Right.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- Result.Array(Index) = Array(Index) - Right.Array(I);
+
+ Standard_Integer I = theRight.FirstIndex;
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
+ Result.Array(Index) = Array(Index) - theRight.Array(I);
I++;
}
return Result;
-}
-
-void math_IntegerVector::Add (const math_IntegerVector& Left,
- const math_IntegerVector& Right) {
-
- Standard_DimensionError_Raise_if((Length() != Right.Length()) ||
- (Right.Length() != Left.Length()), " ");
-
- Standard_Integer I = Left.FirstIndex;
- Standard_Integer J = Right.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- Array(Index) = Left.Array(I) + Right.Array(J);
+}
+
+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.FirstIndex;
+ Standard_Integer J = theRight.FirstIndex;
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
+ Array(Index) = theLeft.Array(I) + theRight.Array(J);
I++;
J++;
}
-}
-
-
-void math_IntegerVector::Subtract (const math_IntegerVector& Left,
- const math_IntegerVector& Right) {
-
- Standard_DimensionError_Raise_if((Length() != Right.Length()) ||
- (Right.Length() != Left.Length()), " ");
-
- Standard_Integer I = Left.FirstIndex;
- Standard_Integer J = Right.FirstIndex;
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- Array(Index) = Left.Array(I) - Right.Array(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.FirstIndex;
+ Standard_Integer J = theRight.FirstIndex;
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
+ Array(Index) = theLeft.Array(I) - theRight.Array(J);
I++;
J++;
}
-}
-
+}
-void math_IntegerVector::Multiply(const Standard_Integer Left,
- const math_IntegerVector& Right)
+void math_IntegerVector::Multiply(const Standard_Integer theLeft, const math_IntegerVector& theRight)
{
- Standard_DimensionError_Raise_if((Length() != Right.Length()),
- " ");
- for(Standard_Integer I = FirstIndex; I <= LastIndex; I++) {
- Array(I) = Left * Right.Array(I);
+ Standard_DimensionError_Raise_if((Length() != theRight.Length()), " ");
+ for(Standard_Integer I = FirstIndex; I <= LastIndex; I++)
+ {
+ Array(I) = theLeft * theRight.Array(I);
}
}
+math_IntegerVector& math_IntegerVector::Initialized(const math_IntegerVector& theOther)
+{
+ Standard_DimensionError_Raise_if(Length() != theOther.Length(), " ");
-math_IntegerVector& math_IntegerVector::Initialized (const math_IntegerVector& Other) {
-
- Standard_DimensionError_Raise_if(Length() != Other.Length(), " ");
-
- (Other.Array).Copy(Array);
+ (theOther.Array).Copy(Array);
return *this;
}
-
-
-void math_IntegerVector::Dump(Standard_OStream& o) const
+void math_IntegerVector::Dump(Standard_OStream& theO) const
{
- o << "math_IntegerVector of Range = " << Length() << "\n";
- for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
- o << "math_IntegerVector(" << Index << ") = " << Array(Index) << "\n";
- }
+ theO << "math_IntegerVector of Range = " << Length() << "\n";
+ for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++)
+ {
+ theO << "math_IntegerVector(" << Index << ") = " << Array(Index) << "\n";
+ }
}
-
-
-
-
-
--- /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 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_IntegerVector_HeaderFile
+#define _math_IntegerVector_HeaderFile
+
+#include <math_SingleTab.hxx>
+
+class Standard_DimensionError;
+class Standard_DivideByZero;
+class Standard_RangeError;
+class math_Matrix;
+
+//! This class implements the real IntegerVector abstract data type.
+//! IntegerVectors can have an arbitrary range which must be define at
+//! the declaration and cannot be changed after this declaration.
+//! Example:
+//! @code
+//! math_IntegerVector V1(-3, 5); // an IntegerVector with range [-3..5]
+//! @endcode
+//!
+//! IntegerVector is copied through assignement :
+//! @code
+//! math_IntegerVector V2( 1, 9);
+//! ....
+//! V2 = V1;
+//! V1(1) = 2.0; // the IntegerVector V2 will not be modified.
+//! @endcode
+//!
+//! The Exception RangeError is raised when trying to access outside
+//! the range of an IntegerVector :
+//! @code
+//! V1(11) = 0 // --> will raise RangeError;
+//! @endcode
+//!
+//! The Exception DimensionError is raised when the dimensions of two
+//! IntegerVectors are not compatible :
+//! @code
+//! math_IntegerVector V3(1, 2);
+//! V3 = V1; // --> will raise DimensionError;
+//! V1.Add(V3) // --> will raise DimensionError;
+//! @endcode
+class math_IntegerVector
+{
+public:
+
+ DEFINE_STANDARD_ALLOC
+
+ //! contructs an IntegerVector in the range [Lower..Upper]
+ Standard_EXPORT math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast);
+
+ //! contructs 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_Address 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 LastIndex - FirstIndex +1;
+ }
+
+ //! returns the value of the Lower index of an IntegerVector.
+ inline Standard_Integer Lower() const
+ {
+ return FirstIndex;
+ }
+
+ //! returns the value of the Upper index of an IntegerVector.
+ inline Standard_Integer Upper() const
+ {
+ return LastIndex;
+ }
+
+ //! 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_EXPORT math_IntegerVector Multiplied(const Standard_Integer theRight) const;
+
+ math_IntegerVector operator*(const Standard_Integer theRight) const
+ {
+ return Multiplied(theRight);
+ }
+
+ //! returns the product of a vector and a real value.
+ 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_EXPORT math_IntegerVector Added(const math_IntegerVector& theRight) const;
+
+ 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 (in read or write mode) the value of index theNum of an IntegerVector.
+ inline Standard_Integer& Value(const Standard_Integer theNum) const
+ {
+ Standard_RangeError_Raise_if(theNum < FirstIndex || theNum > LastIndex, " ");
+ return Array(theNum);
+ }
+
+ Standard_EXPORT Standard_Integer& operator()(const Standard_Integer theNum) const
+ {
+ 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_EXPORT Standard_Integer Multiplied(const math_IntegerVector& theRight) const;
+
+ 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_EXPORT math_IntegerVector Subtracted(const math_IntegerVector& theRight) const;
+
+ 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:
+
+ Standard_Integer FirstIndex;
+ Standard_Integer LastIndex;
+ math_SingleTab<Standard_Integer> Array;
+};
+
+#endif
+
+++ /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 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.
-
-// lpa, le 29/10/91
-
-#include <Standard_DimensionError.hxx>
-
-inline Standard_OStream& operator<<(Standard_OStream& o,
- const math_IntegerVector& vec)
-{
- vec.Dump(o);
- return o;
-}
-
-inline math_IntegerVector operator* (const Standard_Integer Left,
- const math_IntegerVector& Right)
-{
- return Right.Multiplied(Left);
-}
-
-inline Standard_Integer math_IntegerVector::Length() const
- { return LastIndex - FirstIndex +1;}
- // length of a IntegerVector.
-
-
-
-
-inline Standard_Integer math_IntegerVector::Lower() const
- { return FirstIndex;}
- // value of the lower index of a IntegerVector.
-
-
-inline Standard_Integer math_IntegerVector::Upper() const
- {return LastIndex;}
- // value of the Upper index of a IntegerVector.
-
-
-inline Standard_Integer& math_IntegerVector::Value(const Standard_Integer Num) const {
-
- Standard_RangeError_Raise_if(Num < FirstIndex || Num > LastIndex, " ");
-
- return Array(Num);
- }
uses Vector from math,
- DoubleTabOfReal from math,
+ DoubleTab from math,
OStream from Standard
raises DimensionError from Standard, RangeError from Standard,
UpperRowIndex: Integer;
LowerColIndex: Integer;
UpperColIndex: Integer;
-Array: DoubleTabOfReal;
+Array: DoubleTab;
friends
class Vector from math
UpperRowIndex(UpperRow),
LowerColIndex(LowerCol),
UpperColIndex(UpperCol),
- Array(*((const Standard_Real *)Tab),
- LowerRow, UpperRow,
- LowerCol, UpperCol)
+ Array(Tab, LowerRow, UpperRow, LowerCol, UpperCol)
{
Standard_RangeError_Raise_if((LowerRow > UpperRow) ||
+++ /dev/null
--- Created on: 1992-02-04
--- Created by: Laurent PAINNOT
--- Copyright (c) 1992-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 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.
-
-generic class SingleTab from math (Item as any)
-uses Address from Standard
-is
-
- Create(LowerIndex, UpperIndex: Integer)
- returns SingleTab;
-
- Create(Tab : Item; LowerIndex, UpperIndex: Integer)
- returns SingleTab;
-
- Init(me : in out; InitValue: Item) is static;
-
- Create(Other: SingleTab)
- returns SingleTab;
-
- Copy(me; Other : in out SingleTab)
- ---C++: inline
- is static;
-
- SetLower(me: in out; LowerIndex : Integer)
- is static;
-
- Value(me; Index: Integer)
- ---C++: alias operator()
- ---C++: return &
- ---C++: inline
- returns Item
- is static;
-
-
- Free(me: in out)
- ---C++: alias ~
-
- is static;
-
-fields
-
-Addr : Address;
-Buf : Item[512];
-isAllocated : Boolean;
-First : Integer;
-Last : Integer;
-
-end;
-
+++ /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 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_Memory.hxx>
-#include <Standard_OutOfRange.hxx>
-#include <Standard_Failure.hxx>
-
-// macro to get size of C array
-#define CARRAY_LENGTH(arr) (int)(sizeof(arr)/sizeof(arr[0]))
-
-math_SingleTab::math_SingleTab(const Standard_Integer LowerIndex,
- const Standard_Integer UpperIndex) :
- Addr(Buf),
- isAllocated(UpperIndex - LowerIndex + 1 > CARRAY_LENGTH(Buf)),
- First(LowerIndex), Last(UpperIndex)
-{
- Item* TheAddr = !isAllocated? Buf :
- (Item*) Standard::Allocate((Last-First+1) * sizeof(Item));
- Addr = (Standard_Address) (TheAddr - First);
-}
-
-math_SingleTab::math_SingleTab(const Item& Tab,
- const Standard_Integer LowerIndex,
- const Standard_Integer UpperIndex) :
- Addr((void*)(&Tab - LowerIndex)),
- isAllocated(Standard_False),
- First(LowerIndex), Last(UpperIndex)
-
-{
-}
-
-void math_SingleTab::Init(const Item& InitValue)
-{
- for (Standard_Integer i=First; i<= Last; i++) {
- ((Item*)Addr)[i] = InitValue;
- }
-}
-
-
-math_SingleTab::math_SingleTab(const math_SingleTab& Other) :
-
- isAllocated(Other.Last - Other.First + 1 > CARRAY_LENGTH(Buf)),
- First(Other.First),
- Last(Other.Last)
-
-{
- Item* TheAddr = !isAllocated? Buf :
- (Item*) Standard::Allocate((Last-First+1) * sizeof(Item));
- Addr = (Standard_Address) (TheAddr - First);
- Item* TheOtherAddr = (Item*) Other.Addr;
- memmove((void*) TheAddr, (const void*) (TheOtherAddr + First),
- (size_t)(Last - First + 1) * sizeof(Item));
-}
-
-
-void math_SingleTab::Free()
-{
- if(isAllocated) {
- Standard_Address it = (Standard_Address)&((Item*)Addr)[First];
- Standard::Free(it);
- Addr = 0;
- }
-}
-
-
-void math_SingleTab::SetLower(const Standard_Integer LowerIndex)
-{
- Item* TheAddr = (Item*) Addr;
- Addr = (Standard_Address) (TheAddr + First - LowerIndex);
- Last = Last - First + LowerIndex;
- First = LowerIndex;
-}
-
-
-
-
--- /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 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 <math_Memory.hxx>
+#include <Standard_OutOfRange.hxx>
+#include <Standard_Failure.hxx>
+
+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
+++ /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 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_OutOfRange.hxx>
-#include <math_Memory.hxx>
-
-inline Item& math_SingleTab::Value(const Standard_Integer Index) const
-{
- return ((Item*)Addr)[Index];
-}
-
-
-inline void math_SingleTab::Copy(math_SingleTab& Other) const
-{
- memmove((void*) (((Item*)Other.Addr) + Other.First),
- (const void*) (((Item*)Addr) + First),
- (size_t)(Last - First + 1) * sizeof(Item));
-}
-
-
-
-
-
-
-
-
-
-
-
+++ /dev/null
--- Created on: 1991-05-06
--- Created by: Laurent PAINNOT
--- Copyright (c) 1991-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 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.
-
-class Vector from math
-
- ---Purpose:
- -- 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.
- -- math_Vector V1(-3, 5); // a vector with range [-3..5]
- --
- -- Vector are copied through assignement :
- -- math_Vector V2( 1, 9);
- -- ....
- -- V2 = V1;
- -- V1(1) = 2.0; // the vector V2 will not be modified.
- --
- -- The Exception RangeError is raised when trying to access outside
- -- the range of a vector :
- -- V1(11) = 0.0 // --> will raise RangeError;
- --
- -- The Exception DimensionError is raised when the dimensions of two
- -- vectors are not compatible :
- -- math_Vector V3(1, 2);
- -- V3 = V1; // --> will raise DimensionError;
- -- V1.Add(V3) // --> will raise DimensionError;
-
- -- A Vector can be constructed with a a pointer to "c array".
- -- It allows to carry the bounds inside the Vector.
- -- Exemple :
- -- Standard_Real tab1[10];
- --
- -- math_Vector A (tab1[0], 1, 10);
- -- Vector values may be initialized and
- -- obtained using indexes which must lie within the range
- -- definition of the vector.
- -- Vector objects follow "value semantics", that is, they
- -- cannot be shared and are copied through assignment.
- -- Note: the overview of the Vectors and Matrices
- -- component illustrates these properties on vectors.
-
-uses Matrix from math,
- SingleTabOfReal from math,
- OStream from Standard
-
-raises DimensionError from Standard,
- DivideByZero from Standard,
- RangeError from Standard,
- NullValue from Standard
-
-is
-
- Create(Lower, Upper: Integer)
- ---Purpose: Contructs a non-initialized vector in the range [Lower..Upper]
- -- Lower and Upper are the indexes of the lower and upper
- -- bounds of the constructed vector.
- returns Vector;
-
- Create(Lower, Upper: Integer; InitialValue : Real)
- ---Purpose: Contructs a vector in the range [Lower..Upper]
- -- whose values are all initialized with the value InitialValue..
-
- returns Vector;
-
-
- Create(Tab : Address; Lower, Upper: Integer)
- ---Purpose: Constructs a vector in the range [Lower..Upper]
- -- with the "c array" Tab.
-
- returns Vector;
-
-
- Init(me : in out; InitialValue: Real)
- ---Purpose: Initialize all the elements of a vector with InitialValue.
- is static;
-
- Create(Other: Vector)
- ---Purpose: Constructs a copy for initialization.
- -- An exception is raised if the lengths of the vectors are
- -- different.
-
- returns Vector
- raises DimensionError;
- --JR/Hpis private;
-
-
- SetLower(me: in out; Lower: Integer)
- ---Purpose: Is used internally to set the Lower value of the vector.
-
- is static protected;
-
-
- Length(me)
- ---Purpose: Returns the length of a vector
- ---C++: inline
- returns Integer
- is static;
-
-
- Lower(me)
- ---Purpose: Returns the value of the Lower index of a vector.
- ---C++: inline
-
- returns Integer
- is static;
-
-
- Upper(me)
- ---Purpose: Returns the value of the Upper index of a vector.
- ---C++: inline
-
- returns Integer
- is static;
-
-
- Norm(me)
- ---Purpose: Returns the value or the square of the norm of this vector.
-
- returns Real
- is static;
-
-
- Norm2 (me)
- ---Purpose: Returns the value of the square of the norm of a vector.
-
- returns Real
- is static;
-
-
- Max(me)
- ---Purpose: Returns the value of the Index of the maximum element of a vector.
-
- returns Integer
- is static;
-
-
- Min(me)
- ---Purpose: Returns the value of the Index of the minimum element of a vector.
-
- returns Integer
- is static;
-
-
- Normalize(me: in out)
- ---Purpose: 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().
-
- raises NullValue
- is static;
-
-
-
- Normalized(me)
- ---Purpose: 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().
-
-
- returns Vector
- raises NullValue
- is static;
-
-
- Invert(me: in out)
- ---Purpose: Inverts this vector and assigns the result to this vector.
- --If the values of this vector were (1.,
- -- 2., 3., 4.), the result values are (4., 3., 2., 1.).
- -- Example: [1, 2, 3, 4] becomes [4, 3, 2, 1].
-
- is static;
-
-
- Inverse(me)
- ---Purpose: Inverts this vector and creates a new vector.
- --If the values of this vector were (1.,
- -- 2., 3., 4.), the result values are (4., 3., 2., 1.).
- -- Example: if <me> = [1, 2, 3, 4], the method returns [4, 3, 2, 1].
-
- returns Vector
- is static;
-
-
- Set(me: in out; I1, I2: Integer; V: Vector)
- ---Purpose: sets a vector from <I1> to <I2> to the vector <V>;
- -- An exception is raised if I1<LowerIndex or I2>UpperIndex or I1>I2.
- -- An exception is raised if I2-I1+1 is different from the Length of V.
-
- raises RangeError
- is static;
-
-
- Slice(me; I1, I2: Integer)
- ---Purpose:Creates a new vector by inverting the values of this vector
- -- between indexes I1 and I2.
- -- 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.)
- ---Example: [2, 1, 2, 3, 4, 5] becomes [2, 4, 3, 2, 1, 5] between 2 and 5.
- -- An exception is raised if I1<LowerIndex or I2>UpperIndex.
-
- returns Vector
- raises RangeError
- is static;
-
-
- Multiply (me: in out; Right: Real)
- ---Purpose: returns the product of a vector and a real value.
- ---C++: alias operator *=
- is static;
-
-
- Multiplied (me; Right: Real)
- ---Purpose: returns the product of a vector and a real value.
- ---C++: alias operator*
- returns Vector
- is static;
-
- TMultiplied (me; Right: Real)
- ---Purpose: returns the product of a vector and a real value.
- ---C++: alias "friend math_Vector operator *(const Standard_Real Left,const math_Vector& Right);"
- returns Vector
- is static;
-
-
- Divide (me: in out; Right: Real)
- ---Purpose: divides a vector by the value <Right>.
- -- An exception is raised if <Right> = 0.
- ---C++: alias operator /=
-
- raises DivideByZero from Standard
- is static;
-
-
- Divided (me; Right: Real)
- ---Purpose: divides a vector by the value <Right>.
- -- An exception is raised if <Right> = 0.
- ---C++: alias operator/
-
- returns Vector
- raises DivideByZero from Standard
- is static;
-
-
- Add (me: in out; Right: Vector)
- ---Purpose: adds the vector <Right> 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.
- ---C++: alias operator +=
- raises DimensionError
- is static;
-
-
- Added (me; Right: Vector)
- ---Purpose: adds the vector <Right> 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.
- ---C++:alias operator+
-
- returns Vector
- raises DimensionError
- is static;
-
-
- Multiply (me: in out; Left: Vector; Right: Matrix)
- ---Purpose: sets a vector to the product of the vector <Left>
- -- with the matrix <Right>.
-
- raises DimensionError
- is static;
-
-
- Multiply (me: in out; Left: Matrix; Right: Vector)
- ---Purpose:sets a vector to the product of the matrix <Left>
- -- with the vector <Right>.
-
- raises DimensionError
- is static;
-
-
- TMultiply (me: in out; TLeft: Matrix; Right: Vector)
- ---Purpose: sets a vector to the product of the transpose
- -- of the matrix <TLeft> by the vector <Right>.
-
- raises DimensionError
- is static;
-
-
- TMultiply (me: in out; Left: Vector; TRight: Matrix)
- ---Purpose: sets a vector to the product of the vector
- -- <Left> by the transpose of the matrix <TRight>.
-
- raises DimensionError
- is static;
-
-
- Add (me: in out; Left, Right: Vector)
- ---Purpose: sets a vector to the sum of the vector <Left>
- -- and the vector <Right>.
- -- An exception is raised if the lengths are different.
-
-
- raises DimensionError
- is static;
-
-
- Subtract(me: in out; Left, Right: Vector)
- ---Purpose: sets a vector to the Subtraction of the
- -- vector <Right> from the vector <Left>.
- -- 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.
- raises DimensionError
- is static;
-
-
- Value(me; Num: Integer)
- ---Purpose: accesses (in read or write mode) the value of index Num of
- -- a vector.
- ---C++: alias operator()
- ---C++: return &
- ---C++: inline
-
- returns Real
- raises RangeError from Standard
- is static;
-
-
- Initialized(me: in out; Other: Vector)
- ---Purpose: Initialises a vector by copying <Other>.
- -- An exception is raised if the Lengths are differents.
- ---C++: alias operator=
- ---C++: return &
-
- returns Vector
- raises DimensionError
- is static;
-
-
-
- Multiplied(me; Right: Vector)
- ---Purpose: returns the inner product of 2 vectors.
- -- An exception is raised if the lengths are not equal.
- ---C++: alias operator*
-
- returns Real
- raises DimensionError
- is static;
-
-
- Multiplied(me; Right: Matrix)
- ---Purpose: returns the product of a vector by a matrix.
- ---C++: alias operator*
-
- returns Vector
- raises DimensionError
- is static;
-
-
- Opposite(me : in out)
- ---Purpose: returns the opposite of a vector.
- ---C++: alias operator-
-
- returns Vector
- is static;
-
-
- Subtract(me: in out; Right: Vector)
- ---Purpose: returns the subtraction of <Right> from <me>.
- -- An exception is raised if the vectors have not the same length.
- ---C++: alias operator-=
-
- raises DimensionError
- is static;
-
-
- Subtracted(me; Right: Vector)
- ---Purpose: returns the subtraction of <Right> from <me>.
- -- An exception is raised if the vectors have not the same length.
- ---C++: alias operator-
-
- returns Vector
- raises DimensionError
- is static;
-
-
- Multiply(me: in out; Left: Real; Right: Vector)
- ---Purpose: returns the multiplication of a real by a vector.
- -- <me> = <Left> * <Right>
-
- raises DimensionError
- is static;
-
-
- Dump(me; o: in out OStream)
- ---Purpose: Prints information on the current state of the object.
- -- Is used to redefine the operator <<.
-
- is static;
-
-
-fields
-
-LowerIndex: Integer;
-UpperIndex: Integer;
-Array: SingleTabOfReal;
-
-friends
-class Matrix from math
-
-
-end Vector;
#include <stdio.h>
-#include <math_Vector.ixx>
+#include <math_Vector.hxx>
#include <math_Matrix.hxx>
#include <Standard_DimensionError.hxx>
#include <Standard_RangeError.hxx>
#include <Standard_NullValue.hxx>
-
-math_Vector::math_Vector(const Standard_Integer Lower,
- const Standard_Integer Upper):
-
- LowerIndex(Lower),
- UpperIndex(Upper),
- Array(Lower,Upper) {
- Standard_RangeError_Raise_if(Lower > Upper, "");
- }
-
-math_Vector::math_Vector(const Standard_Integer Lower,
- const Standard_Integer Upper,
- const Standard_Real InitialValue):
-
- LowerIndex(Lower),
- UpperIndex(Upper),
- Array(Lower,Upper)
+math_Vector::math_Vector(const Standard_Integer theLower, const Standard_Integer theUpper) :
+ LowerIndex(theLower),
+ UpperIndex(theUpper),
+ Array(theLower,theUpper)
{
- Standard_RangeError_Raise_if(Lower > Upper, "");
- Array.Init(InitialValue);
+ Standard_RangeError_Raise_if(theLower > theUpper, "");
}
-math_Vector::math_Vector(const Standard_Address Tab,
- const Standard_Integer Lower,
- const Standard_Integer Upper) :
-
- LowerIndex(Lower),
- UpperIndex(Upper),
- Array(*((const Standard_Real *)Tab), Lower,Upper)
+math_Vector::math_Vector(const Standard_Integer theLower,
+ const Standard_Integer theUpper,
+ const Standard_Real theInitialValue):
+ LowerIndex(theLower),
+ UpperIndex(theUpper),
+ Array(theLower,theUpper)
{
- Standard_RangeError_Raise_if((Lower > Upper) , "");
+ Standard_RangeError_Raise_if(theLower > theUpper, "");
+ Array.Init(theInitialValue);
}
-void math_Vector::Init(const Standard_Real InitialValue) {
- Array.Init(InitialValue);
+math_Vector::math_Vector(const Standard_Address theTab,
+ const Standard_Integer theLower,
+ const Standard_Integer theUpper) :
+ LowerIndex(theLower),
+ UpperIndex(theUpper),
+ Array(theTab, theLower,theUpper)
+{
+ Standard_RangeError_Raise_if((theLower > theUpper) , "");
}
-math_Vector::math_Vector(const math_Vector& Other):
-
-LowerIndex(Other.LowerIndex),
-UpperIndex(Other.UpperIndex),
-Array(Other.Array) {}
-
-
-void math_Vector::SetLower(const Standard_Integer Lower) {
+void math_Vector::Init(const Standard_Real theInitialValue)
+{
+ Array.Init(theInitialValue);
+}
- Array.SetLower(Lower);
- UpperIndex = UpperIndex - LowerIndex + Lower;
- LowerIndex = Lower;
+math_Vector::math_Vector(const math_Vector& theOther) :
+ LowerIndex(theOther.LowerIndex),
+ UpperIndex(theOther.UpperIndex),
+ Array(theOther.Array)
+{
}
-Standard_Real math_Vector::Norm() const {
+void math_Vector::SetLower(const Standard_Integer theLower)
+{
+ Array.SetLower(theLower);
+ UpperIndex = UpperIndex - LowerIndex + theLower;
+ LowerIndex = theLower;
+}
+Standard_Real math_Vector::Norm() const
+{
Standard_Real Result = 0;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
Result = Result + Array(Index) * Array(Index);
}
return Sqrt(Result);
}
-Standard_Real math_Vector::Norm2() const {
-
+Standard_Real math_Vector::Norm2() const
+{
Standard_Real Result = 0;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
Result = Result + Array(Index) * Array(Index);
}
return Result;
}
-Standard_Integer math_Vector::Max() const {
-
+Standard_Integer math_Vector::Max() const
+{
Standard_Integer I=0;
Standard_Real X = RealFirst();
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- if(Array(Index) > X) {
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ if(Array(Index) > X)
+ {
X = Array(Index);
I = Index;
}
return I;
}
-Standard_Integer math_Vector::Min() const {
-
+Standard_Integer math_Vector::Min() const
+{
Standard_Integer I=0;
Standard_Real X = RealLast();
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- if(Array(Index) < X) {
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ if(Array(Index) < X)
+ {
X = Array(Index);
I = Index;
}
return I;
}
-void math_Vector::Set(const Standard_Integer I1,
- const Standard_Integer I2,
- const math_Vector &V) {
+void math_Vector::Set(const Standard_Integer theI1,
+ const Standard_Integer theI2,
+ const math_Vector &theV)
+{
+ Standard_RangeError_Raise_if((theI1 < LowerIndex) || (theI2 > UpperIndex) ||
+ (theI1 > theI2) || (theI2 - theI1 + 1 != theV.Length()), "");
- Standard_RangeError_Raise_if((I1 < LowerIndex) ||
- (I2 > UpperIndex) ||
- (I1 > I2) ||
- (I2 - I1 + 1 != V.Length()), "");
-
- Standard_Integer I = V.Lower();
- for(Standard_Integer Index = I1; Index <= I2; Index++) {
- Array(Index) = V.Array(I);
+ Standard_Integer I = theV.Lower();
+ for(Standard_Integer Index = theI1; Index <= theI2; Index++)
+ {
+ Array(Index) = theV.Array(I);
I++;
}
}
-void math_Vector::Normalize() {
-
+void math_Vector::Normalize()
+{
Standard_Real Result = Norm();
Standard_NullValue_Raise_if((Result <= RealEpsilon()), "");
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
Array(Index) = Array(Index) / Result;
}
}
-math_Vector math_Vector::Normalized() const {
-
+math_Vector math_Vector::Normalized() const
+{
math_Vector Result = *this;
Result.Normalize();
return Result;
}
-void math_Vector::Invert() {
+void math_Vector::Invert()
+{
Standard_Integer J;
Standard_Real Temp;
- for(Standard_Integer Index = LowerIndex;
-// Index <= LowerIndex + (Length()) >> 1 ; Index++) {
- Index <= (LowerIndex + Length()) >> 1 ; Index++) {
+ for(Standard_Integer Index = LowerIndex; Index <= (LowerIndex + Length()) >> 1 ; Index++)
+ {
J = UpperIndex + LowerIndex - Index;
Temp = Array(Index);
Array(Index) = Array(J);
}
}
-math_Vector math_Vector::Inverse() const {
+math_Vector math_Vector::Inverse() const
+{
math_Vector Result = *this;
Result.Invert();
return Result;
}
-math_Vector math_Vector::Multiplied(const Standard_Real Right) const{
-
+math_Vector math_Vector::Multiplied(const Standard_Real theRight) const
+{
math_Vector Result (LowerIndex, UpperIndex);
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- Result.Array(Index) = Array(Index) * Right;
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ Result.Array(Index) = Array(Index) * theRight;
}
return Result;
}
-math_Vector math_Vector::TMultiplied(const Standard_Real Right) const{
-
+math_Vector math_Vector::TMultiplied(const Standard_Real theRight) const
+{
math_Vector Result (LowerIndex, UpperIndex);
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- Result.Array(Index) = Array(Index) * Right;
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ Result.Array(Index) = Array(Index) * theRight;
}
return Result;
}
-
-void math_Vector::Multiply(const Standard_Real Right) {
-
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- Array(Index) = Array(Index) * Right;
+void math_Vector::Multiply(const Standard_Real theRight)
+{
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ Array(Index) = Array(Index) * theRight;
}
}
+void math_Vector::Divide(const Standard_Real theRight)
+{
+ Standard_DivideByZero_Raise_if(Abs(theRight) <= RealEpsilon(), "");
-void math_Vector::Divide(const Standard_Real Right) {
-
- Standard_DivideByZero_Raise_if(Abs(Right) <= RealEpsilon(), "");
-
- for(Standard_Integer Index =LowerIndex; Index <=UpperIndex; Index++) {
- Array(Index) = Array(Index) / Right;
+ for(Standard_Integer Index =LowerIndex; Index <=UpperIndex; Index++)
+ {
+ Array(Index) = Array(Index) / theRight;
}
}
-
-math_Vector math_Vector::Divided (const Standard_Real Right) const {
-
- Standard_DivideByZero_Raise_if(Abs(Right) <= RealEpsilon(), "");
- math_Vector temp = Multiplied(1./Right);
+math_Vector math_Vector::Divided (const Standard_Real theRight) const
+{
+ Standard_DivideByZero_Raise_if(Abs(theRight) <= RealEpsilon(), "");
+ math_Vector temp = Multiplied(1./theRight);
return temp;
}
+void math_Vector::Add(const math_Vector& theRight)
+{
+ Standard_DimensionError_Raise_if(Length() != theRight.Length(), "");
-void math_Vector::Add(const math_Vector& Right) {
-
- Standard_DimensionError_Raise_if(Length() != Right.Length(), "");
-
- Standard_Integer I = Right.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- Array(Index) = Array(Index) + Right.Array(I);
+ Standard_Integer I = theRight.LowerIndex;
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ Array(Index) = Array(Index) + theRight.Array(I);
I++;
}
-}
-
-math_Vector math_Vector::Added(const math_Vector& Right) const{
+}
- Standard_DimensionError_Raise_if(Length() != Right.Length(), "");
+math_Vector math_Vector::Added(const math_Vector& theRight) const
+{
+ Standard_DimensionError_Raise_if(Length() != theRight.Length(), "");
math_Vector Result(LowerIndex, UpperIndex);
-
- Standard_Integer I = Right.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- Result.Array(Index) = Array(Index) + Right.Array(I);
+
+ Standard_Integer I = theRight.LowerIndex;
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ Result.Array(Index) = Array(Index) + theRight.Array(I);
I++;
}
return Result;
-}
-
-
-
-void math_Vector::Subtract(const math_Vector& Right) {
+}
- Standard_DimensionError_Raise_if(Length() != Right.Length(), "");
+void math_Vector::Subtract(const math_Vector& theRight)
+{
+ Standard_DimensionError_Raise_if(Length() != theRight.Length(), "");
- Standard_Integer I = Right.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- Array(Index) = Array(Index) - Right.Array(I);
+ Standard_Integer I = theRight.LowerIndex;
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ Array(Index) = Array(Index) - theRight.Array(I);
I++;
}
-}
-
+}
-math_Vector math_Vector::Subtracted (const math_Vector& Right) const {
+math_Vector math_Vector::Subtracted (const math_Vector& theRight) const
+{
+ Standard_DimensionError_Raise_if(Length() != theRight.Length(), "");
- Standard_DimensionError_Raise_if(Length() != Right.Length(), "");
-
math_Vector Result(LowerIndex, UpperIndex);
-
- Standard_Integer I = Right.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- Result.Array(Index) = Array(Index) - Right.Array(I);
+
+ Standard_Integer I = theRight.LowerIndex;
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ Result.Array(Index) = Array(Index) - theRight.Array(I);
I++;
}
return Result;
-}
-
+}
-math_Vector math_Vector::Slice(const Standard_Integer I1,
- const Standard_Integer I2) const
+math_Vector math_Vector::Slice(const Standard_Integer theI1, const Standard_Integer theI2) const
{
-
- Standard_RangeError_Raise_if((I1 < LowerIndex) ||
- (I1 > UpperIndex) ||
- (I2 < LowerIndex) ||
- (I2 > UpperIndex) , "");
-
+ Standard_RangeError_Raise_if((theI1 < LowerIndex) || (theI1 > UpperIndex) || (theI2 < LowerIndex) || (theI2 > UpperIndex) , "");
- if(I2 >= I1) {
- math_Vector Result(I1, I2);
- for(Standard_Integer Index = I1; Index <= I2; Index++) {
+ if(theI2 >= theI1)
+ {
+ math_Vector Result(theI1, theI2);
+ for(Standard_Integer Index = theI1; Index <= theI2; Index++)
+ {
Result.Array(Index) = Array(Index);
- }
- return Result;
+ }
+ return Result;
}
- else {
- math_Vector Result(I2, I1);
- for(Standard_Integer Index = I1; Index >= I2; Index--) {
+ 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()), "");
-void math_Vector::Add (const math_Vector& Left, const math_Vector& Right) {
-
- Standard_DimensionError_Raise_if((Length() != Right.Length()) ||
- (Right.Length() != Left.Length()), "");
-
-
- Standard_Integer I = Left.LowerIndex;
- Standard_Integer J = Right.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- Array(Index) = Left.Array(I) + Right.Array(J);
+ Standard_Integer I = theLeft.LowerIndex;
+ Standard_Integer J = theRight.LowerIndex;
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ Array(Index) = theLeft.Array(I) + theRight.Array(J);
I++;
J++;
}
-}
-
-void math_Vector::Subtract (const math_Vector& Left,
- const math_Vector& Right) {
-
- Standard_DimensionError_Raise_if((Length() != Right.Length()) ||
- (Right.Length() != Left.Length()), "");
-
- Standard_Integer I = Left.LowerIndex;
- Standard_Integer J = Right.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- Array(Index) = Left.Array(I) - Right.Array(J);
+}
+
+void math_Vector::Subtract (const math_Vector& theLeft, const math_Vector& theRight)
+{
+ Standard_DimensionError_Raise_if((Length() != theRight.Length()) || (theRight.Length() != theLeft.Length()), "");
+
+ Standard_Integer I = theLeft.LowerIndex;
+ Standard_Integer J = theRight.LowerIndex;
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ Array(Index) = theLeft.Array(I) - theRight.Array(J);
I++;
J++;
}
-}
-
-void math_Vector::Multiply(const math_Matrix& Left,
- const math_Vector& Right) {
+}
- Standard_DimensionError_Raise_if((Length() != Left.RowNumber()) ||
- (Left.ColNumber() != Right.Length()),
- "");
+void math_Vector::Multiply(const math_Matrix& theLeft, const math_Vector& theRight)
+{
+ Standard_DimensionError_Raise_if((Length() != theLeft.RowNumber()) ||
+ (theLeft.ColNumber() != theRight.Length()), "");
Standard_Integer Index = LowerIndex;
- for(Standard_Integer I = Left.LowerRowIndex; I <= Left.UpperRowIndex; I++) {
+ for(Standard_Integer I = theLeft.LowerRowIndex; I <= theLeft.UpperRowIndex; I++)
+ {
Array(Index) = 0.0;
- Standard_Integer K = Right.LowerIndex;
- for(Standard_Integer J = Left.LowerColIndex; J <= Left.UpperColIndex; J++) {
- Array(Index) = Array(Index) + Left.Array(I, J) * Right.Array(K);
+ Standard_Integer K = theRight.LowerIndex;
+ 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& Left,
- const math_Matrix& Right) {
+}
- Standard_DimensionError_Raise_if((Length() != Right.ColNumber()) ||
- (Left.Length() != Right.RowNumber()),
- "");
+void math_Vector::Multiply(const math_Vector& theLeft, const math_Matrix& theRight)
+{
+ Standard_DimensionError_Raise_if((Length() != theRight.ColNumber()) ||
+ (theLeft.Length() != theRight.RowNumber()), "");
Standard_Integer Index = LowerIndex;
- for(Standard_Integer J = Right.LowerColIndex; J <= Right.UpperColIndex; J++) {
+ for(Standard_Integer J = theRight.LowerColIndex; J <= theRight.UpperColIndex; J++)
+ {
Array(Index) = 0.0;
- Standard_Integer K = Left.LowerIndex;
- for(Standard_Integer I = Right.LowerRowIndex; I <= Right.UpperRowIndex; I++) {
- Array(Index) = Array(Index) + Left.Array(K) * Right.Array(I, J);
+ Standard_Integer K = theLeft.LowerIndex;
+ 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& TLeft,
- const math_Vector& Right) {
+}
- Standard_DimensionError_Raise_if((Length() != TLeft.ColNumber()) ||
- (TLeft.RowNumber() != Right.Length()),
- "");
+void math_Vector::TMultiply(const math_Matrix& theTLeft, const math_Vector& theRight)
+{
+ Standard_DimensionError_Raise_if((Length() != theTLeft.ColNumber()) ||
+ (theTLeft.RowNumber() != theRight.Length()), "");
Standard_Integer Index = LowerIndex;
- for(Standard_Integer I = TLeft.LowerColIndex; I <= TLeft.UpperColIndex; I++) {
+ for(Standard_Integer I = theTLeft.LowerColIndex; I <= theTLeft.UpperColIndex; I++)
+ {
Array(Index) = 0.0;
- Standard_Integer K = Right.LowerIndex;
- for(Standard_Integer J = TLeft.LowerRowIndex; J <= TLeft.UpperRowIndex; J++) {
- Array(Index) = Array(Index) + TLeft.Array(J, I) * Right.Array(K);
+ Standard_Integer K = theRight.LowerIndex;
+ 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& Left,
- const math_Matrix& TRight) {
+}
- Standard_DimensionError_Raise_if((Length() != TRight.RowNumber()) ||
- (Left.Length() != TRight.ColNumber()),
- "");
+void math_Vector::TMultiply(const math_Vector& theLeft, const math_Matrix& theTRight)
+{
+ Standard_DimensionError_Raise_if((Length() != theTRight.RowNumber()) ||
+ (theLeft.Length() != theTRight.ColNumber()), "");
Standard_Integer Index = LowerIndex;
- for(Standard_Integer J = TRight.LowerRowIndex; J <= TRight.UpperRowIndex; J++) {
+ for(Standard_Integer J = theTRight.LowerRowIndex; J <= theTRight.UpperRowIndex; J++)
+ {
Array(Index) = 0.0;
- Standard_Integer K = Left.LowerIndex;
- for(Standard_Integer I = TRight.LowerColIndex;
- I <= TRight.UpperColIndex; I++) {
- Array(Index) = Array(Index) + Left.Array(K) * TRight.Array(J, I);
- K++;
+ Standard_Integer K = theLeft.LowerIndex;
+ 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& Right) const{
+Standard_Real math_Vector::Multiplied(const math_Vector& theRight) const
+{
Standard_Real Result = 0;
- Standard_DimensionError_Raise_if(Length() != Right.Length(), "");
+ Standard_DimensionError_Raise_if(Length() != theRight.Length(), "");
- Standard_Integer I = Right.LowerIndex;
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
- Result = Result + Array(Index) * Right.Array(I);
+ Standard_Integer I = theRight.LowerIndex;
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ Result = Result + Array(Index) * theRight.Array(I);
I++;
}
return Result;
-}
+}
-math_Vector math_Vector::Opposite() {
+math_Vector math_Vector::Opposite()
+{
math_Vector Result(LowerIndex, UpperIndex);
- for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++) {
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
Result.Array(Index) = - Array(Index);
}
return Result;
-}
-
-math_Vector math_Vector::Multiplied(const math_Matrix& Right)const {
- Standard_DimensionError_Raise_if(Length() != Right.RowNumber(), "");
-
- math_Vector Result(Right.LowerColIndex, Right.UpperColIndex);
- for(Standard_Integer J2 = Right.LowerColIndex;
- J2 <= Right.UpperColIndex; J2++) {
- Array(J2) = 0.0;
- Standard_Integer I2 = Right.LowerRowIndex;
- for(Standard_Integer I = LowerIndex; I <= UpperIndex; I++) {
- Result.Array(J2) = Result.Array(J2) + Array(I) *
- Right.Array(I2, J2);
- I2++;
- }
+}
+
+math_Vector math_Vector::Multiplied(const math_Matrix& theRight)const
+{
+ Standard_DimensionError_Raise_if(Length() != theRight.RowNumber(), "");
+
+ 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++;
+ }
}
return Result;
-}
-
+}
-void math_Vector::Multiply(const Standard_Real Left,
- const math_Vector& Right)
+void math_Vector::Multiply(const Standard_Real theLeft, const math_Vector& theRight)
{
- Standard_DimensionError_Raise_if((Length() != Right.Length()),
- "");
- for(Standard_Integer I = LowerIndex; I <= UpperIndex; I++) {
- Array(I) = Left * Right.Array(I);
+ Standard_DimensionError_Raise_if((Length() != theRight.Length()), "");
+ for(Standard_Integer I = LowerIndex; I <= UpperIndex; 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& math_Vector::Initialized(const math_Vector& Other) {
-
- Standard_DimensionError_Raise_if(Length() != Other.Length(), "");
-
- (Other.Array).Copy(Array);
+ (theOther.Array).Copy(Array);
return *this;
}
-
-
-void math_Vector::Dump(Standard_OStream& o) const
+void math_Vector::Dump(Standard_OStream& theO) const
{
- o << "math_Vector of Length = " << Length() << "\n";
- for(Standard_Integer Index = LowerIndex;
- Index <= UpperIndex; Index++) {
- o << "math_Vector(" << Index << ") = " << Array(Index) << "\n";
+ theO << "math_Vector of Length = " << Length() << "\n";
+ for(Standard_Integer Index = LowerIndex; Index <= UpperIndex; Index++)
+ {
+ theO << "math_Vector(" << Index << ") = " << Array(Index) << "\n";
}
}
+
--- /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 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_Vector_HeaderFile
+#define _math_Vector_HeaderFile
+
+#include <math_SingleTab.hxx>
+
+class Standard_DimensionError;
+class Standard_DivideByZero;
+class Standard_RangeError;
+class Standard_NullValue;
+class math_Matrix;
+
+//! 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_Vector V1(-3, 5); // a vector with range [-3..5]
+//! @endcode
+//!
+//! Vector are copied through assignement :
+//! @code
+//! math_Vector 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_Vector V3(1, 2);
+//! V3 = V1; // --> will raise DimensionError;
+//! V1.Add(V3) // --> will raise DimensionError;
+//! @endcode
+class math_Vector
+{
+public:
+
+ DEFINE_STANDARD_ALLOC
+
+ //! Contructs 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);
+
+ //! Contructs 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_Address theTab, const Standard_Integer theLower, const Standard_Integer theUpper);
+
+ //! 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 UpperIndex - LowerIndex +1;
+ }
+
+ //! Returns the value of the theLower index of a vector.
+ inline Standard_Integer Lower() const
+ {
+ return LowerIndex;
+ }
+
+ //! Returns the value of the theUpper index of a vector.
+ inline Standard_Integer Upper() const
+ {
+ return UpperIndex;
+ }
+
+ //! 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_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_EXPORT math_Vector Multiplied(const Standard_Real theRight) const;
+
+ math_Vector operator*(const Standard_Real theRight) const
+ {
+ return Multiplied(theRight);
+ }
+
+ //! returns the product of a vector and a real value.
+ 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_EXPORT math_Vector Divided(const Standard_Real theRight) const;
+
+ 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_EXPORT math_Vector Added(const math_Vector& theRight) const;
+
+ 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 (in read or write mode) the value of index "theNum" of a vector.
+ inline Standard_Real& Value(const Standard_Integer theNum) const
+ {
+ Standard_RangeError_Raise_if(theNum < LowerIndex || theNum > UpperIndex, " ");
+ return Array(theNum);
+ }
+
+ Standard_Real& operator()(const Standard_Integer theNum) const
+ {
+ return Value(theNum);
+ }
+
+ //! Initialises a vector by copying "theOther".
+ //! An exception is raised if the Lengths are differents.
+ 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_EXPORT Standard_Real Multiplied(const math_Vector& theRight) const;
+ Standard_Real operator*(const math_Vector& theRight) const
+ {
+ return Multiplied(theRight);
+ }
+
+ //! returns the product of a vector by a matrix.
+ Standard_EXPORT math_Vector Multiplied(const math_Matrix& theRight) const;
+
+ 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_EXPORT math_Vector Subtracted(const math_Vector& theRight) const;
+
+ 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:
+
+ Standard_Integer LowerIndex;
+ Standard_Integer UpperIndex;
+ math_SingleTab<Standard_Real> Array;
+};
+
+#endif
+++ /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 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.
-
-// lpa, le 29/10/91
-
-#include <Standard_DimensionError.hxx>
-
-inline Standard_OStream& operator<<(Standard_OStream& o,
- const math_Vector& vec)
-{
- vec.Dump(o);
- return o;
-}
-
-inline math_Vector operator* (const Standard_Real Left,
- const math_Vector& Right)
-{
- return Right.Multiplied(Left);
-}
-
-
-inline Standard_Integer math_Vector::Length() const
- { return UpperIndex - LowerIndex +1;}
- // length of a vector.
-
-
-inline Standard_Integer math_Vector::Lower() const
- { return LowerIndex;}
- // value of the lower index of a vector.
-
-
-inline Standard_Integer math_Vector::Upper() const
- {return UpperIndex;}
- // value of the Upper index of a vector.
-
-
-inline Standard_Real& math_Vector::Value(const Standard_Integer Num) const {
-
- Standard_RangeError_Raise_if(Num < LowerIndex || Num > UpperIndex, " ");
-
- return Array(Num);
-}
-
-