0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / gp / gp_Vec2d.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 modifs suite a la deuxieme revue de projet
16 // et introduction des classes XY, Mat2d + nouveau operateurs
17
18 #include <gp_Dir2d.hxx>
19 #include <gp_Trsf2d.hxx>
20 #include <gp_Pnt2d.hxx>
21
22 inline gp_Vec2d::gp_Vec2d()
23 {}
24
25 inline gp_Vec2d::gp_Vec2d (const gp_Dir2d& V)
26 { coord = V.XY(); }
27
28 inline gp_Vec2d::gp_Vec2d (const gp_XY& Coord) : coord(Coord)
29 {}
30
31 inline gp_Vec2d::gp_Vec2d (const Standard_Real Xv,
32                            const Standard_Real Yv) : coord (Xv, Yv)
33 { }
34
35 inline gp_Vec2d::gp_Vec2d (const gp_Pnt2d& P1,
36                            const gp_Pnt2d& P2)
37 { coord = P2.XY().Subtracted (P1.XY()); }
38
39 inline void gp_Vec2d::SetCoord (const Standard_Integer Index,
40                                 const Standard_Real Xi)
41 { coord.SetCoord (Index, Xi); }
42
43 inline void gp_Vec2d::SetCoord (const Standard_Real Xv,
44                                 const Standard_Real Yv)
45 { coord.SetCoord (Xv, Yv); }
46
47 inline void gp_Vec2d::SetX (const Standard_Real X)
48 { coord.SetX (X); }
49
50 inline void gp_Vec2d::SetY (const Standard_Real Y)
51 { coord.SetY (Y); }
52
53 inline void gp_Vec2d::SetXY (const gp_XY& Coord)
54 { coord = Coord; }
55
56 inline Standard_Real gp_Vec2d::Coord (const Standard_Integer Index) const
57 { return coord.Coord(Index); }
58
59 inline void gp_Vec2d::Coord(Standard_Real& Xv,
60                             Standard_Real& Yv) const
61 { coord.Coord(Xv, Yv); }
62
63 inline Standard_Real gp_Vec2d::X() const
64 { return coord.X(); }
65      
66 inline Standard_Real gp_Vec2d::Y() const
67 { return coord.Y(); }
68
69 inline  const gp_XY& gp_Vec2d::XY () const
70 { return coord; }
71
72 inline Standard_Boolean gp_Vec2d::IsNormal
73 (const gp_Vec2d& theOther, 
74  const Standard_Real theAngularTolerance) const
75 {
76   const Standard_Real anAng = Abs(M_PI_2 - Abs(Angle(theOther)));
77   return !(anAng > theAngularTolerance);
78 }    
79
80 inline Standard_Boolean gp_Vec2d::IsOpposite
81 (const gp_Vec2d& Other,
82  const Standard_Real AngularTolerance) const
83 {
84   Standard_Real Ang = Angle(Other);
85   if (Ang < 0) Ang = - Ang;
86   return M_PI - Ang <= AngularTolerance;
87 }    
88
89 inline Standard_Boolean gp_Vec2d::IsParallel
90 (const gp_Vec2d& Other,
91  const Standard_Real AngularTolerance) const
92 {
93   Standard_Real Ang = Angle(Other);
94   if (Ang < 0) Ang = - Ang;
95   return   Ang <= AngularTolerance || M_PI - Ang <= AngularTolerance;
96 }    
97
98 inline Standard_Real gp_Vec2d::Magnitude() const
99 { return coord.Modulus(); }
100
101 inline Standard_Real gp_Vec2d::SquareMagnitude() const
102 { return coord.SquareModulus(); }
103
104 inline void gp_Vec2d::Add (const gp_Vec2d& Other)
105 { coord.Add (Other.coord); }
106
107 inline gp_Vec2d gp_Vec2d::Added (const gp_Vec2d& Other) const
108 {
109   gp_Vec2d V = *this;
110   V.coord.Add (Other.coord);
111   return V;
112 }
113
114 inline Standard_Real gp_Vec2d::Crossed (const gp_Vec2d& Right) const
115 { return coord.Crossed (Right.coord); }
116
117 inline Standard_Real gp_Vec2d::CrossMagnitude (const gp_Vec2d& Right) const
118 { return coord.CrossMagnitude (Right.coord); }
119
120 inline Standard_Real gp_Vec2d::CrossSquareMagnitude
121 (const gp_Vec2d& Right) const
122 { return coord.CrossSquareMagnitude (Right.coord); }
123
124 inline void gp_Vec2d::Divide (const Standard_Real Scalar)
125 { coord.Divide (Scalar); }
126
127 inline gp_Vec2d gp_Vec2d::Divided (const Standard_Real Scalar) const
128 {
129   gp_Vec2d V = *this;
130   V.coord.Divide(Scalar);
131   return V;
132 }
133
134 inline Standard_Real gp_Vec2d::Dot (const gp_Vec2d& Other) const
135 { return coord.Dot (Other.coord); }
136
137 inline void gp_Vec2d::Multiply (const Standard_Real Scalar)
138 { coord.Multiply (Scalar); }
139
140 inline gp_Vec2d gp_Vec2d::Multiplied (const Standard_Real Scalar) const
141 {
142   gp_Vec2d V = *this;
143   V.coord.Multiply(Scalar);
144   return V;
145 }
146
147 inline void gp_Vec2d::Normalize()
148
149   Standard_Real D = coord.Modulus();
150   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
151   coord.Divide (D);
152 }
153
154 inline gp_Vec2d gp_Vec2d::Normalized() const
155
156   Standard_Real D = coord.Modulus();
157   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
158   gp_Vec2d V = *this;
159   V.coord.Divide (D);
160   return V; 
161 }
162
163 inline void gp_Vec2d::Reverse()
164 { coord.Reverse(); }
165
166 inline gp_Vec2d gp_Vec2d::Reversed() const
167 {
168   gp_Vec2d V = *this;
169   V.coord.Reverse();
170   return V;
171 }
172
173 inline void gp_Vec2d::Subtract (const gp_Vec2d& Right)
174 { coord.Subtract (Right.coord); }
175
176 inline gp_Vec2d gp_Vec2d::Subtracted (const gp_Vec2d& Right) const
177 {
178   gp_Vec2d V = *this;
179   V.coord.Subtract (Right.coord);
180   return V;
181 }
182
183 inline void gp_Vec2d::SetLinearForm (const Standard_Real L, 
184                                      const gp_Vec2d& Left,
185                                      const Standard_Real R,
186                                      const gp_Vec2d& Right)
187 { coord.SetLinearForm (L, Left.coord, R, Right.coord); }
188
189 inline void gp_Vec2d::SetLinearForm (const Standard_Real L, 
190                                      const gp_Vec2d& Left,
191                                      const gp_Vec2d& Right)
192 { coord.SetLinearForm (L, Left.coord, Right.coord); }
193
194 inline void gp_Vec2d::SetLinearForm (const gp_Vec2d& Left,
195                                      const gp_Vec2d& Right)
196 { coord.SetLinearForm (Left.coord,  Right.coord); }
197
198 inline void gp_Vec2d::SetLinearForm (const Standard_Real A1, 
199                                      const gp_Vec2d& V1,
200                                      const Standard_Real A2, 
201                                      const gp_Vec2d& V2, 
202                                      const gp_Vec2d& V3)
203 { coord.SetLinearForm (A1, V1.coord, A2, V2.coord, V3.coord); }
204
205 inline void gp_Vec2d::Rotate (const Standard_Real Ang)
206 {
207   gp_Trsf2d T;
208   T.SetRotation  (gp_Pnt2d (0.0, 0.0), Ang);
209   coord.Multiply (T.VectorialPart ());
210 }
211
212 inline gp_Vec2d gp_Vec2d::Rotated (const Standard_Real Ang) const
213 {
214   gp_Vec2d V = *this;
215   V.Rotate (Ang);
216   return V;
217 }
218
219 inline void gp_Vec2d::Scale (const Standard_Real S)
220 { coord.Multiply (S); }
221
222 inline gp_Vec2d gp_Vec2d::Scaled (const Standard_Real S) const
223 {
224   gp_Vec2d V = *this;
225   V.coord.Multiply (S);
226   return V;
227 }
228
229 inline gp_Vec2d gp_Vec2d::Transformed (const gp_Trsf2d& T) const
230 {
231   gp_Vec2d V = *this;
232   V.Transform(T);
233   return V;
234
235
236 inline gp_Vec2d operator* (const Standard_Real Scalar,
237                            const gp_Vec2d& V)
238 { return V.Multiplied(Scalar); }
239
240 inline gp_Vec2d gp_Vec2d::GetNormal() const
241 {
242   return gp_Vec2d(this->Y(), (-1)*this->X());
243 }
244