Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-25 09:19:55

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_Circ2d_HeaderFile
0016 #define _gp_Circ2d_HeaderFile
0017 
0018 #include <gp_Ax22d.hxx>
0019 #include <gp_Ax2d.hxx>
0020 #include <gp_Pnt2d.hxx>
0021 #include <gp_Trsf2d.hxx>
0022 #include <gp_Vec2d.hxx>
0023 #include <Standard_ConstructionError.hxx>
0024 
0025 //! Describes a circle in the plane (2D space).
0026 //! A circle is defined by its radius and positioned in the
0027 //! plane with a coordinate system (a gp_Ax22d object) as follows:
0028 //! -   the origin of the coordinate system is the center of the circle, and
0029 //! -   the orientation (direct or indirect) of the coordinate
0030 //! system gives an implicit orientation to the circle (and
0031 //! defines its trigonometric sense).
0032 //! This positioning coordinate system is the "local
0033 //! coordinate system" of the circle.
0034 //! Note: when a gp_Circ2d circle is converted into a
0035 //! Geom2d_Circle circle, some implicit properties of the
0036 //! circle are used explicitly:
0037 //! -   the implicit orientation corresponds to the direction in
0038 //! which parameter values increase,
0039 //! -   the starting point for parameterization is that of the "X
0040 //! Axis" of the local coordinate system (i.e. the "X Axis" of the circle).
0041 //! See Also
0042 //! GccAna and Geom2dGcc packages which provide
0043 //! functions for constructing circles defined by geometric constraints
0044 //! gce_MakeCirc2d which provides functions for more
0045 //! complex circle constructions
0046 //! Geom2d_Circle which provides additional functions for
0047 //! constructing circles and works, with the parametric
0048 //! equations of circles in particular gp_Ax22d
0049 class gp_Circ2d
0050 {
0051 public:
0052   DEFINE_STANDARD_ALLOC
0053 
0054   //! creates an indefinite circle.
0055   constexpr gp_Circ2d() noexcept
0056       : radius(RealLast())
0057   {
0058   }
0059 
0060   //! The location point of theXAxis is the center of the circle.
0061   //! Warnings:
0062   //! It is not forbidden to create a circle with theRadius = 0.0
0063   //! Raises ConstructionError if theRadius < 0.0.
0064   constexpr gp_Circ2d(const gp_Ax2d& theXAxis, const double theRadius, const bool theIsSense = true)
0065       : pos(theXAxis, theIsSense),
0066         radius(theRadius)
0067   {
0068     Standard_ConstructionError_Raise_if(theRadius < 0.0,
0069                                         "gp_Circ2d() - radius should be positive number");
0070   }
0071 
0072   //! theAxis defines the Xaxis and Yaxis of the circle which defines
0073   //! the origin and the sense of parametrization.
0074   //! The location point of theAxis is the center of the circle.
0075   //! Warnings:
0076   //! It is not forbidden to create a circle with theRadius = 0.0
0077   //! Raises ConstructionError if theRadius < 0.0.
0078   constexpr gp_Circ2d(const gp_Ax22d& theAxis, const double theRadius)
0079       : pos(theAxis),
0080         radius(theRadius)
0081   {
0082     Standard_ConstructionError_Raise_if(theRadius < 0.0,
0083                                         "gp_Circ2d() - radius should be positive number");
0084   }
0085 
0086   //! Changes the location point (center) of the circle.
0087   constexpr void SetLocation(const gp_Pnt2d& theP) noexcept { pos.SetLocation(theP); }
0088 
0089   //! Changes the X axis of the circle.
0090   constexpr void SetXAxis(const gp_Ax2d& theA) { pos.SetXAxis(theA); }
0091 
0092   //! Changes the X axis of the circle.
0093   constexpr void SetAxis(const gp_Ax22d& theA) noexcept { pos.SetAxis(theA); }
0094 
0095   //! Changes the Y axis of the circle.
0096   constexpr void SetYAxis(const gp_Ax2d& theA) { pos.SetYAxis(theA); }
0097 
0098   //! Modifies the radius of this circle.
0099   //! This class does not prevent the creation of a circle where
0100   //! theRadius is null.
0101   //! Exceptions
0102   //! Standard_ConstructionError if theRadius is negative.
0103   void SetRadius(const double theRadius)
0104   {
0105     Standard_ConstructionError_Raise_if(
0106       theRadius < 0.0,
0107       "gp_Circ2d::SetRadius() - radius should be positive number");
0108     radius = theRadius;
0109   }
0110 
0111   //! Computes the area of the circle.
0112   constexpr double Area() const noexcept { return M_PI * radius * radius; }
0113 
0114   //! Returns the normalized coefficients from the implicit equation
0115   //! of the circle :
0116   //! theA * (X**2) + theB * (Y**2) + 2*theC*(X*Y) + 2*theD*X + 2*theE*Y + theF = 0.0
0117   constexpr void Coefficients(double& theA,
0118                               double& theB,
0119                               double& theC,
0120                               double& theD,
0121                               double& theE,
0122                               double& theF) const noexcept;
0123 
0124   //! Does <me> contain theP ?
0125   //! Returns True if the distance between theP and any point on
0126   //! the circumference of the circle is lower of equal to
0127   //! <theLinearTolerance>.
0128   bool Contains(const gp_Pnt2d& theP, const double theLinearTolerance) const noexcept
0129   {
0130     return Distance(theP) <= theLinearTolerance;
0131   }
0132 
0133   //! Computes the minimum of distance between the point theP and any
0134   //! point on the circumference of the circle.
0135   double Distance(const gp_Pnt2d& theP) const noexcept;
0136 
0137   //! Computes the square distance between <me> and the point theP.
0138   double SquareDistance(const gp_Pnt2d& theP) const noexcept;
0139 
0140   //! computes the circumference of the circle.
0141   constexpr double Length() const noexcept { return 2. * M_PI * radius; }
0142 
0143   //! Returns the location point (center) of the circle.
0144   constexpr const gp_Pnt2d& Location() const noexcept { return pos.Location(); }
0145 
0146   //! Returns the radius value of the circle.
0147   constexpr double Radius() const noexcept { return radius; }
0148 
0149   //! returns the position of the circle.
0150   constexpr const gp_Ax22d& Axis() const noexcept { return pos; }
0151 
0152   //! returns the position of the circle. Idem Axis(me).
0153   constexpr const gp_Ax22d& Position() const noexcept { return pos; }
0154 
0155   //! returns the X axis of the circle.
0156   gp_Ax2d XAxis() const noexcept { return gp_Ax2d(pos.XAxis()); }
0157 
0158   //! Returns the Y axis of the circle.
0159   //! Reverses the direction of the circle.
0160   gp_Ax2d YAxis() const noexcept { return gp_Ax2d(pos.YAxis()); }
0161 
0162   //! Reverses the orientation of the local coordinate system
0163   //! of this circle (the "Y Direction" is reversed) and therefore
0164   //! changes the implicit orientation of this circle.
0165   //! Reverse assigns the result to this circle,
0166   void Reverse() noexcept
0167   {
0168     gp_Dir2d aTemp = pos.YDirection();
0169     aTemp.Reverse();
0170     pos.SetAxis(gp_Ax22d(pos.Location(), pos.XDirection(), aTemp));
0171   }
0172 
0173   //! Reverses the orientation of the local coordinate system
0174   //! of this circle (the "Y Direction" is reversed) and therefore
0175   //! changes the implicit orientation of this circle.
0176   //! Reversed creates a new circle.
0177   [[nodiscard]] gp_Circ2d Reversed() const noexcept;
0178 
0179   //! Returns true if the local coordinate system is direct
0180   //! and false in the other case.
0181   constexpr bool IsDirect() const noexcept
0182   {
0183     return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0;
0184   }
0185 
0186   Standard_EXPORT void Mirror(const gp_Pnt2d& theP) noexcept;
0187 
0188   //! Performs the symmetrical transformation of a circle with respect
0189   //! to the point theP which is the center of the symmetry
0190   [[nodiscard]] Standard_EXPORT gp_Circ2d Mirrored(const gp_Pnt2d& theP) const noexcept;
0191 
0192   Standard_EXPORT void Mirror(const gp_Ax2d& theA) noexcept;
0193 
0194   //! Performs the symmetrical transformation of a circle with respect
0195   //! to an axis placement which is the axis of the symmetry.
0196   [[nodiscard]] Standard_EXPORT gp_Circ2d Mirrored(const gp_Ax2d& theA) const noexcept;
0197 
0198   void Rotate(const gp_Pnt2d& theP, const double theAng) { pos.Rotate(theP, theAng); }
0199 
0200   //! Rotates a circle. theP is the center of the rotation.
0201   //! Ang is the angular value of the rotation in radians.
0202   [[nodiscard]] gp_Circ2d Rotated(const gp_Pnt2d& theP, const double theAng) const
0203   {
0204     gp_Circ2d aCirc = *this;
0205     aCirc.pos.Rotate(theP, theAng);
0206     return aCirc;
0207   }
0208 
0209   void Scale(const gp_Pnt2d& theP, const double theS);
0210 
0211   //! Scales a circle. theS is the scaling value.
0212   //! Warnings:
0213   //! If theS is negative the radius stay positive but
0214   //! the "XAxis" and the "YAxis" are reversed as for
0215   //! an ellipse.
0216   [[nodiscard]] gp_Circ2d Scaled(const gp_Pnt2d& theP, const double theS) const;
0217 
0218   void Transform(const gp_Trsf2d& theT);
0219 
0220   //! Transforms a circle with the transformation theT from class Trsf2d.
0221   [[nodiscard]] gp_Circ2d Transformed(const gp_Trsf2d& theT) const;
0222 
0223   constexpr void Translate(const gp_Vec2d& theV) noexcept { pos.Translate(theV); }
0224 
0225   //! Translates a circle in the direction of the vector theV.
0226   //! The magnitude of the translation is the vector's magnitude.
0227   [[nodiscard]] constexpr gp_Circ2d Translated(const gp_Vec2d& theV) const noexcept
0228   {
0229     gp_Circ2d aCirc = *this;
0230     aCirc.pos.Translate(theV);
0231     return aCirc;
0232   }
0233 
0234   constexpr void Translate(const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) noexcept
0235   {
0236     pos.Translate(theP1, theP2);
0237   }
0238 
0239   //! Translates a circle from the point theP1 to the point theP2.
0240   [[nodiscard]] constexpr gp_Circ2d Translated(const gp_Pnt2d& theP1,
0241                                                const gp_Pnt2d& theP2) const noexcept
0242   {
0243     gp_Circ2d aCirc = *this;
0244     aCirc.pos.Translate(theP1, theP2);
0245     return aCirc;
0246   }
0247 
0248 private:
0249   gp_Ax22d pos;
0250   double   radius;
0251 };
0252 
0253 //=================================================================================================
0254 
0255 constexpr inline void gp_Circ2d::Coefficients(double& theA,
0256                                               double& theB,
0257                                               double& theC,
0258                                               double& theD,
0259                                               double& theE,
0260                                               double& theF) const noexcept
0261 {
0262   double aXc  = pos.Location().X();
0263   double anYc = pos.Location().Y();
0264   theA        = 1.0;
0265   theB        = 1.0;
0266   theC        = 0.0;
0267   theD        = -aXc;
0268   theE        = -anYc;
0269   theF        = aXc * aXc + anYc * anYc - radius * radius;
0270 }
0271 
0272 //=================================================================================================
0273 
0274 inline double gp_Circ2d::Distance(const gp_Pnt2d& theP) const noexcept
0275 {
0276   gp_XY aCoord = theP.XY();
0277   aCoord.Subtract(pos.Location().XY());
0278   double aD = radius - aCoord.Modulus();
0279   if (aD < 0)
0280   {
0281     aD = -aD;
0282   }
0283   return aD;
0284 }
0285 
0286 //=================================================================================================
0287 
0288 inline gp_Circ2d gp_Circ2d::Reversed() const noexcept
0289 {
0290   gp_Circ2d aCirc = *this;
0291   gp_Dir2d  aTemp = pos.YDirection();
0292   aTemp.Reverse();
0293   aCirc.pos.SetAxis(gp_Ax22d(pos.Location(), pos.XDirection(), aTemp));
0294   return aCirc;
0295 }
0296 
0297 //=================================================================================================
0298 
0299 inline double gp_Circ2d::SquareDistance(const gp_Pnt2d& theP) const noexcept
0300 {
0301   gp_XY aCoord = theP.XY();
0302   aCoord.Subtract(pos.Location().XY());
0303   double aD = radius - aCoord.Modulus();
0304   return aD * aD;
0305 }
0306 
0307 //=================================================================================================
0308 
0309 inline void gp_Circ2d::Scale(const gp_Pnt2d& theP, const double theS)
0310 {
0311   radius *= theS;
0312   if (radius < 0)
0313   {
0314     radius = -radius;
0315   }
0316   pos.Scale(theP, theS);
0317 }
0318 
0319 //=================================================================================================
0320 
0321 inline gp_Circ2d gp_Circ2d::Scaled(const gp_Pnt2d& theP, const double theS) const
0322 {
0323   gp_Circ2d aCirc = *this;
0324   aCirc.radius *= theS;
0325   if (aCirc.radius < 0)
0326   {
0327     aCirc.radius = -aCirc.radius;
0328   }
0329   aCirc.pos.Scale(theP, theS);
0330   return aCirc;
0331 }
0332 
0333 //=================================================================================================
0334 
0335 inline void gp_Circ2d::Transform(const gp_Trsf2d& theT)
0336 {
0337   radius *= theT.ScaleFactor();
0338   if (radius < 0)
0339   {
0340     radius = -radius;
0341   }
0342   pos.Transform(theT);
0343 }
0344 
0345 //=================================================================================================
0346 
0347 inline gp_Circ2d gp_Circ2d::Transformed(const gp_Trsf2d& theT) const
0348 {
0349   gp_Circ2d aCirc = *this;
0350   aCirc.radius *= theT.ScaleFactor();
0351   if (aCirc.radius < 0)
0352   {
0353     aCirc.radius = -aCirc.radius;
0354   }
0355   aCirc.pos.Transform(theT);
0356   return aCirc;
0357 }
0358 
0359 #endif // _gp_Circ2d_HeaderFile