0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[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
d0fcf95a 73(const gp_Vec2d& theOther,
74 const Standard_Real theAngularTolerance) const
7fd59977 75{
d0fcf95a 76 const Standard_Real anAng = Abs(M_PI_2 - Abs(Angle(theOther)));
77 return !(anAng > theAngularTolerance);
7fd59977 78}
79
80inline 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;
c6541a0c 86 return M_PI - Ang <= AngularTolerance;
7fd59977 87}
88
89inline 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;
c6541a0c 95 return Ang <= AngularTolerance || M_PI - Ang <= AngularTolerance;
7fd59977 96}
97
98inline Standard_Real gp_Vec2d::Magnitude() const
99{ return coord.Modulus(); }
100
101inline Standard_Real gp_Vec2d::SquareMagnitude() const
102{ return coord.SquareModulus(); }
103
104inline void gp_Vec2d::Add (const gp_Vec2d& Other)
105{ coord.Add (Other.coord); }
106
107inline 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
114inline Standard_Real gp_Vec2d::Crossed (const gp_Vec2d& Right) const
115{ return coord.Crossed (Right.coord); }
116
117inline Standard_Real gp_Vec2d::CrossMagnitude (const gp_Vec2d& Right) const
118{ return coord.CrossMagnitude (Right.coord); }
119
120inline Standard_Real gp_Vec2d::CrossSquareMagnitude
121(const gp_Vec2d& Right) const
122{ return coord.CrossSquareMagnitude (Right.coord); }
123
124inline void gp_Vec2d::Divide (const Standard_Real Scalar)
125{ coord.Divide (Scalar); }
126
127inline 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
134inline Standard_Real gp_Vec2d::Dot (const gp_Vec2d& Other) const
135{ return coord.Dot (Other.coord); }
136
137inline void gp_Vec2d::Multiply (const Standard_Real Scalar)
138{ coord.Multiply (Scalar); }
139
140inline 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
147inline void gp_Vec2d::Normalize()
148{
149 Standard_Real D = coord.Modulus();
2d2b3d53 150 Standard_ConstructionError_Raise_if (D <= gp::Resolution(),
151 "gp_Vec2d::Normalize() - vector has zero norm");
7fd59977 152 coord.Divide (D);
153}
154
155inline gp_Vec2d gp_Vec2d::Normalized() const
156{
157 Standard_Real D = coord.Modulus();
2d2b3d53 158 Standard_ConstructionError_Raise_if (D <= gp::Resolution(),
159 "gp_Vec2d::Normalized() - vector has zero norm");
7fd59977 160 gp_Vec2d V = *this;
161 V.coord.Divide (D);
162 return V;
163}
164
165inline void gp_Vec2d::Reverse()
166{ coord.Reverse(); }
167
168inline gp_Vec2d gp_Vec2d::Reversed() const
169{
170 gp_Vec2d V = *this;
171 V.coord.Reverse();
172 return V;
173}
174
175inline void gp_Vec2d::Subtract (const gp_Vec2d& Right)
176{ coord.Subtract (Right.coord); }
177
178inline gp_Vec2d gp_Vec2d::Subtracted (const gp_Vec2d& Right) const
179{
180 gp_Vec2d V = *this;
181 V.coord.Subtract (Right.coord);
182 return V;
183}
184
185inline void gp_Vec2d::SetLinearForm (const Standard_Real L,
186 const gp_Vec2d& Left,
187 const Standard_Real R,
188 const gp_Vec2d& Right)
189{ coord.SetLinearForm (L, Left.coord, R, Right.coord); }
190
191inline void gp_Vec2d::SetLinearForm (const Standard_Real L,
192 const gp_Vec2d& Left,
193 const gp_Vec2d& Right)
194{ coord.SetLinearForm (L, Left.coord, Right.coord); }
195
196inline void gp_Vec2d::SetLinearForm (const gp_Vec2d& Left,
197 const gp_Vec2d& Right)
198{ coord.SetLinearForm (Left.coord, Right.coord); }
199
200inline void gp_Vec2d::SetLinearForm (const Standard_Real A1,
201 const gp_Vec2d& V1,
202 const Standard_Real A2,
203 const gp_Vec2d& V2,
204 const gp_Vec2d& V3)
205{ coord.SetLinearForm (A1, V1.coord, A2, V2.coord, V3.coord); }
206
207inline void gp_Vec2d::Rotate (const Standard_Real Ang)
208{
209 gp_Trsf2d T;
210 T.SetRotation (gp_Pnt2d (0.0, 0.0), Ang);
211 coord.Multiply (T.VectorialPart ());
212}
213
214inline gp_Vec2d gp_Vec2d::Rotated (const Standard_Real Ang) const
215{
216 gp_Vec2d V = *this;
217 V.Rotate (Ang);
218 return V;
219}
220
221inline void gp_Vec2d::Scale (const Standard_Real S)
222{ coord.Multiply (S); }
223
224inline gp_Vec2d gp_Vec2d::Scaled (const Standard_Real S) const
225{
226 gp_Vec2d V = *this;
227 V.coord.Multiply (S);
228 return V;
229}
230
231inline gp_Vec2d gp_Vec2d::Transformed (const gp_Trsf2d& T) const
232{
233 gp_Vec2d V = *this;
234 V.Transform(T);
235 return V;
236}
237
238inline gp_Vec2d operator* (const Standard_Real Scalar,
239 const gp_Vec2d& V)
240{ return V.Multiplied(Scalar); }
241
32ca7a51 242inline gp_Vec2d gp_Vec2d::GetNormal() const
d0fcf95a 243{
32ca7a51 244 return gp_Vec2d(this->Y(), (-1)*this->X());
d0fcf95a 245}
32ca7a51 246