0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / gp / gp_GTrsf.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.
7fd59977 14
15#define No_Standard_OutOfRange
16
42cf5bc1 17
18#include <gp_Ax1.hxx>
19#include <gp_Ax2.hxx>
20#include <gp_GTrsf.hxx>
7fd59977 21#include <gp_Mat.hxx>
42cf5bc1 22#include <gp_Trsf.hxx>
23#include <gp_XYZ.hxx>
24#include <Standard_ConstructionError.hxx>
25#include <Standard_OutOfRange.hxx>
7fd59977 26
27void gp_GTrsf::SetTranslationPart (const gp_XYZ& Coord)
28{
29 loc = Coord;
30 if (Form() == gp_CompoundTrsf || Form() == gp_Other ||
31 Form() == gp_Translation) { }
32 else if (Form() == gp_Identity) { shape = gp_Translation; }
33 else { shape = gp_CompoundTrsf; }
34}
35
36void gp_GTrsf::Invert ()
37{
38 if (shape == gp_Other) {
39 matrix.Invert() ;
40 loc.Multiply (matrix);
41 loc.Reverse();
42 }
43 else {
44 gp_Trsf T = Trsf();
45 T.Invert ();
46 SetTrsf (T);
47 }
48}
49
50void gp_GTrsf::Multiply (const gp_GTrsf& T)
51{
52 if (Form() == gp_Other || T.Form() == gp_Other) {
53 shape = gp_Other;
54 loc.Add (T.loc.Multiplied (matrix));
55 matrix.Multiply(T.matrix);
56 }
57 else {
58 gp_Trsf T1 = Trsf();
59 gp_Trsf T2 = T.Trsf();
60 T1.Multiply(T2);
61 matrix = T1.matrix;
62 loc = T1.loc;
63 scale = T1.scale;
64 shape = T1.shape;
65 }
66}
67
68void gp_GTrsf::Power (const Standard_Integer N)
69{
70 if (N == 0) {
71 scale = 1.;
72 shape = gp_Identity;
73 matrix.SetIdentity();
74 loc = gp_XYZ (0.,0.,0.);
75 }
76 else if (N == 1) { }
77 else if (N == -1) { Invert(); }
78 else {
79 if (shape == gp_Other) {
80 Standard_Integer Npower = N;
81 if (Npower < 0) Npower = - Npower;
82 Npower--;
83 gp_XYZ Temploc = loc;
84// Standard_Real Tempscale = scale;
85 gp_Mat Tempmatrix (matrix);
302f96fb 86 for(;;) {
7fd59977 87 if (IsOdd(Npower)) {
88 loc.Add (Temploc.Multiplied (matrix));
89 matrix.Multiply (Tempmatrix);
90 }
91 if (Npower == 1) { break; }
92 Temploc.Add (Temploc.Multiplied (Tempmatrix));
93 Tempmatrix.Multiply (Tempmatrix);
94 Npower = Npower/2;
95 }
96 }
97 else {
98 gp_Trsf T = Trsf ();
99 T.Power (N);
100 SetTrsf (T);
101 }
102 }
103}
104
105void gp_GTrsf::PreMultiply (const gp_GTrsf& T)
106{
107 if (Form() == gp_Other || T.Form() == gp_Other) {
108 shape = gp_Other;
109 loc.Multiply (T.matrix);
110 loc.Add (T.loc);
111 matrix.PreMultiply(T.matrix);
112 }
113 else {
114 gp_Trsf T1 = Trsf();
115 gp_Trsf T2 = T.Trsf();
116 T1.PreMultiply(T2);
117 matrix = T1.matrix;
118 loc = T1.loc;
119 scale = T1.scale;
120 shape = T1.shape;
121 }
122}
123
124void gp_GTrsf::SetForm()
125{
126 Standard_Real tol = 1.e-12; // Precision::Angular();
127 //
128 // don t trust the initial values !
129 //
130 gp_Mat M(matrix);
131 Standard_Real s = M.Determinant();
18ee2939 132
133 if ( Abs(s) < gp::Resolution() )
9775fa61 134 throw Standard_ConstructionError("gp_GTrsf::SetForm, null determinant");
18ee2939 135
7fd59977 136 if (s > 0)
137 s = Pow(s,1./3.);
138 else
139 s = -Pow(-s,1./3.);
140 M.Divide(s);
141
142 // check if the matrix is an uniform matrix
143 // the transposition should be the invert.
144 gp_Mat TM(M);
145 TM.Transpose();
146 TM.Multiply(M);
147 gp_Mat anIdentity ;
148 anIdentity.SetIdentity() ;
149 TM.Subtract(anIdentity);
150 if (shape==gp_Other) shape = gp_CompoundTrsf;
151
18ee2939 152 for (Standard_Integer i = 1; i <= 3; i++)
153 for (Standard_Integer j = 1; j <= 3; j++)
154 if ( Abs( TM.Value(i, j) ) > tol )
155 {
156 shape = gp_Other;
157 return;
7fd59977 158 }
7fd59977 159}