7fd59977 |
1 | // File gp_Trsf.lxx, JCV 03/06/90 |
2 | // Modif JCV 04/10/90 ajout des methodes Form Scale IsNegative |
3 | // Modif JCV 10/12/90 ajout de la methode Translationpart |
4 | |
5 | |
6 | #include <Standard_OutOfRange.hxx> |
7 | #include <gp_Trsf2d.hxx> |
8 | #include <gp_Vec.hxx> |
9 | #include <gp_Pnt.hxx> |
10 | |
11 | inline gp_Trsf::gp_Trsf () : |
12 | scale(1.0), |
13 | shape(gp_Identity), |
14 | matrix(1,0,0, 0,1,0, 0,0,1), |
15 | loc(0.0, 0.0, 0.0) |
16 | {} |
17 | |
18 | inline gp_Trsf::gp_Trsf (const gp_Trsf2d& T) : |
19 | scale(T.ScaleFactor()), |
20 | shape(T.Form()), |
21 | loc(T.TranslationPart().X(),T.TranslationPart().Y(), 0.0) |
22 | { |
23 | const gp_Mat2d& M = T.HVectorialPart(); |
24 | matrix(1,1) = M(1,1); |
25 | matrix(1,2) = M(1,2); |
26 | matrix(2,1) = M(2,1); |
27 | matrix(2,2) = M(2,2); |
28 | matrix(3,3) = 1.; |
29 | } |
30 | |
31 | inline void gp_Trsf::SetMirror (const gp_Pnt& P) |
32 | { |
33 | shape = gp_PntMirror; |
34 | scale = -1.0; |
35 | loc = P.XYZ(); |
36 | matrix.SetIdentity (); |
37 | loc.Multiply(2.0); |
38 | } |
39 | |
40 | inline void gp_Trsf::SetTranslation (const gp_Vec& V) |
41 | { |
42 | shape = gp_Translation; |
43 | scale = 1.; |
44 | matrix.SetIdentity (); |
45 | loc = V.XYZ(); |
46 | } |
47 | |
48 | inline void gp_Trsf::SetTranslation(const gp_Pnt& P1, |
49 | const gp_Pnt& P2) |
50 | { |
51 | shape = gp_Translation; |
52 | scale = 1.0; |
53 | matrix.SetIdentity (); |
54 | loc = (P2.XYZ()).Subtracted (P1.XYZ()); |
55 | } |
56 | |
57 | inline Standard_Boolean gp_Trsf::IsNegative() const |
58 | { return (scale < 0.0); } |
59 | |
60 | inline const gp_XYZ& gp_Trsf::TranslationPart () const |
61 | { return loc; } |
62 | |
63 | inline const gp_Mat& gp_Trsf::HVectorialPart () const |
64 | { return matrix; } |
65 | |
66 | inline Standard_Real gp_Trsf::Value (const Standard_Integer Row, |
67 | const Standard_Integer Col) const |
68 | { |
69 | Standard_OutOfRange_Raise_if |
70 | (Row < 1 || Row > 3 || Col < 1 || Col > 4, " "); |
71 | if (Col < 4) return scale * matrix.Value (Row, Col); |
72 | else return loc.Coord (Row); |
73 | } |
74 | |
75 | inline gp_TrsfForm gp_Trsf::Form () const |
76 | { return shape; } |
77 | |
78 | inline Standard_Real gp_Trsf::ScaleFactor () const |
79 | { return scale; } |
80 | |
81 | inline gp_Trsf gp_Trsf::Inverted() const |
82 | { |
83 | gp_Trsf T = *this; |
84 | T.Invert(); |
85 | return T; |
86 | } |
87 | |
88 | inline gp_Trsf gp_Trsf::Multiplied (const gp_Trsf& T) const |
89 | { |
90 | gp_Trsf Tresult(*this); |
91 | Tresult.Multiply(T); |
92 | return Tresult; |
93 | } |
94 | |
95 | inline gp_Trsf gp_Trsf::Powered (const Standard_Integer N) |
96 | { |
97 | gp_Trsf T = *this; |
98 | T.Power (N); |
99 | return T; |
100 | } |
101 | |
102 | inline void gp_Trsf::Transforms (Standard_Real& X, |
103 | Standard_Real& Y, |
104 | Standard_Real& Z) const |
105 | { |
106 | gp_XYZ Triplet (X, Y, Z); |
107 | Triplet.Multiply (matrix); |
108 | if (scale != 1.0) Triplet.Multiply (scale); |
109 | Triplet.Add(loc); |
110 | X = Triplet.X(); |
111 | Y = Triplet.Y(); |
112 | Z = Triplet.Z(); |
113 | } |
114 | |
115 | inline void gp_Trsf::Transforms (gp_XYZ& Coord) const |
116 | { |
117 | Coord.Multiply (matrix); |
118 | if (scale != 1.0) Coord.Multiply (scale); |
119 | Coord.Add(loc); |
120 | } |
121 | |