bf2f24bdd1ee4bc5c7e2d1cc92180387f12137fe
[occt.git] / src / Geom2d / Geom2d_VectorWithMagnitude.hxx
1 // Created on: 1993-03-24
2 // Created by: JCV
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _Geom2d_VectorWithMagnitude_HeaderFile
18 #define _Geom2d_VectorWithMagnitude_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <Geom2d_Vector.hxx>
24 #include <Standard_Real.hxx>
25 class Standard_ConstructionError;
26 class gp_Vec2d;
27 class gp_Pnt2d;
28 class Geom2d_Vector;
29 class gp_Trsf2d;
30 class Geom2d_Geometry;
31
32
33 class Geom2d_VectorWithMagnitude;
34 DEFINE_STANDARD_HANDLE(Geom2d_VectorWithMagnitude, Geom2d_Vector)
35
36
37 //! Defines a vector with magnitude.
38 //! A vector with magnitude can have a zero length.
39 class Geom2d_VectorWithMagnitude : public Geom2d_Vector
40 {
41
42 public:
43
44   
45   //! Creates a persistent copy of V.
46   Standard_EXPORT Geom2d_VectorWithMagnitude(const gp_Vec2d& V);
47   
48   //! Creates a vector with two cartesian coordinates.
49   Standard_EXPORT Geom2d_VectorWithMagnitude(const Standard_Real X, const Standard_Real Y);
50   
51
52   //! Creates a vector from the point P1 to the point P2.
53   //! The magnitude of the vector is the distance between P1 and P2
54   Standard_EXPORT Geom2d_VectorWithMagnitude(const gp_Pnt2d& P1, const gp_Pnt2d& P2);
55   
56   //! Set <me> to X, Y coordinates.
57   Standard_EXPORT void SetCoord (const Standard_Real X, const Standard_Real Y);
58   
59   Standard_EXPORT void SetVec2d (const gp_Vec2d& V);
60   
61   //! Changes the X coordinate of <me>.
62   Standard_EXPORT void SetX (const Standard_Real X);
63   
64   //! Changes the Y coordinate of <me>
65   Standard_EXPORT void SetY (const Standard_Real Y);
66   
67   //! Returns the magnitude of <me>.
68   Standard_EXPORT Standard_Real Magnitude() const Standard_OVERRIDE;
69   
70   //! Returns the square magnitude of <me>.
71   Standard_EXPORT Standard_Real SquareMagnitude() const Standard_OVERRIDE;
72   
73
74   //! Adds the Vector Other to <me>.
75   Standard_EXPORT void Add (const Handle(Geom2d_Vector)& Other);
76 void operator += (const Handle(Geom2d_Vector)& Other)
77 {
78   Add(Other);
79 }
80   
81
82   //! Adds the vector Other to <me>.
83   Standard_EXPORT Handle(Geom2d_VectorWithMagnitude) Added (const Handle(Geom2d_Vector)& Other) const;
84 Handle(Geom2d_VectorWithMagnitude) operator + (const Handle(Geom2d_Vector)& Other) const
85 {
86   return Added(Other);
87 }
88   
89
90   //! Computes the cross product  between <me> and Other
91   //! <me> ^ Other. A new vector is returned.
92   Standard_EXPORT Standard_Real Crossed (const Handle(Geom2d_Vector)& Other) const Standard_OVERRIDE;
93 Standard_Real operator ^ (const Handle(Geom2d_Vector)& Other) const
94 {
95   return Crossed(Other);
96 }
97   
98   //! Divides <me> by a scalar.
99   Standard_EXPORT void Divide (const Standard_Real Scalar);
100 void operator /= (const Standard_Real Scalar)
101 {
102   Divide(Scalar);
103 }
104   
105
106   //! Divides <me> by a scalar. A new vector is returned.
107   Standard_EXPORT Handle(Geom2d_VectorWithMagnitude) Divided (const Standard_Real Scalar) const;
108 Handle(Geom2d_VectorWithMagnitude) operator / (const Standard_Real Scalar) const
109 {
110   return Divided(Scalar);
111 }
112   
113
114   //! Computes the product of the vector <me> by a scalar.
115   //! A new vector is returned.
116   //!
117   //! -C++: alias operator *
118   //! Collision with same operator defined for the class Vector!
119   Standard_EXPORT Handle(Geom2d_VectorWithMagnitude) Multiplied (const Standard_Real Scalar) const;
120   
121
122   //! Computes the product of the vector <me> by a scalar.
123   Standard_EXPORT void Multiply (const Standard_Real Scalar);
124 void operator *= (const Standard_Real Scalar)
125 {
126   Multiply(Scalar);
127 }
128   
129   //! Normalizes <me>.
130   //!
131   //! Raised if the magnitude of the vector is lower or equal to
132   //! Resolution from package gp.
133   Standard_EXPORT void Normalize();
134   
135   //! Returns a copy of <me> Normalized.
136   //!
137   //! Raised if the magnitude of the vector is lower or equal to
138   //! Resolution from package gp.
139   Standard_EXPORT Handle(Geom2d_VectorWithMagnitude) Normalized() const;
140   
141   //! Subtracts the Vector Other to <me>.
142   Standard_EXPORT void Subtract (const Handle(Geom2d_Vector)& Other);
143 void operator -= (const Handle(Geom2d_Vector)& Other)
144 {
145   Subtract(Other);
146 }
147   
148
149   //! Subtracts the vector Other to <me>. A new vector is returned.
150   Standard_EXPORT Handle(Geom2d_VectorWithMagnitude) Subtracted (const Handle(Geom2d_Vector)& Other) const;
151 Handle(Geom2d_VectorWithMagnitude) operator - (const Handle(Geom2d_Vector)& Other) const
152 {
153   return Subtracted(Other);
154 }
155   
156   //! Applies the transformation T to this vector.
157   Standard_EXPORT void Transform (const gp_Trsf2d& T) Standard_OVERRIDE;
158   
159   //! Creates a new object which is a copy of this vector.
160   Standard_EXPORT Handle(Geom2d_Geometry) Copy() const Standard_OVERRIDE;
161
162
163
164
165   DEFINE_STANDARD_RTTIEXT(Geom2d_VectorWithMagnitude,Geom2d_Vector)
166
167 protected:
168
169
170
171
172 private:
173
174
175
176
177 };
178
179
180
181
182
183
184
185 #endif // _Geom2d_VectorWithMagnitude_HeaderFile