File indexing completed on 2026-09-25 09:19:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
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
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 class gp_Circ2d
0050 {
0051 public:
0052 DEFINE_STANDARD_ALLOC
0053
0054
0055 constexpr gp_Circ2d() noexcept
0056 : radius(RealLast())
0057 {
0058 }
0059
0060
0061
0062
0063
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
0073
0074
0075
0076
0077
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
0087 constexpr void SetLocation(const gp_Pnt2d& theP) noexcept { pos.SetLocation(theP); }
0088
0089
0090 constexpr void SetXAxis(const gp_Ax2d& theA) { pos.SetXAxis(theA); }
0091
0092
0093 constexpr void SetAxis(const gp_Ax22d& theA) noexcept { pos.SetAxis(theA); }
0094
0095
0096 constexpr void SetYAxis(const gp_Ax2d& theA) { pos.SetYAxis(theA); }
0097
0098
0099
0100
0101
0102
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
0112 constexpr double Area() const noexcept { return M_PI * radius * radius; }
0113
0114
0115
0116
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
0125
0126
0127
0128 bool Contains(const gp_Pnt2d& theP, const double theLinearTolerance) const noexcept
0129 {
0130 return Distance(theP) <= theLinearTolerance;
0131 }
0132
0133
0134
0135 double Distance(const gp_Pnt2d& theP) const noexcept;
0136
0137
0138 double SquareDistance(const gp_Pnt2d& theP) const noexcept;
0139
0140
0141 constexpr double Length() const noexcept { return 2. * M_PI * radius; }
0142
0143
0144 constexpr const gp_Pnt2d& Location() const noexcept { return pos.Location(); }
0145
0146
0147 constexpr double Radius() const noexcept { return radius; }
0148
0149
0150 constexpr const gp_Ax22d& Axis() const noexcept { return pos; }
0151
0152
0153 constexpr const gp_Ax22d& Position() const noexcept { return pos; }
0154
0155
0156 gp_Ax2d XAxis() const noexcept { return gp_Ax2d(pos.XAxis()); }
0157
0158
0159
0160 gp_Ax2d YAxis() const noexcept { return gp_Ax2d(pos.YAxis()); }
0161
0162
0163
0164
0165
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
0174
0175
0176
0177 [[nodiscard]] gp_Circ2d Reversed() const noexcept;
0178
0179
0180
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
0189
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
0195
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
0201
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
0212
0213
0214
0215
0216 [[nodiscard]] gp_Circ2d Scaled(const gp_Pnt2d& theP, const double theS) const;
0217
0218 void Transform(const gp_Trsf2d& theT);
0219
0220
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
0226
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
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