0032137: Coding Rules - merge redundant .lxx files into header files within Package gp
[occt.git] / src / gp / gp_Pnt2d.hxx
CommitLineData
42cf5bc1 1// Copyright (c) 1991-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#ifndef _gp_Pnt2d_HeaderFile
16#define _gp_Pnt2d_HeaderFile
17
18#include <Standard.hxx>
19#include <Standard_DefineAlloc.hxx>
20#include <Standard_Handle.hxx>
21
22#include <gp_XY.hxx>
23#include <Standard_Real.hxx>
24#include <Standard_Integer.hxx>
25#include <Standard_Boolean.hxx>
d5477f8c 26
42cf5bc1 27class Standard_OutOfRange;
28class gp_XY;
29class gp_Ax2d;
30class gp_Trsf2d;
31class gp_Vec2d;
32
42cf5bc1 33//! Defines a non-persistent 2D cartesian point.
34class gp_Pnt2d
35{
36public:
37
38 DEFINE_STANDARD_ALLOC
39
42cf5bc1 40 //! Creates a point with zero coordinates.
d5477f8c 41 gp_Pnt2d() {}
42
42cf5bc1 43 //! Creates a point with a doublet of coordinates.
d5477f8c 44 gp_Pnt2d (const gp_XY& theCoord)
45 : coord (theCoord)
46 {}
47
48 //! Creates a point with its 2 cartesian's coordinates : theXp, theYp.
49 gp_Pnt2d (const Standard_Real theXp, const Standard_Real theYp)
50 : coord (theXp, theYp)
51 {}
52
53 //! Assigns the value Xi to the coordinate that corresponds to theIndex:
54 //! theIndex = 1 => X is modified
55 //! theIndex = 2 => Y is modified
56 //! Raises OutOfRange if theIndex != {1, 2}.
57 void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi) { coord.SetCoord (theIndex, theXi); }
58
59 //! For this point, assigns the values theXp and theYp to its two coordinates
60 void SetCoord (const Standard_Real theXp, const Standard_Real theYp) { coord.SetCoord (theXp, theYp); }
61
42cf5bc1 62 //! Assigns the given value to the X coordinate of this point.
d5477f8c 63 void SetX (const Standard_Real theX) { coord.SetX (theX); }
64
42cf5bc1 65 //! Assigns the given value to the Y coordinate of this point.
d5477f8c 66 void SetY (const Standard_Real theY) { coord.SetY (theY); }
67
42cf5bc1 68 //! Assigns the two coordinates of Coord to this point.
d5477f8c 69 void SetXY (const gp_XY& theCoord) { coord = theCoord; }
70
71 //! Returns the coordinate of range theIndex :
72 //! theIndex = 1 => X is returned
73 //! theIndex = 2 => Y is returned
74 //! Raises OutOfRange if theIndex != {1, 2}.
75 Standard_Real Coord (const Standard_Integer theIndex) const { return coord.Coord (theIndex); }
76
42cf5bc1 77 //! For this point returns its two coordinates as a number pair.
d5477f8c 78 void Coord (Standard_Real& theXp, Standard_Real& theYp) const { coord.Coord (theXp, theYp); }
79
42cf5bc1 80 //! For this point, returns its X coordinate.
d5477f8c 81 Standard_Real X() const { return coord.X(); }
82
42cf5bc1 83 //! For this point, returns its Y coordinate.
d5477f8c 84 Standard_Real Y() const { return coord.Y(); }
85
42cf5bc1 86 //! For this point, returns its two coordinates as a number pair.
d5477f8c 87 const gp_XY& XY() const { return coord; }
88
42cf5bc1 89 //! For this point, returns its two coordinates as a number pair.
d5477f8c 90 const gp_XY& Coord() const { return coord; }
42cf5bc1 91
92 //! Returns the coordinates of this point.
93 //! Note: This syntax allows direct modification of the returned value.
d5477f8c 94 gp_XY& ChangeCoord() { return coord; }
95
42cf5bc1 96 //! Comparison
97 //! Returns True if the distance between the two
d5477f8c 98 //! points is lower or equal to theLinearTolerance.
99 Standard_Boolean IsEqual (const gp_Pnt2d& theOther, const Standard_Real theLinearTolerance) const
100 {
101 return Distance (theOther) <= theLinearTolerance;
102 }
103
42cf5bc1 104 //! Computes the distance between two points.
d5477f8c 105 Standard_Real Distance (const gp_Pnt2d& theOther) const;
106
42cf5bc1 107 //! Computes the square distance between two points.
d5477f8c 108 Standard_Real SquareDistance (const gp_Pnt2d& theOther) const;
42cf5bc1 109
110 //! Performs the symmetrical transformation of a point
d5477f8c 111 //! with respect to the point theP which is the center of
42cf5bc1 112 //! the symmetry.
d5477f8c 113 Standard_EXPORT void Mirror (const gp_Pnt2d& theP);
42cf5bc1 114
115 //! Performs the symmetrical transformation of a point
116 //! with respect to an axis placement which is the axis
d5477f8c 117 Standard_NODISCARD Standard_EXPORT gp_Pnt2d Mirrored (const gp_Pnt2d& theP) const;
42cf5bc1 118
d5477f8c 119 Standard_EXPORT void Mirror (const gp_Ax2d& theA);
42cf5bc1 120
d5477f8c 121 Standard_NODISCARD Standard_EXPORT gp_Pnt2d Mirrored (const gp_Ax2d& theA) const;
42cf5bc1 122
d5477f8c 123 //! Rotates a point. theA1 is the axis of the rotation.
124 //! Ang is the angular value of the rotation in radians.
125 void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng);
126
127 Standard_NODISCARD gp_Pnt2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
128 {
129 gp_Pnt2d aPres = *this;
130 aPres.Rotate (theP, theAng);
131 return aPres;
132 }
133
134 //! Scales a point. theS is the scaling value.
135 void Scale (const gp_Pnt2d& theP, const Standard_Real theS);
136
137 Standard_NODISCARD gp_Pnt2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
138 {
139 gp_Pnt2d aPres = *this;
140 aPres.Scale (theP, theS);
141 return aPres;
142 }
143
144 //! Transforms a point with the transformation theT.
145 Standard_EXPORT void Transform (const gp_Trsf2d& theT);
146
147 Standard_NODISCARD gp_Pnt2d Transformed (const gp_Trsf2d& theT) const
148 {
149 gp_Pnt2d aPres = *this;
150 aPres.Transform (theT);
151 return aPres;
152 }
153
154 //! Translates a point in the direction of the vector theV.
155 //! The magnitude of the translation is the vector's magnitude.
156 void Translate (const gp_Vec2d& theV);
42cf5bc1 157
d5477f8c 158 Standard_NODISCARD gp_Pnt2d Translated (const gp_Vec2d& theV) const;
42cf5bc1 159
d5477f8c 160 //! Translates a point from the point theP1 to the point theP2.
161 void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2)
162 {
163 coord.Add (theP2.coord);
164 coord.Subtract (theP1.coord);
165 }
42cf5bc1 166
d5477f8c 167 Standard_NODISCARD gp_Pnt2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
168 {
169 gp_Pnt2d aP = *this;
170 aP.Translate (theP1, theP2);
171 return aP;
172 }
42cf5bc1 173
d5477f8c 174 //! Dumps the content of me into the stream
175 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
42cf5bc1 176
177private:
178
42cf5bc1 179 gp_XY coord;
180
42cf5bc1 181};
182
d5477f8c 183#include <gp_Vec2d.hxx>
184#include <gp_Ax2d.hxx>
185#include <gp_Trsf2d.hxx>
42cf5bc1 186
d5477f8c 187//=======================================================================
188//function : Distance
189// purpose :
190//=======================================================================
191inline Standard_Real gp_Pnt2d::Distance (const gp_Pnt2d& theOther) const
192{
193 const gp_XY& aXY = theOther.coord;
194 Standard_Real aX = coord.X() - aXY.X();
195 Standard_Real aY = coord.Y() - aXY.Y();
196 return sqrt (aX * aX + aY * aY);
197}
198
199//=======================================================================
200//function : SquareDistance
201// purpose :
202//=======================================================================
203inline Standard_Real gp_Pnt2d::SquareDistance (const gp_Pnt2d& theOther) const
204{
205 const gp_XY& aXY = theOther.coord;
206 Standard_Real aX = coord.X() - aXY.X();
207 Standard_Real aY = coord.Y() - aXY.Y();
208 return (aX * aX + aY * aY);
209}
210
211//=======================================================================
212//function : Rotate
213// purpose :
214//=======================================================================
215inline void gp_Pnt2d::Rotate (const gp_Pnt2d& theP, const Standard_Real theAng)
216{
217 gp_Trsf2d aT;
218 aT.SetRotation (theP, theAng);
219 aT.Transforms (coord);
220}
221
222//=======================================================================
223//function : Scale
224// purpose :
225//=======================================================================
226inline void gp_Pnt2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS)
227{
228 gp_XY aXY = theP.coord;
229 aXY.Multiply (1.0 - theS);
230 coord.Multiply (theS);
231 coord.Add (aXY);
232}
233
234//=======================================================================
235//function : Translate
236// purpose :
237//=======================================================================
238inline void gp_Pnt2d::Translate(const gp_Vec2d& theV)
239{
240 coord.Add (theV.XY());
241}
242
243//=======================================================================
244//function : Translated
245// purpose :
246//=======================================================================
247inline gp_Pnt2d gp_Pnt2d::Translated (const gp_Vec2d& theV) const
248{
249 gp_Pnt2d aP = *this;
250 aP.coord.Add (theV.XY());
251 return aP;
252}
42cf5bc1 253
254#endif // _gp_Pnt2d_HeaderFile