1 // Created on: 1993-03-24
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Geom2d_VectorWithMagnitude_HeaderFile
18 #define _Geom2d_VectorWithMagnitude_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <Geom2d_Vector.hxx>
24 #include <Standard_Real.hxx>
25 class Standard_ConstructionError;
30 class Geom2d_Geometry;
33 class Geom2d_VectorWithMagnitude;
34 DEFINE_STANDARD_HANDLE(Geom2d_VectorWithMagnitude, Geom2d_Vector)
37 //! Defines a vector with magnitude.
38 //! A vector with magnitude can have a zero length.
39 class Geom2d_VectorWithMagnitude : public Geom2d_Vector
45 //! Creates a persistent copy of V.
46 Standard_EXPORT Geom2d_VectorWithMagnitude(const gp_Vec2d& V);
48 //! Creates a vector with two cartesian coordinates.
49 Standard_EXPORT Geom2d_VectorWithMagnitude(const Standard_Real X, const Standard_Real Y);
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);
56 //! Set <me> to X, Y coordinates.
57 Standard_EXPORT void SetCoord (const Standard_Real X, const Standard_Real Y);
59 Standard_EXPORT void SetVec2d (const gp_Vec2d& V);
61 //! Changes the X coordinate of <me>.
62 Standard_EXPORT void SetX (const Standard_Real X);
64 //! Changes the Y coordinate of <me>
65 Standard_EXPORT void SetY (const Standard_Real Y);
67 //! Returns the magnitude of <me>.
68 Standard_EXPORT Standard_Real Magnitude() const Standard_OVERRIDE;
70 //! Returns the square magnitude of <me>.
71 Standard_EXPORT Standard_Real SquareMagnitude() const Standard_OVERRIDE;
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)
82 //! Adds the vector Other to <me>.
83 Standard_NODISCARD Standard_EXPORT
84 Handle(Geom2d_VectorWithMagnitude) Added (const Handle(Geom2d_Vector)& Other) const;
85 Standard_NODISCARD Handle(Geom2d_VectorWithMagnitude) operator + (const Handle(Geom2d_Vector)& Other) const
91 //! Computes the cross product between <me> and Other
92 //! <me> ^ Other. A new vector is returned.
93 Standard_EXPORT Standard_Real Crossed (const Handle(Geom2d_Vector)& Other) const Standard_OVERRIDE;
94 Standard_Real operator ^ (const Handle(Geom2d_Vector)& Other) const
96 return Crossed(Other);
99 //! Divides <me> by a scalar.
100 Standard_EXPORT void Divide (const Standard_Real Scalar);
101 void operator /= (const Standard_Real Scalar)
107 //! Divides <me> by a scalar. A new vector is returned.
108 Standard_NODISCARD Standard_EXPORT Handle(Geom2d_VectorWithMagnitude) Divided (const Standard_Real Scalar) const;
109 Standard_NODISCARD Handle(Geom2d_VectorWithMagnitude) operator / (const Standard_Real Scalar) const
111 return Divided(Scalar);
115 //! Computes the product of the vector <me> by a scalar.
116 //! A new vector is returned.
118 //! -C++: alias operator *
119 //! Collision with same operator defined for the class Vector!
120 Standard_NODISCARD Standard_EXPORT Handle(Geom2d_VectorWithMagnitude) Multiplied (const Standard_Real Scalar) const;
123 //! Computes the product of the vector <me> by a scalar.
124 Standard_EXPORT void Multiply (const Standard_Real Scalar);
125 void operator *= (const Standard_Real Scalar)
132 //! Raised if the magnitude of the vector is lower or equal to
133 //! Resolution from package gp.
134 Standard_EXPORT void Normalize();
136 //! Returns a copy of <me> Normalized.
138 //! Raised if the magnitude of the vector is lower or equal to
139 //! Resolution from package gp.
140 Standard_NODISCARD Standard_EXPORT Handle(Geom2d_VectorWithMagnitude) Normalized() const;
142 //! Subtracts the Vector Other to <me>.
143 Standard_EXPORT void Subtract (const Handle(Geom2d_Vector)& Other);
144 void operator -= (const Handle(Geom2d_Vector)& Other)
150 //! Subtracts the vector Other to <me>. A new vector is returned.
151 Standard_NODISCARD Standard_EXPORT
152 Handle(Geom2d_VectorWithMagnitude) Subtracted (const Handle(Geom2d_Vector)& Other) const;
153 Standard_NODISCARD Handle(Geom2d_VectorWithMagnitude) operator - (const Handle(Geom2d_Vector)& Other) const
155 return Subtracted(Other);
158 //! Applies the transformation T to this vector.
159 Standard_EXPORT void Transform (const gp_Trsf2d& T) Standard_OVERRIDE;
161 //! Creates a new object which is a copy of this vector.
162 Standard_EXPORT Handle(Geom2d_Geometry) Copy() const Standard_OVERRIDE;
167 DEFINE_STANDARD_RTTIEXT(Geom2d_VectorWithMagnitude,Geom2d_Vector)
187 #endif // _Geom2d_VectorWithMagnitude_HeaderFile