0024624: Lost word in license statement in source files
[occt.git] / src / gp / gp_Dir2d.lxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
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);
33   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
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);
43   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
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);
52   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
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();
62   Standard_OutOfRange_Raise_if (Index < 1 || Index > 2, " ");
63   if      (Index == 1) X = Xi;
64   else                 Y = Xi;
65   Standard_Real D = sqrt (X * X + Y * Y);
66   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
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);
75   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
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);
84   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
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);
93   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
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);
103   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
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;
138   Ang = M_PI / 2.0 - Ang;
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;
149   return M_PI - Ang <= AngularTolerance;
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;
158   return   Ang <= AngularTolerance || M_PI - Ang <= AngularTolerance;
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