OpenLexocad  28.0
Mat2d.h
Go to the documentation of this file.
1 //
3 // Copyright(C) 2013-2016 OpenCascade [www.opencascade.org]
4 //
5 // This library is free software; you can redistribute it and / or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street,
18 // Fifth Floor, Boston, MA 02110 - 1301 USA
19 //
21 
22 #pragma once
23 
24 
25 namespace Geom
26 {
27 class GTrsf2d;
28 class Trsf2d;
29 class XY;
30 
33 class LX_GEOM_EXPORT Mat2d
34 {
35 public:
37  Mat2d();
38 
40  Mat2d(const XY& Col1, const XY& Col2);
41  void add(const Mat2d& Other);
48  Mat2d added(const Mat2d& Other) const;
52  double& changeValue(const int Row, const int Col);
55  XY column(const int Col) const;
57  double determinant() const;
59  XY diagonal() const;
60  void divide(const double Scalar);
62  Mat2d divided(const double Scalar) const;
63  void invert();
64 
67  Mat2d inverted() const;
68 
69  static inline bool isEven(const int Value) { return Value % 2 == 0; }
70 
71  static inline bool isOdd(const int Value) { return Value % 2 != 0; }
76  bool isSingular() const;
77 
78  Mat2d multiplied(const Mat2d& Other) const;
80  void multiply(const Mat2d& Other);
81  Mat2d multiplied(const double Scalar) const;
83  void multiply(const double Scalar);
84  void operator+=(const Mat2d& Other) { add(Other); }
85 
86  Mat2d operator+(const Mat2d& Other) const { return added(Other); }
87 
88  void operator-=(const Mat2d& Other) { subtract(Other); }
89 
90  Mat2d operator-(const Mat2d& Other) const { return subtracted(Other); }
91 
92  void operator*=(const double Scalar) { multiply(Scalar); }
93 
94  Mat2d operator*(const double Scalar) const { return multiplied(Scalar); }
95 
96  Mat2d operator*(const Mat2d& Other) const { return multiplied(Other); }
97 
98  void operator/=(const double Scalar) { divide(Scalar); }
99 
100  Mat2d operator/(const double Scalar) const { return divided(Scalar); }
101 
102  const double& operator()(const int Row, const int Col) const { return value(Row, Col); }
103  double& operator()(const int Row, const int Col) { return changeValue(Row, Col); }
104 
105  void power(const int N);
106 
112  Mat2d powered(const int N) const;
113 
116  void preMultiply(const Mat2d& Other);
117 
119  XY row(const int Row) const;
123  void setCol(const int Col, const XY& Value);
125  void setCols(const XY& Col1, const XY& Col2);
126 
131  void setDiagonal(const double X1, const double X2);
133  void setIdentity();
134 
137  void setRotation(const double Ang);
140  void setRow(const int Row, const XY& Value);
142  void setRows(const XY& Row1, const XY& Row2);
143 
148  void setScale(const double S);
151  void setValue(const int Row, const int Col, const double Value);
152  void subtract(const Mat2d& Other);
155  Mat2d subtracted(const Mat2d& Other) const;
156  void transpose();
157 
159  Mat2d transposed() const;
160 
164  const double& value(const int Row, const int Col) const;
165  friend class GTrsf2d;
166  friend class Trsf2d;
167  friend class XY;
168 
169 protected:
170 private:
171  double _matrix[2][2];
172 };
173 } // namespace Geom
Geom::Mat2d::multiplied
Mat2d multiplied(const Mat2d &Other) const
Geom::Mat2d::diagonal
XY diagonal() const
Returns the main diagonal of the matrix.
Geom::Mat2d::subtracted
Mat2d subtracted(const Mat2d &Other) const
Geom::Mat2d::invert
void invert()
Geom::Mat2d::multiply
void multiply(const Mat2d &Other)
Computes the product of two matrices <me> * <Other>
Geom::Mat2d::value
const double & value(const int Row, const int Col) const
Geom::Mat2d::setCols
void setCols(const XY &Col1, const XY &Col2)
Assigns the number pairs Col1, Col2 to the two columns of this matrix
Geom::Mat2d::isOdd
static bool isOdd(const int Value)
Definition: Mat2d.h:71
Geom::Mat2d::transpose
void transpose()
Geom::Mat2d::added
Mat2d added(const Mat2d &Other) const
Geom::Mat2d::operator()
double & operator()(const int Row, const int Col)
Definition: Mat2d.h:103
Geom::Mat2d::inverted
Mat2d inverted() const
Geom::Mat2d::power
void power(const int N)
Geom::Mat2d::setScale
void setScale(const double S)
Geom::Mat2d::powered
Mat2d powered(const int N) const
Geom::XY
Definition: XY.h:34
Geom::Mat2d::divide
void divide(const double Scalar)
Geom::Mat2d::preMultiply
void preMultiply(const Mat2d &Other)
Geom::Mat2d::Mat2d
Mat2d()
Creates a matrix with null coefficients.
Geom::Mat2d::transposed
Mat2d transposed() const
Transposes the matrix. A(j, i) -> A (i, j)
Geom::Mat2d::setValue
void setValue(const int Row, const int Col, const double Value)
Geom::Mat2d
Definition: Mat2d.h:34
Geom::Mat2d::operator+=
void operator+=(const Mat2d &Other)
Definition: Mat2d.h:84
Geom::Mat2d::operator-=
void operator-=(const Mat2d &Other)
Definition: Mat2d.h:88
Geom::Mat2d::Mat2d
Mat2d(const XY &Col1, const XY &Col2)
Col1, Col2 are the 2 columns of the matrix.
Geom::Mat2d::changeValue
double & changeValue(const int Row, const int Col)
Geom::Mat2d::subtract
void subtract(const Mat2d &Other)
Geom::Mat2d::multiply
void multiply(const double Scalar)
Multiplies all the coefficients of the matrix by a scalar.
Geom::Mat2d::isEven
static bool isEven(const int Value)
Definition: Mat2d.h:69
Geom::GTrsf2d
Definition: GTrsf2d.h:49
Geom::Mat2d::operator*
Mat2d operator*(const double Scalar) const
Definition: Mat2d.h:94
Geom::Mat2d::operator+
Mat2d operator+(const Mat2d &Other) const
Definition: Mat2d.h:86
Geom::Mat2d::setCol
void setCol(const int Col, const XY &Value)
Geom::Mat2d::operator*=
void operator*=(const double Scalar)
Definition: Mat2d.h:92
Geom::Mat2d::add
void add(const Mat2d &Other)
Geom::Mat2d::setRotation
void setRotation(const double Ang)
Geom::Mat2d::multiplied
Mat2d multiplied(const double Scalar) const
Geom::Mat2d::operator/
Mat2d operator/(const double Scalar) const
Definition: Mat2d.h:100
Geom::Mat2d::setDiagonal
void setDiagonal(const double X1, const double X2)
Geom::Mat2d::isSingular
bool isSingular() const
Geom::Mat2d::operator()
const double & operator()(const int Row, const int Col) const
Definition: Mat2d.h:102
Geom::Trsf2d
Definition: Trsf2d.h:47
Geom::Mat2d::divided
Mat2d divided(const double Scalar) const
Divides all the coefficients of the matrix by a scalar.
Geom::Mat2d::operator/=
void operator/=(const double Scalar)
Definition: Mat2d.h:98
Geom::Mat2d::setRows
void setRows(const XY &Row1, const XY &Row2)
Assigns the number pairs Row1, Row2 to the two rows of this matrix.
Geom::Mat2d::column
XY column(const int Col) const
Geom::Mat2d::operator*
Mat2d operator*(const Mat2d &Other) const
Definition: Mat2d.h:96
Geom::Mat2d::row
XY row(const int Row) const
Returns the row of index Row. //! Raised if Row < 1 or Row > 2
Geom::Mat2d::operator-
Mat2d operator-(const Mat2d &Other) const
Definition: Mat2d.h:90
Geom::Mat2d::setIdentity
void setIdentity()
Modifies this matrix, so that it represents the Identity matrix.
Geom::Mat2d::setRow
void setRow(const int Row, const XY &Value)
Geom
Definition: PropertyContainer.h:33
Geom::Mat2d::determinant
double determinant() const
Computes the determinant of the matrix.