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_Pnt_HeaderFile
0016 #define _gp_Pnt_HeaderFile
0017
0018 #include <Standard.hxx>
0019 #include <Standard_DefineAlloc.hxx>
0020 #include <Standard_Handle.hxx>
0021 #include <gp_XYZ.hxx>
0022 #include <Standard_Real.hxx>
0023 #include <Standard_Boolean.hxx>
0024
0025 class gp_Ax1;
0026 class gp_Ax2;
0027 class gp_Trsf;
0028 class gp_Vec;
0029
0030
0031 class gp_Pnt
0032 {
0033 public:
0034
0035 DEFINE_STANDARD_ALLOC
0036
0037
0038 gp_Pnt() {}
0039
0040
0041 gp_Pnt (const gp_XYZ& theCoord)
0042 : coord (theCoord)
0043 {}
0044
0045
0046 gp_Pnt (const Standard_Real theXp, const Standard_Real theYp, const Standard_Real theZp)
0047 : coord (theXp, theYp, theZp)
0048 {}
0049
0050
0051
0052
0053
0054
0055 void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi)
0056 {
0057 coord.SetCoord (theIndex, theXi);
0058 }
0059
0060
0061 void SetCoord (const Standard_Real theXp, const Standard_Real theYp, const Standard_Real theZp)
0062 {
0063 coord.SetCoord (theXp, theYp, theZp);
0064 }
0065
0066
0067 void SetX (const Standard_Real theX) { coord.SetX (theX); }
0068
0069
0070 void SetY (const Standard_Real theY) { coord.SetY (theY); }
0071
0072
0073 void SetZ (const Standard_Real theZ) { coord.SetZ (theZ); }
0074
0075
0076 void SetXYZ (const gp_XYZ& theCoord) { coord = theCoord; }
0077
0078
0079
0080
0081
0082
0083
0084 Standard_Real Coord (const Standard_Integer theIndex) const { return coord.Coord (theIndex); }
0085
0086
0087 void Coord (Standard_Real& theXp, Standard_Real& theYp, Standard_Real& theZp) const
0088 {
0089 coord.Coord (theXp, theYp, theZp);
0090 }
0091
0092
0093 Standard_Real X() const { return coord.X(); }
0094
0095
0096 Standard_Real Y() const { return coord.Y(); }
0097
0098
0099 Standard_Real Z() const { return coord.Z(); }
0100
0101
0102 const gp_XYZ& XYZ() const { return coord; }
0103
0104
0105 const gp_XYZ& Coord() const { return coord; }
0106
0107
0108
0109 gp_XYZ& ChangeCoord() { return coord; }
0110
0111
0112
0113 void BaryCenter (const Standard_Real theAlpha, const gp_Pnt& theP, const Standard_Real theBeta)
0114 {
0115 coord.SetLinearForm (theAlpha, coord, theBeta, theP.coord);
0116 coord.Divide (theAlpha + theBeta);
0117 }
0118
0119
0120
0121
0122 Standard_Boolean IsEqual (const gp_Pnt& theOther, const Standard_Real theLinearTolerance) const
0123 {
0124 return Distance (theOther) <= theLinearTolerance;
0125 }
0126
0127
0128 Standard_Real Distance (const gp_Pnt& theOther) const;
0129
0130
0131 Standard_Real SquareDistance (const gp_Pnt& theOther) const;
0132
0133
0134
0135
0136 Standard_EXPORT void Mirror (const gp_Pnt& theP);
0137
0138
0139
0140
0141 Standard_NODISCARD Standard_EXPORT gp_Pnt Mirrored (const gp_Pnt& theP) const;
0142
0143 Standard_EXPORT void Mirror (const gp_Ax1& theA1);
0144
0145
0146
0147
0148 Standard_NODISCARD Standard_EXPORT gp_Pnt Mirrored (const gp_Ax1& theA1) const;
0149
0150 Standard_EXPORT void Mirror (const gp_Ax2& theA2);
0151
0152
0153
0154 Standard_NODISCARD Standard_EXPORT gp_Pnt Mirrored (const gp_Ax2& theA2) const;
0155
0156 void Rotate (const gp_Ax1& theA1, const Standard_Real theAng);
0157
0158 Standard_NODISCARD gp_Pnt Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const
0159 {
0160 gp_Pnt aP = *this;
0161 aP.Rotate (theA1, theAng);
0162 return aP;
0163 }
0164
0165
0166 void Scale (const gp_Pnt& theP, const Standard_Real theS);
0167
0168 Standard_NODISCARD gp_Pnt Scaled (const gp_Pnt& theP, const Standard_Real theS) const
0169 {
0170 gp_Pnt aPres = *this;
0171 aPres.Scale (theP, theS);
0172 return aPres;
0173 }
0174
0175
0176 Standard_EXPORT void Transform (const gp_Trsf& theT);
0177
0178 Standard_NODISCARD gp_Pnt Transformed (const gp_Trsf& theT) const
0179 {
0180 gp_Pnt aP = *this;
0181 aP.Transform (theT);
0182 return aP;
0183 }
0184
0185
0186
0187 void Translate (const gp_Vec& theV);
0188
0189 Standard_NODISCARD gp_Pnt Translated (const gp_Vec& theV) const;
0190
0191
0192 void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2)
0193 {
0194 coord.Add (theP2.coord);
0195 coord.Subtract (theP1.coord);
0196 }
0197
0198 Standard_NODISCARD gp_Pnt Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const
0199 {
0200 gp_Pnt aP = *this;
0201 aP.Translate (theP1, theP2);
0202 return aP;
0203 }
0204
0205
0206 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0207
0208
0209 Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos);
0210
0211 private:
0212
0213 gp_XYZ coord;
0214
0215 };
0216
0217 namespace std
0218 {
0219 template <>
0220 struct hash<gp_Pnt>
0221 {
0222 size_t operator()(const gp_Pnt& thePnt) const noexcept
0223 {
0224 union
0225 {
0226 Standard_Real R[3];
0227 Standard_Integer I[6];
0228 } U;
0229
0230 thePnt.Coord(U.R[0], U.R[1], U.R[2]);
0231
0232 return std::hash<double>{}(U.I[0] / 23 + U.I[1] / 19 + U.I[2] / 17 + U.I[3] / 13 + U.I[4] / 11 + U.I[5] / 7);
0233 }
0234 };
0235
0236 template<>
0237 struct equal_to<gp_Pnt>
0238 {
0239 bool operator()(const gp_Pnt& thePnt1,
0240 const gp_Pnt& thePnt2) const noexcept
0241 {
0242 if (Abs(thePnt1.X() - thePnt2.X()) > Epsilon(thePnt2.X())) return false;
0243 if (Abs(thePnt1.Y() - thePnt2.Y()) > Epsilon(thePnt2.Y())) return false;
0244 if (Abs(thePnt1.Z() - thePnt2.Z()) > Epsilon(thePnt2.Z())) return false;
0245 return true;
0246 }
0247 };
0248 }
0249
0250 #include <gp_Trsf.hxx>
0251 #include <gp_Vec.hxx>
0252 #include <gp_XYZ.hxx>
0253
0254
0255
0256
0257
0258 inline Standard_Real gp_Pnt::Distance (const gp_Pnt& theOther) const
0259 {
0260 Standard_Real aD=0,aDD;
0261 const gp_XYZ& aXYZ = theOther.coord;
0262 aDD = coord.X(); aDD -= aXYZ.X(); aDD *= aDD; aD += aDD;
0263 aDD = coord.Y(); aDD -= aXYZ.Y(); aDD *= aDD; aD += aDD;
0264 aDD = coord.Z(); aDD -= aXYZ.Z(); aDD *= aDD; aD += aDD;
0265 return sqrt (aD);
0266 }
0267
0268
0269
0270
0271
0272 inline Standard_Real gp_Pnt::SquareDistance (const gp_Pnt& theOther) const
0273 {
0274 Standard_Real aD=0, aDD;
0275 const gp_XYZ& XYZ = theOther.coord;
0276 aDD = coord.X(); aDD -= XYZ.X(); aDD *= aDD; aD += aDD;
0277 aDD = coord.Y(); aDD -= XYZ.Y(); aDD *= aDD; aD += aDD;
0278 aDD = coord.Z(); aDD -= XYZ.Z(); aDD *= aDD; aD += aDD;
0279 return aD;
0280 }
0281
0282
0283
0284
0285
0286 inline void gp_Pnt::Rotate (const gp_Ax1& theA1, const Standard_Real theAng)
0287 {
0288 gp_Trsf aT;
0289 aT.SetRotation (theA1, theAng);
0290 aT.Transforms (coord);
0291 }
0292
0293
0294
0295
0296
0297 inline void gp_Pnt::Scale (const gp_Pnt& theP, const Standard_Real theS)
0298 {
0299 gp_XYZ aXYZ = theP.coord;
0300 aXYZ.Multiply (1.0 - theS);
0301 coord.Multiply (theS);
0302 coord.Add (aXYZ);
0303 }
0304
0305
0306
0307
0308
0309 inline void gp_Pnt::Translate(const gp_Vec& theV)
0310 {
0311 coord.Add (theV.XYZ());
0312 }
0313
0314
0315
0316
0317
0318 inline gp_Pnt gp_Pnt::Translated (const gp_Vec& theV) const
0319 {
0320 gp_Pnt aP = *this;
0321 aP.coord.Add (theV.XYZ());
0322 return aP;
0323 }
0324
0325 #endif