Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:21:30

0001 // Copyright (c) 1991-1999 Matra Datavision
0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
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 //! Defines  a non-persistent 2D cartesian point.
0031 class gp_Pnt2d 
0032 {
0033 public:
0034 
0035   DEFINE_STANDARD_ALLOC
0036 
0037   //! Creates a point with zero coordinates.
0038   gp_Pnt2d() {}
0039 
0040   //! Creates a point with a doublet of coordinates.
0041   gp_Pnt2d (const gp_XY& theCoord)
0042   : coord (theCoord)
0043   {}
0044 
0045   //! Creates a  point with its 2 cartesian's coordinates : theXp, theYp.
0046   gp_Pnt2d (const Standard_Real theXp, const Standard_Real theYp)
0047   : coord (theXp, theYp)
0048   {}
0049 
0050   //! Assigns the value Xi to the coordinate that corresponds to theIndex:
0051   //! theIndex = 1 => X is modified
0052   //! theIndex = 2 => Y is modified
0053   //! Raises OutOfRange if theIndex != {1, 2}.
0054   void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi) { coord.SetCoord (theIndex, theXi); }
0055 
0056   //! For this point, assigns the values theXp and theYp to its two coordinates
0057   void SetCoord (const Standard_Real theXp, const Standard_Real theYp) { coord.SetCoord (theXp, theYp); }
0058 
0059   //! Assigns the given value to the X  coordinate of this point.
0060   void SetX (const Standard_Real theX) { coord.SetX (theX); }
0061 
0062   //! Assigns the given value to the Y  coordinate of this point.
0063   void SetY (const Standard_Real theY) { coord.SetY (theY); }
0064 
0065   //! Assigns the two coordinates of Coord to this point.
0066   void SetXY (const gp_XY& theCoord) { coord = theCoord; }
0067 
0068   //! Returns the coordinate of range theIndex :
0069   //! theIndex = 1 => X is returned
0070   //! theIndex = 2 => Y is returned
0071   //! Raises OutOfRange if theIndex != {1, 2}.
0072   Standard_Real Coord (const Standard_Integer theIndex) const { return coord.Coord (theIndex); }
0073 
0074   //! For this point returns its two coordinates as a number pair.
0075   void Coord (Standard_Real& theXp, Standard_Real& theYp) const { coord.Coord (theXp, theYp); }
0076 
0077   //! For this point, returns its X  coordinate.
0078   Standard_Real X() const { return coord.X(); }
0079 
0080   //! For this point, returns its Y coordinate.
0081   Standard_Real Y() const { return coord.Y(); }
0082 
0083   //! For this point, returns its two coordinates as a number pair.
0084   const gp_XY& XY() const { return coord; }
0085 
0086   //! For this point, returns its two coordinates as a number pair.
0087   const gp_XY& Coord() const { return coord; }
0088 
0089   //! Returns the coordinates of this point.
0090   //! Note: This syntax allows direct modification of the returned value.
0091   gp_XY& ChangeCoord() { return coord; }
0092 
0093   //! Comparison
0094   //! Returns True if the distance between the two
0095   //! points is lower or equal to theLinearTolerance.
0096   Standard_Boolean IsEqual (const gp_Pnt2d& theOther, const Standard_Real theLinearTolerance) const
0097   {
0098     return Distance (theOther) <= theLinearTolerance;
0099   }
0100 
0101   //! Computes the distance between two points.
0102   Standard_Real Distance (const gp_Pnt2d& theOther) const;
0103 
0104   //! Computes the square distance between two points.
0105   Standard_Real SquareDistance (const gp_Pnt2d& theOther) const;
0106 
0107   //! Performs the symmetrical transformation of a point
0108   //! with respect to the point theP which is the center of
0109   //! the  symmetry.
0110   Standard_EXPORT void Mirror (const gp_Pnt2d& theP);
0111 
0112   //! Performs the symmetrical transformation of a point
0113   //! with respect to an axis placement which is the axis
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   //! Rotates a point. theA1 is the axis of the rotation.
0121   //! Ang is the angular value of the rotation in radians.
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   //! Scales a point. theS is the scaling value.
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   //! Transforms a point with the transformation theT.
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   //! Translates a point in the direction of the vector theV.
0152   //! The magnitude of the translation is the vector's magnitude.
0153   void Translate (const gp_Vec2d& theV);
0154 
0155   Standard_NODISCARD gp_Pnt2d Translated (const gp_Vec2d& theV) const;
0156 
0157   //! Translates a point from the point theP1 to the point theP2.
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   //! Dumps the content of me into the stream
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 //function : Distance
0185 // purpose :
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 //function : SquareDistance
0197 // purpose :
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 //function : Rotate
0209 // purpose :
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 //function : Scale
0220 // purpose :
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 //function : Translate
0232 // purpose :
0233 //=======================================================================
0234 inline void gp_Pnt2d::Translate(const gp_Vec2d& theV)
0235 {
0236   coord.Add (theV.XY());
0237 }
0238 
0239 //=======================================================================
0240 //function : Translated
0241 // purpose :
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 // _gp_Pnt2d_HeaderFile