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 | #include <gp_Trsf2d.hxx> |
16 | #include <Standard_OutOfRange.hxx> |
17 | |
18 | inline gp_GTrsf2d::gp_GTrsf2d () |
19 | { |
20 | shape = gp_Identity; |
21 | matrix.SetScale (1.0); |
22 | loc.SetCoord (0.0, 0.0); |
23 | scale = 1.0; |
24 | } |
25 | |
26 | inline gp_GTrsf2d::gp_GTrsf2d (const gp_Trsf2d& T) |
27 | { |
28 | shape = T.shape; |
29 | matrix = T.matrix; |
30 | loc = T.loc; |
31 | scale = T.scale; |
32 | } |
33 | |
34 | inline gp_GTrsf2d::gp_GTrsf2d (const gp_Mat2d& M, |
35 | const gp_XY& V) : |
36 | matrix(M), |
37 | loc(V) |
38 | { shape = gp_Other; scale = 0.0; } |
39 | |
40 | inline void gp_GTrsf2d::SetValue (const Standard_Integer Row, |
41 | const Standard_Integer Col, |
42 | const Standard_Real Value) |
43 | { |
44 | Standard_OutOfRange_Raise_if |
45 | (Row < 1 || Row > 2 || Col < 1 || Col > 3, " "); |
46 | if (Col == 3) loc.SetCoord (Row, Value); |
47 | else matrix.SetValue (Row, Col, Value); |
48 | shape = gp_Other; |
49 | } |
50 | |
51 | inline void gp_GTrsf2d::SetTrsf2d (const gp_Trsf2d& T) |
52 | { |
53 | shape = T.shape; |
54 | matrix = T.matrix; |
55 | loc = T.loc; |
56 | scale = T.scale; |
57 | } |
58 | |
59 | inline void gp_GTrsf2d::SetVectorialPart (const gp_Mat2d& Matrix) |
60 | { matrix = Matrix; shape = gp_Other; scale = 0.0; } |
61 | |
62 | inline Standard_Boolean gp_GTrsf2d::IsNegative () const |
63 | { return matrix.Determinant() < 0.0; } |
64 | |
65 | inline Standard_Boolean gp_GTrsf2d::IsSingular () const |
66 | { return matrix.IsSingular(); } |
67 | |
68 | inline const gp_Mat2d& gp_GTrsf2d::VectorialPart () const |
69 | { return matrix; } |
70 | |
71 | inline Standard_Real gp_GTrsf2d::Value (const Standard_Integer Row, |
72 | const Standard_Integer Col) const |
73 | { |
74 | Standard_OutOfRange_Raise_if |
75 | (Row < 1 || Row > 2 || Col < 1 || Col > 3, " "); |
76 | if (Col == 3) return loc.Coord (Row); |
77 | if (shape == gp_Other) return matrix.Value (Row, Col); |
78 | return scale * matrix.Value (Row, Col); |
79 | } |
80 | |
81 | inline gp_TrsfForm gp_GTrsf2d::Form () const |
82 | { return shape; } |
83 | |
84 | inline const gp_XY& gp_GTrsf2d::TranslationPart () const |
85 | { return loc; } |
86 | |
87 | inline gp_GTrsf2d gp_GTrsf2d::Inverted () const |
88 | { |
89 | gp_GTrsf2d T = *this; |
90 | T.Invert (); |
91 | return T; |
92 | } |
93 | |
94 | inline gp_GTrsf2d gp_GTrsf2d::Multiplied (const gp_GTrsf2d& T) const |
95 | { |
96 | gp_GTrsf2d Tres = *this; |
97 | Tres.Multiply (T); |
98 | return Tres; |
99 | } |
100 | |
101 | inline gp_GTrsf2d gp_GTrsf2d::Powered (const Standard_Integer N) const |
102 | { |
103 | gp_GTrsf2d T = *this; |
104 | T.Power (N); |
105 | return T; |
106 | } |
107 | |
108 | inline void gp_GTrsf2d::Transforms (gp_XY& Coord) const |
109 | { |
110 | Coord.Multiply (matrix); |
111 | if (!(shape == gp_Other) && !(scale == 1.0)) Coord.Multiply (scale); |
112 | Coord.Add(loc); |
113 | } |
114 | |
115 | inline gp_XY gp_GTrsf2d::Transformed(const gp_XY& Coord) const |
116 | { |
117 | gp_XY newCoord = Coord; |
118 | Transforms(newCoord); |
119 | return newCoord; |
120 | } |
121 | |
122 | inline void gp_GTrsf2d::Transforms (Standard_Real& X, |
123 | Standard_Real& Y) const |
124 | { |
125 | gp_XY Doublet (X, Y); |
126 | Doublet.Multiply (matrix); |
127 | if (!(shape == gp_Other) && !(scale == 1.0)) Doublet.Multiply (scale); |
128 | Doublet.Add(loc); |
129 | Doublet.Coord (X, Y); |
130 | } |
131 | |