OpenLexocad  27.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 #include <Geom/geom_defines.h>
26 
27 namespace Geom
28 {
29 class GTrsf2d;
30 class Trsf2d;
31 class XY;
32 
36 {
37 public:
39  Mat2d();
40 
42  Mat2d(const XY& Col1, const XY& Col2);
43  void add(const Mat2d& Other);
50  Mat2d added(const Mat2d& Other) const;
54  double& changeValue(const int Row, const int Col);
57  XY column(const int Col) const;
59  double determinant() const;
61  XY diagonal() const;
62  void divide(const double Scalar);
64  Mat2d divided(const double Scalar) const;
65  void invert();
66 
69  Mat2d inverted() const;
70 
71  static inline bool isEven(const int Value) { return Value % 2 == 0; }
72 
73  static inline bool isOdd(const int Value) { return Value % 2 != 0; }
78  bool isSingular() const;
79 
80  Mat2d multiplied(const Mat2d& Other) const;
82  void multiply(const Mat2d& Other);
83  Mat2d multiplied(const double Scalar) const;
85  void multiply(const double Scalar);
86  void operator+=(const Mat2d& Other) { add(Other); }
87 
88  Mat2d operator+(const Mat2d& Other) const { return added(Other); }
89 
90  void operator-=(const Mat2d& Other) { subtract(Other); }
91 
92  Mat2d operator-(const Mat2d& Other) const { return subtracted(Other); }
93 
94  void operator*=(const double Scalar) { multiply(Scalar); }
95 
96  Mat2d operator*(const double Scalar) const { return multiplied(Scalar); }
97 
98  Mat2d operator*(const Mat2d& Other) const { return multiplied(Other); }
99 
100  void operator/=(const double Scalar) { divide(Scalar); }
101 
102  Mat2d operator/(const double Scalar) const { return divided(Scalar); }
103 
104  const double& operator()(const int Row, const int Col) const { return value(Row, Col); }
105  double& operator()(const int Row, const int Col) { return changeValue(Row, Col); }
106 
107  void power(const int N);
108 
114  Mat2d powered(const int N) const;
115 
118  void preMultiply(const Mat2d& Other);
119 
121  XY row(const int Row) const;
125  void setCol(const int Col, const XY& Value);
127  void setCols(const XY& Col1, const XY& Col2);
128 
133  void setDiagonal(const double X1, const double X2);
135  void setIdentity();
136 
139  void setRotation(const double Ang);
142  void setRow(const int Row, const XY& Value);
144  void setRows(const XY& Row1, const XY& Row2);
145 
150  void setScale(const double S);
153  void setValue(const int Row, const int Col, const double Value);
154  void subtract(const Mat2d& Other);
157  Mat2d subtracted(const Mat2d& Other) const;
158  void transpose();
159 
161  Mat2d transposed() const;
162 
166  const double& value(const int Row, const int Col) const;
167  friend class GTrsf2d;
168  friend class Trsf2d;
169  friend class XY;
170 
171 protected:
172 private:
173  double _matrix[2][2];
174 };
175 } // namespace Geom
Definition: Rotation.h:5
Definition: XY.h:35
static bool isEven(const int Value)
Definition: Mat2d.h:71
Mat2d operator+(const Mat2d &Other) const
Definition: Mat2d.h:88
static bool isOdd(const int Value)
Definition: Mat2d.h:73
Definition: Mat2d.h:35
#define GEOM_EXPORT
Definition: geom_defines.h:8
void operator/=(const double Scalar)
Definition: Mat2d.h:100
Definition: GTrsf2d.h:48
Definition: Trsf2d.h:46
Mat2d operator-(const Mat2d &Other) const
Definition: Mat2d.h:92
Geom::Vec operator *(const double Scalar, const Geom::Vec &V)
Definition: Vec.h:312
const double & operator()(const int Row, const int Col) const
Definition: Mat2d.h:104
Mat2d operator/(const double Scalar) const
Definition: Mat2d.h:102
void operator-=(const Mat2d &Other)
Definition: Mat2d.h:90
double & operator()(const int Row, const int Col)
Definition: Mat2d.h:105
void operator+=(const Mat2d &Other)
Definition: Mat2d.h:86