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