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 | |
7fd59977 |
15 | // Modif JCV 08/01/91 introduction classe XY dans le package gp |
16 | |
17 | #include <Standard_ConstructionError.hxx> |
18 | #include <Standard_OutOfRange.hxx> |
19 | #include <gp_XY.hxx> |
20 | #include <gp_Ax2d.hxx> |
21 | #include <gp_Trsf2d.hxx> |
22 | |
23 | inline gp_Dir2d::gp_Dir2d() : coord (1.,0.) |
24 | { |
25 | } |
26 | |
27 | inline gp_Dir2d::gp_Dir2d (const gp_Vec2d& V) |
28 | { |
29 | const gp_XY& XY = V.XY(); |
30 | Standard_Real X = XY.X(); |
31 | Standard_Real Y = XY.Y(); |
32 | Standard_Real D = sqrt(X * X + Y * Y); |
2d2b3d53 |
33 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm"); |
7fd59977 |
34 | coord.SetX(X / D); |
35 | coord.SetY(Y / D); |
36 | } |
37 | |
38 | inline gp_Dir2d::gp_Dir2d (const gp_XY& XY) |
39 | { |
40 | Standard_Real X = XY.X(); |
41 | Standard_Real Y = XY.Y(); |
42 | Standard_Real D = sqrt(X * X + Y * Y); |
2d2b3d53 |
43 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm"); |
7fd59977 |
44 | coord.SetX(X / D); |
45 | coord.SetY(Y / D); |
46 | } |
47 | |
48 | inline gp_Dir2d::gp_Dir2d (const Standard_Real Xv, |
49 | const Standard_Real Yv) |
50 | { |
51 | Standard_Real D = sqrt (Xv * Xv + Yv * Yv); |
2d2b3d53 |
52 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm"); |
7fd59977 |
53 | coord.SetX(Xv / D); |
54 | coord.SetY(Yv / D); |
55 | } |
56 | |
57 | inline void gp_Dir2d::SetCoord (const Standard_Integer Index, |
58 | const Standard_Real Xi) |
59 | { |
60 | Standard_Real X = coord.X(); |
61 | Standard_Real Y = coord.Y(); |
2d2b3d53 |
62 | Standard_OutOfRange_Raise_if (Index < 1 || Index > 2, "gp_Dir2d::SetCoord() - index is out of range [1, 2]"); |
7fd59977 |
63 | if (Index == 1) X = Xi; |
64 | else Y = Xi; |
65 | Standard_Real D = sqrt (X * X + Y * Y); |
2d2b3d53 |
66 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d::SetCoord() - result vector has zero norm"); |
7fd59977 |
67 | coord.SetX(X / D); |
68 | coord.SetY(Y / D); |
69 | } |
70 | |
71 | inline void gp_Dir2d::SetCoord (const Standard_Real Xv, |
72 | const Standard_Real Yv) |
73 | { |
74 | Standard_Real D = sqrt (Xv * Xv + Yv * Yv); |
2d2b3d53 |
75 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d::SetCoord() - result vector has zero norm"); |
7fd59977 |
76 | coord.SetX(Xv / D); |
77 | coord.SetY(Yv / D); |
78 | } |
79 | |
80 | inline void gp_Dir2d::SetX (const Standard_Real X) |
81 | { |
82 | Standard_Real Y = coord.Y(); |
83 | Standard_Real D = sqrt (X * X + Y * Y); |
2d2b3d53 |
84 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d::SetX() - result vector has zero norm"); |
7fd59977 |
85 | coord.SetX(X / D); |
86 | coord.SetY(Y / D); |
87 | } |
88 | |
89 | inline void gp_Dir2d::SetY (const Standard_Real Y) |
90 | { |
91 | Standard_Real X = coord.X(); |
92 | Standard_Real D = sqrt (X * X + Y * Y); |
2d2b3d53 |
93 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d::SetY() - result vector has zero norm"); |
7fd59977 |
94 | coord.SetX(X / D); |
95 | coord.SetY(Y / D); |
96 | } |
97 | |
98 | inline void gp_Dir2d::SetXY (const gp_XY& XY) |
99 | { |
100 | Standard_Real X = XY.X(); |
101 | Standard_Real Y = XY.Y(); |
102 | Standard_Real D = sqrt(X * X + Y * Y); |
2d2b3d53 |
103 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "gp_Dir2d::SetZ() - result vector has zero norm"); |
7fd59977 |
104 | coord.SetX(X / D); |
105 | coord.SetY(Y / D); |
106 | } |
107 | |
108 | inline Standard_Real gp_Dir2d::Coord (const Standard_Integer Index) const |
109 | { return coord.Coord(Index); } |
110 | |
111 | inline void gp_Dir2d::Coord(Standard_Real& Xv, Standard_Real& Yv) const |
112 | { coord.Coord (Xv, Yv); } |
113 | |
114 | inline Standard_Real gp_Dir2d::X() const |
115 | { return coord.X() ; } |
116 | |
117 | inline Standard_Real gp_Dir2d::Y() const |
118 | { return coord.Y() ; } |
119 | |
120 | inline const gp_XY& gp_Dir2d::XY () const |
121 | { return coord; } |
122 | |
123 | inline Standard_Boolean gp_Dir2d::IsEqual |
124 | (const gp_Dir2d& Other, |
125 | const Standard_Real AngularTolerance) const |
126 | { |
127 | Standard_Real Ang = Angle(Other); |
128 | if (Ang < 0) Ang = - Ang; |
129 | return Ang <= AngularTolerance; |
130 | } |
131 | |
132 | inline Standard_Boolean gp_Dir2d::IsNormal |
133 | (const gp_Dir2d& Other, |
134 | const Standard_Real AngularTolerance) const |
135 | { |
136 | Standard_Real Ang = Angle(Other); |
137 | if (Ang < 0) Ang = - Ang; |
c6541a0c |
138 | Ang = M_PI / 2.0 - Ang; |
7fd59977 |
139 | if (Ang < 0) Ang = - Ang; |
140 | return Ang <= AngularTolerance; |
141 | } |
142 | |
143 | inline Standard_Boolean gp_Dir2d::IsOpposite |
144 | (const gp_Dir2d& Other, |
145 | const Standard_Real AngularTolerance) const |
146 | { |
147 | Standard_Real Ang = Angle(Other); |
148 | if (Ang < 0) Ang = - Ang; |
c6541a0c |
149 | return M_PI - Ang <= AngularTolerance; |
7fd59977 |
150 | } |
151 | |
152 | inline Standard_Boolean gp_Dir2d::IsParallel |
153 | (const gp_Dir2d& Other, |
154 | const Standard_Real AngularTolerance) const |
155 | { |
156 | Standard_Real Ang = Angle(Other); |
157 | if (Ang < 0) Ang = - Ang; |
c6541a0c |
158 | return Ang <= AngularTolerance || M_PI - Ang <= AngularTolerance; |
7fd59977 |
159 | } |
160 | |
161 | inline Standard_Real gp_Dir2d::Crossed (const gp_Dir2d& Right) const |
162 | { return coord.Crossed (Right.coord); } |
163 | |
164 | inline Standard_Real gp_Dir2d::Dot (const gp_Dir2d& Other) const |
165 | { return coord.Dot (Other.coord); } |
166 | |
167 | inline void gp_Dir2d::Reverse() |
168 | { coord.Reverse(); } |
169 | |
170 | inline gp_Dir2d gp_Dir2d::Reversed() const |
171 | { |
172 | gp_Dir2d V = *this; |
173 | V.coord.Reverse (); |
174 | return V; |
175 | } |
176 | |
177 | inline void gp_Dir2d::Rotate (const Standard_Real Ang) |
178 | { |
179 | gp_Trsf2d T; |
180 | T.SetRotation (gp_Pnt2d (0.0, 0.0), Ang); |
181 | coord.Multiply (T.HVectorialPart()); |
182 | } |
183 | |
184 | inline gp_Dir2d gp_Dir2d::Rotated (const Standard_Real Ang) const |
185 | { |
186 | gp_Dir2d V = *this; |
187 | V.Rotate (Ang); |
188 | return V; |
189 | } |
190 | |
191 | inline gp_Dir2d gp_Dir2d::Transformed (const gp_Trsf2d& T) const |
192 | { |
193 | gp_Dir2d V = *this; |
194 | V.Transform (T); |
195 | return V; |
196 | } |
197 | |