0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / gp / gp_Mat2d.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
0797d9d3 15#ifndef OCCT_DEBUG
7fd59977 16#define No_Standard_OutOfRange
17#define No_Standard_ConstructionError
18#endif
19
d5477f8c 20#include <gp_Mat2d.hxx>
42cf5bc1 21
22#include <gp_GTrsf2d.hxx>
42cf5bc1 23#include <gp_Trsf2d.hxx>
24#include <gp_XY.hxx>
7fd59977 25#include <Standard_ConstructionError.hxx>
42cf5bc1 26#include <Standard_OutOfRange.hxx>
7fd59977 27
623e54f9 28// =======================================================================
29// function : gp_Mat2d
30// purpose :
31// =======================================================================
32gp_Mat2d::gp_Mat2d (const gp_XY& theCol1, const gp_XY& theCol2)
7fd59977 33{
623e54f9 34 myMat[0][0] = theCol1.X(); myMat[1][0] = theCol1.Y();
35 myMat[0][1] = theCol2.X(); myMat[1][1] = theCol2.Y();
7fd59977 36}
37
623e54f9 38// =======================================================================
39// function : SetCol
40// purpose :
41// =======================================================================
42void gp_Mat2d::SetCol (const Standard_Integer theCol,
43 const gp_XY& theValue)
7fd59977 44{
623e54f9 45 Standard_OutOfRange_Raise_if (theCol < 1 || theCol > 2, "gp_Mat2d::SetCol() - invalid index");
46 if (theCol == 1)
47 {
48 myMat[0][0] = theValue.X();
49 myMat[1][0] = theValue.Y();
7fd59977 50 }
623e54f9 51 else
52 {
53 myMat[0][1] = theValue.X();
54 myMat[1][1] = theValue.Y();
7fd59977 55 }
56}
57
623e54f9 58// =======================================================================
59// function : SetCols
60// purpose :
61// =======================================================================
62void gp_Mat2d::SetCols (const gp_XY& theCol1,
63 const gp_XY& theCol2)
7fd59977 64{
623e54f9 65 myMat[0][0] = theCol1.X(); myMat[1][0] = theCol1.Y();
66 myMat[0][1] = theCol2.X(); myMat[1][1] = theCol2.Y();
7fd59977 67}
68
623e54f9 69// =======================================================================
70// function : SetRow
71// purpose :
72// =======================================================================
73void gp_Mat2d::SetRow (const Standard_Integer theRow, const gp_XY& theValue)
7fd59977 74{
623e54f9 75 Standard_OutOfRange_Raise_if (theRow < 1 || theRow > 2, "gp_Mat2d::SetRow() - invalid index");
76 if (theRow == 1)
77 {
78 myMat[0][0] = theValue.X();
79 myMat[0][1] = theValue.Y();
7fd59977 80 }
623e54f9 81 else
82 {
83 myMat[1][0] = theValue.X();
84 myMat[1][1] = theValue.Y();
7fd59977 85 }
86}
87
623e54f9 88// =======================================================================
89// function : SetRows
90// purpose :
91// =======================================================================
92void gp_Mat2d::SetRows (const gp_XY& theRow1, const gp_XY& theRow2)
7fd59977 93{
623e54f9 94 myMat[0][0] = theRow1.X(); myMat[0][1] = theRow1.Y();
95 myMat[1][0] = theRow2.X(); myMat[1][1] = theRow2.Y();
7fd59977 96}
97
623e54f9 98// =======================================================================
99// function : Column
100// purpose :
101// =======================================================================
102gp_XY gp_Mat2d::Column (const Standard_Integer theCol) const
7fd59977 103{
623e54f9 104 Standard_OutOfRange_Raise_if (theCol < 1 || theCol > 2, "gp_Mat2d::Column() - invalid index");
105 if (theCol == 1)
106 {
107 return gp_XY (myMat[0][0], myMat[1][0]);
108 }
109 return gp_XY (myMat[0][1], myMat[1][1]);
7fd59977 110}
111
623e54f9 112// =======================================================================
113// function : Diagonal
114// purpose :
115// =======================================================================
116gp_XY gp_Mat2d::Diagonal() const
7fd59977 117{
623e54f9 118 return gp_XY (myMat[0][0], myMat[1][1]);
7fd59977 119}
120
623e54f9 121// =======================================================================
122// function : Row
123// purpose :
124// =======================================================================
125gp_XY gp_Mat2d::Row (const Standard_Integer theRow) const
7fd59977 126{
623e54f9 127 Standard_OutOfRange_Raise_if (theRow < 1 || theRow > 2, "gp_Mat2d::Row() - invalid index");
128 if (theRow == 1)
129 {
130 return gp_XY (myMat[0][0], myMat[0][1]);
131 }
132 return gp_XY (myMat[1][0], myMat[1][1]);
7fd59977 133}
134
623e54f9 135// =======================================================================
136// function : Invert
137// purpose :
138// =======================================================================
139void gp_Mat2d::Invert()
7fd59977 140{
623e54f9 141 Standard_Real aNewMat[2][2];
142 aNewMat[0][0] = myMat[1][1];
143 aNewMat[0][1] = -myMat[0][1];
144 aNewMat[1][0] = -myMat[1][0];
145 aNewMat[1][1] = myMat[0][0];
146 Standard_Real aDet = aNewMat[0][0] * aNewMat[1][1] - aNewMat[0][1] * aNewMat[1][0];
147 Standard_Real val = aDet;
7fd59977 148 if (val < 0) val = - val;
2d2b3d53 149 Standard_ConstructionError_Raise_if (val <= gp::Resolution(), "gp_Mat2d::Invert() - matrix has zero determinant");
623e54f9 150 aDet = 1.0 / aDet;
151 myMat[0][0] = aNewMat[0][0] * aDet;
152 myMat[1][0] = aNewMat[1][0] * aDet;
153 myMat[0][1] = aNewMat[0][1] * aDet;
154 myMat[1][1] = aNewMat[1][1] * aDet;
7fd59977 155}
156
623e54f9 157// =======================================================================
158// function : Power
159// purpose :
160// =======================================================================
161void gp_Mat2d::Power (const Standard_Integer theN)
7fd59977 162{
623e54f9 163 if (theN == 1) { }
164 else if (theN == 0) { SetIdentity(); }
165 else if (theN == -1) { Invert(); }
7fd59977 166 else {
623e54f9 167 if (theN < 0) Invert();
168 Standard_Integer Npower = theN;
7fd59977 169 if (Npower < 0) Npower = - Npower;
170 Npower--;
623e54f9 171 gp_Mat2d aTemp = *this;
302f96fb 172 for(;;) {
623e54f9 173 if (IsOdd(Npower)) Multiply (aTemp);
7fd59977 174 if (Npower == 1) break;
623e54f9 175 aTemp.Multiply (aTemp);
7fd59977 176 Npower = Npower/2;
177 }
178 }
179}