0030448: Coding - add typo detection to derivation creation methods using Standard_NO...
[occt.git] / src / gp / gp_Mat2d.hxx
CommitLineData
42cf5bc1 1// Copyright (c) 1991-1999 Matra Datavision
2// Copyright (c) 1999-2014 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15#ifndef _gp_Mat2d_HeaderFile
16#define _gp_Mat2d_HeaderFile
17
18#include <Standard.hxx>
19#include <Standard_DefineAlloc.hxx>
20#include <Standard_Handle.hxx>
21
22#include <Standard_Real.hxx>
23#include <Standard_Integer.hxx>
24#include <Standard_Boolean.hxx>
25class Standard_ConstructionError;
26class Standard_OutOfRange;
27class gp_Trsf2d;
28class gp_GTrsf2d;
29class gp_XY;
30
31
32
33//! Describes a two column, two row matrix. This sort of
34//! object is used in various vectorial or matrix computations.
35class gp_Mat2d
36{
37public:
38
39 DEFINE_STANDARD_ALLOC
40
41
42 //! Creates a matrix with null coefficients.
43 gp_Mat2d();
44
45
46 //! Col1, Col2 are the 2 columns of the matrix.
47 Standard_EXPORT gp_Mat2d(const gp_XY& Col1, const gp_XY& Col2);
48
49 //! Assigns the two coordinates of Value to the column of range
50 //! Col of this matrix
51 //! Raises OutOfRange if Col < 1 or Col > 2.
52 Standard_EXPORT void SetCol (const Standard_Integer Col, const gp_XY& Value);
53
54 //! Assigns the number pairs Col1, Col2 to the two columns of this matrix
55 Standard_EXPORT void SetCols (const gp_XY& Col1, const gp_XY& Col2);
56
57
58 //! Modifies the main diagonal of the matrix.
59 //! <me>.Value (1, 1) = X1
60 //! <me>.Value (2, 2) = X2
61 //! The other coefficients of the matrix are not modified.
62 void SetDiagonal (const Standard_Real X1, const Standard_Real X2);
63
64 //! Modifies this matrix, so that it represents the Identity matrix.
65 void SetIdentity();
66
67
68 //! Modifies this matrix, so that it representso a rotation. Ang is the angular
69 //! value in radian of the rotation.
70 void SetRotation (const Standard_Real Ang);
71
72 //! Assigns the two coordinates of Value to the row of index Row of this matrix.
73 //! Raises OutOfRange if Row < 1 or Row > 2.
74 Standard_EXPORT void SetRow (const Standard_Integer Row, const gp_XY& Value);
75
76 //! Assigns the number pairs Row1, Row2 to the two rows of this matrix.
77 Standard_EXPORT void SetRows (const gp_XY& Row1, const gp_XY& Row2);
78
79
80 //! Modifies the matrix such that it
81 //! represents a scaling transformation, where S is the scale factor :
82 //! | S 0.0 |
83 //! <me> = | 0.0 S |
84 void SetScale (const Standard_Real S);
85
86 //! Assigns <Value> to the coefficient of row Row, column Col of this matrix.
87 //! Raises OutOfRange if Row < 1 or Row > 2 or Col < 1 or Col > 2
88 void SetValue (const Standard_Integer Row, const Standard_Integer Col, const Standard_Real Value);
89
90 //! Returns the column of Col index.
91 //! Raises OutOfRange if Col < 1 or Col > 2
92 Standard_EXPORT gp_XY Column (const Standard_Integer Col) const;
93
94 //! Computes the determinant of the matrix.
95 Standard_Real Determinant() const;
96
97 //! Returns the main diagonal of the matrix.
98 Standard_EXPORT gp_XY Diagonal() const;
99
100 //! Returns the row of index Row.
101 //! Raised if Row < 1 or Row > 2
102 Standard_EXPORT gp_XY Row (const Standard_Integer Row) const;
103
104 //! Returns the coefficient of range (Row, Col)
105 //! Raises OutOfRange
106 //! if Row < 1 or Row > 2 or Col < 1 or Col > 2
107 const Standard_Real& Value (const Standard_Integer Row, const Standard_Integer Col) const;
108 const Standard_Real& operator() (const Standard_Integer Row, const Standard_Integer Col) const
109{
110 return Value(Row,Col);
111}
112
113 //! Returns the coefficient of range (Row, Col)
114 //! Raises OutOfRange
115 //! if Row < 1 or Row > 2 or Col < 1 or Col > 2
116 Standard_Real& ChangeValue (const Standard_Integer Row, const Standard_Integer Col);
117 Standard_Real& operator() (const Standard_Integer Row, const Standard_Integer Col)
118{
119 return ChangeValue(Row,Col);
120}
121
122
123 //! Returns true if this matrix is singular (and therefore, cannot be inverted).
124 //! The Gauss LU decomposition is used to invert the matrix
125 //! so the matrix is considered as singular if the largest
126 //! pivot found is lower or equal to Resolution from gp.
127 Standard_Boolean IsSingular() const;
128
129 void Add (const gp_Mat2d& Other);
130 void operator += (const gp_Mat2d& Other)
131{
132 Add(Other);
133}
134
135
136 //! Computes the sum of this matrix and the matrix
137 //! Other.for each coefficient of the matrix :
138 //! <me>.Coef(i,j) + <Other>.Coef(i,j)
139 //! Note:
140 //! - operator += assigns the result to this matrix, while
141 //! - operator + creates a new one.
0be7dbe1
BB
142 Standard_NODISCARD gp_Mat2d Added (const gp_Mat2d& Other) const;
143 Standard_NODISCARD gp_Mat2d operator + (const gp_Mat2d& Other) const
42cf5bc1 144{
145 return Added(Other);
146}
147
148 void Divide (const Standard_Real Scalar);
149 void operator /= (const Standard_Real Scalar)
150{
151 Divide(Scalar);
152}
153
154
155 //! Divides all the coefficients of the matrix by a scalar.
0be7dbe1
BB
156 Standard_NODISCARD gp_Mat2d Divided (const Standard_Real Scalar) const;
157 Standard_NODISCARD gp_Mat2d operator / (const Standard_Real Scalar) const
42cf5bc1 158{
159 return Divided(Scalar);
160}
161
162 Standard_EXPORT void Invert();
163
164
165 //! Inverses the matrix and raises exception if the matrix
166 //! is singular.
0be7dbe1 167 Standard_NODISCARD gp_Mat2d Inverted() const;
42cf5bc1 168
0be7dbe1
BB
169 Standard_NODISCARD gp_Mat2d Multiplied (const gp_Mat2d& Other) const;
170 Standard_NODISCARD gp_Mat2d operator * (const gp_Mat2d& Other) const
42cf5bc1 171{
172 return Multiplied(Other);
173}
174
175
176 //! Computes the product of two matrices <me> * <Other>
177 void Multiply (const gp_Mat2d& Other);
178
179 //! Modifies this matrix by premultiplying it by the matrix Other
180 //! <me> = Other * <me>.
181 void PreMultiply (const gp_Mat2d& Other);
182
0be7dbe1
BB
183 Standard_NODISCARD gp_Mat2d Multiplied (const Standard_Real Scalar) const;
184 Standard_NODISCARD gp_Mat2d operator * (const Standard_Real Scalar) const
42cf5bc1 185{
186 return Multiplied(Scalar);
187}
188
189
190 //! Multiplies all the coefficients of the matrix by a scalar.
191 void Multiply (const Standard_Real Scalar);
192 void operator *= (const Standard_Real Scalar)
193{
194 Multiply(Scalar);
195}
196
197 Standard_EXPORT void Power (const Standard_Integer N);
198
199
200 //! computes <me> = <me> * <me> * .......* <me>, N time.
201 //! if N = 0 <me> = Identity
202 //! if N < 0 <me> = <me>.Invert() *...........* <me>.Invert().
203 //! If N < 0 an exception can be raised if the matrix is not
204 //! inversible
0be7dbe1 205 Standard_NODISCARD gp_Mat2d Powered (const Standard_Integer N) const;
42cf5bc1 206
207 void Subtract (const gp_Mat2d& Other);
208 void operator -= (const gp_Mat2d& Other)
209{
210 Subtract(Other);
211}
212
213
214 //! Computes for each coefficient of the matrix :
215 //! <me>.Coef(i,j) - <Other>.Coef(i,j)
0be7dbe1
BB
216 Standard_NODISCARD gp_Mat2d Subtracted (const gp_Mat2d& Other) const;
217 Standard_NODISCARD gp_Mat2d operator - (const gp_Mat2d& Other) const
42cf5bc1 218{
219 return Subtracted(Other);
220}
221
222 void Transpose();
223
224
225 //! Transposes the matrix. A(j, i) -> A (i, j)
0be7dbe1 226 Standard_NODISCARD gp_Mat2d Transposed() const;
42cf5bc1 227
228
229friend class gp_Trsf2d;
230friend class gp_GTrsf2d;
231friend class gp_XY;
232
233
234protected:
235
236
237
238
239
240private:
241
242
243
244 Standard_Real matrix[2][2];
245
246
247};
248
249
250#include <gp_Mat2d.lxx>
251
252
253
254
255
256#endif // _gp_Mat2d_HeaderFile