File indexing completed on 2025-12-16 10:21:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _gp_Pnt2d_HeaderFile
0016 #define _gp_Pnt2d_HeaderFile
0017
0018 #include <Standard.hxx>
0019 #include <Standard_DefineAlloc.hxx>
0020 #include <Standard_Handle.hxx>
0021
0022 #include <gp_XY.hxx>
0023 #include <Standard_Real.hxx>
0024 #include <Standard_Boolean.hxx>
0025
0026 class gp_Ax2d;
0027 class gp_Trsf2d;
0028 class gp_Vec2d;
0029
0030
0031 class gp_Pnt2d
0032 {
0033 public:
0034
0035 DEFINE_STANDARD_ALLOC
0036
0037
0038 gp_Pnt2d() {}
0039
0040
0041 gp_Pnt2d (const gp_XY& theCoord)
0042 : coord (theCoord)
0043 {}
0044
0045
0046 gp_Pnt2d (const Standard_Real theXp, const Standard_Real theYp)
0047 : coord (theXp, theYp)
0048 {}
0049
0050
0051
0052
0053
0054 void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi) { coord.SetCoord (theIndex, theXi); }
0055
0056
0057 void SetCoord (const Standard_Real theXp, const Standard_Real theYp) { coord.SetCoord (theXp, theYp); }
0058
0059
0060 void SetX (const Standard_Real theX) { coord.SetX (theX); }
0061
0062
0063 void SetY (const Standard_Real theY) { coord.SetY (theY); }
0064
0065
0066 void SetXY (const gp_XY& theCoord) { coord = theCoord; }
0067
0068
0069
0070
0071
0072 Standard_Real Coord (const Standard_Integer theIndex) const { return coord.Coord (theIndex); }
0073
0074
0075 void Coord (Standard_Real& theXp, Standard_Real& theYp) const { coord.Coord (theXp, theYp); }
0076
0077
0078 Standard_Real X() const { return coord.X(); }
0079
0080
0081 Standard_Real Y() const { return coord.Y(); }
0082
0083
0084 const gp_XY& XY() const { return coord; }
0085
0086
0087 const gp_XY& Coord() const { return coord; }
0088
0089
0090
0091 gp_XY& ChangeCoord() { return coord; }
0092
0093
0094
0095
0096 Standard_Boolean IsEqual (const gp_Pnt2d& theOther, const Standard_Real theLinearTolerance) const
0097 {
0098 return Distance (theOther) <= theLinearTolerance;
0099 }
0100
0101
0102 Standard_Real Distance (const gp_Pnt2d& theOther) const;
0103
0104
0105 Standard_Real SquareDistance (const gp_Pnt2d& theOther) const;
0106
0107
0108
0109
0110 Standard_EXPORT void Mirror (const gp_Pnt2d& theP);
0111
0112
0113
0114 Standard_NODISCARD Standard_EXPORT gp_Pnt2d Mirrored (const gp_Pnt2d& theP) const;
0115
0116 Standard_EXPORT void Mirror (const gp_Ax2d& theA);
0117
0118 Standard_NODISCARD Standard_EXPORT gp_Pnt2d Mirrored (const gp_Ax2d& theA) const;
0119
0120
0121
0122 void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng);
0123
0124 Standard_NODISCARD gp_Pnt2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
0125 {
0126 gp_Pnt2d aPres = *this;
0127 aPres.Rotate (theP, theAng);
0128 return aPres;
0129 }
0130
0131
0132 void Scale (const gp_Pnt2d& theP, const Standard_Real theS);
0133
0134 Standard_NODISCARD gp_Pnt2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
0135 {
0136 gp_Pnt2d aPres = *this;
0137 aPres.Scale (theP, theS);
0138 return aPres;
0139 }
0140
0141
0142 Standard_EXPORT void Transform (const gp_Trsf2d& theT);
0143
0144 Standard_NODISCARD gp_Pnt2d Transformed (const gp_Trsf2d& theT) const
0145 {
0146 gp_Pnt2d aPres = *this;
0147 aPres.Transform (theT);
0148 return aPres;
0149 }
0150
0151
0152
0153 void Translate (const gp_Vec2d& theV);
0154
0155 Standard_NODISCARD gp_Pnt2d Translated (const gp_Vec2d& theV) const;
0156
0157
0158 void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2)
0159 {
0160 coord.Add (theP2.coord);
0161 coord.Subtract (theP1.coord);
0162 }
0163
0164 Standard_NODISCARD gp_Pnt2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
0165 {
0166 gp_Pnt2d aP = *this;
0167 aP.Translate (theP1, theP2);
0168 return aP;
0169 }
0170
0171
0172 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0173
0174 private:
0175
0176 gp_XY coord;
0177
0178 };
0179
0180 #include <gp_Vec2d.hxx>
0181 #include <gp_Trsf2d.hxx>
0182
0183
0184
0185
0186
0187 inline Standard_Real gp_Pnt2d::Distance (const gp_Pnt2d& theOther) const
0188 {
0189 const gp_XY& aXY = theOther.coord;
0190 Standard_Real aX = coord.X() - aXY.X();
0191 Standard_Real aY = coord.Y() - aXY.Y();
0192 return sqrt (aX * aX + aY * aY);
0193 }
0194
0195
0196
0197
0198
0199 inline Standard_Real gp_Pnt2d::SquareDistance (const gp_Pnt2d& theOther) const
0200 {
0201 const gp_XY& aXY = theOther.coord;
0202 Standard_Real aX = coord.X() - aXY.X();
0203 Standard_Real aY = coord.Y() - aXY.Y();
0204 return (aX * aX + aY * aY);
0205 }
0206
0207
0208
0209
0210
0211 inline void gp_Pnt2d::Rotate (const gp_Pnt2d& theP, const Standard_Real theAng)
0212 {
0213 gp_Trsf2d aT;
0214 aT.SetRotation (theP, theAng);
0215 aT.Transforms (coord);
0216 }
0217
0218
0219
0220
0221
0222 inline void gp_Pnt2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS)
0223 {
0224 gp_XY aXY = theP.coord;
0225 aXY.Multiply (1.0 - theS);
0226 coord.Multiply (theS);
0227 coord.Add (aXY);
0228 }
0229
0230
0231
0232
0233
0234 inline void gp_Pnt2d::Translate(const gp_Vec2d& theV)
0235 {
0236 coord.Add (theV.XY());
0237 }
0238
0239
0240
0241
0242
0243 inline gp_Pnt2d gp_Pnt2d::Translated (const gp_Vec2d& theV) const
0244 {
0245 gp_Pnt2d aP = *this;
0246 aP.coord.Add (theV.XY());
0247 return aP;
0248 }
0249
0250 #endif