File indexing completed on 2026-09-13 09:16:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _gp_XY_HeaderFile
0016 #define _gp_XY_HeaderFile
0017
0018 #include <gp.hxx>
0019 #include <gp_Mat2d.hxx>
0020 #include <Standard_ConstructionError.hxx>
0021 #include <Standard_OutOfRange.hxx>
0022
0023
0024
0025
0026
0027
0028
0029 class gp_XY
0030 {
0031 public:
0032 DEFINE_STANDARD_ALLOC
0033
0034
0035 constexpr gp_XY() noexcept
0036 : x(0.),
0037 y(0.)
0038 {
0039 }
0040
0041
0042 constexpr gp_XY(const double theX, const double theY) noexcept
0043 : x(theX),
0044 y(theY)
0045 {
0046 }
0047
0048
0049
0050
0051
0052 constexpr void SetCoord(const int theIndex, const double theXi)
0053 {
0054 Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > 2, nullptr);
0055 if (theIndex == 1)
0056 {
0057 x = theXi;
0058 }
0059 else
0060 {
0061 y = theXi;
0062 }
0063 }
0064
0065
0066
0067 constexpr void SetCoord(const double theX, const double theY) noexcept
0068 {
0069 x = theX;
0070 y = theY;
0071 }
0072
0073
0074 constexpr void SetX(const double theX) noexcept { x = theX; }
0075
0076
0077 constexpr void SetY(const double theY) noexcept { y = theY; }
0078
0079
0080
0081
0082
0083 constexpr double Coord(const int theIndex) const
0084 {
0085 Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > 2, nullptr);
0086 if (theIndex == 1)
0087 {
0088 return x;
0089 }
0090 return y;
0091 }
0092
0093 constexpr double& ChangeCoord(const int theIndex)
0094 {
0095 Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > 2, nullptr);
0096 if (theIndex == 1)
0097 {
0098 return x;
0099 }
0100 return y;
0101 }
0102
0103
0104 constexpr void Coord(double& theX, double& theY) const noexcept
0105 {
0106 theX = x;
0107 theY = y;
0108 }
0109
0110
0111 constexpr double X() const noexcept { return x; }
0112
0113
0114 constexpr double Y() const noexcept { return y; }
0115
0116
0117 double Modulus() const { return sqrt(SquareModulus()); }
0118
0119
0120 constexpr double SquareModulus() const noexcept { return x * x + y * y; }
0121
0122
0123
0124
0125 bool IsEqual(const gp_XY& theOther, const double theTolerance) const
0126 {
0127 return (std::abs(x - theOther.x) < theTolerance) && (std::abs(y - theOther.y) < theTolerance);
0128 }
0129
0130
0131
0132
0133
0134
0135 constexpr void Add(const gp_XY& theOther) noexcept
0136 {
0137 x += theOther.x;
0138 y += theOther.y;
0139 }
0140
0141 constexpr void operator+=(const gp_XY& theOther) noexcept { Add(theOther); }
0142
0143
0144
0145
0146
0147
0148 [[nodiscard]] constexpr gp_XY Added(const gp_XY& theOther) const noexcept
0149 {
0150 return gp_XY(x + theOther.X(), y + theOther.Y());
0151 }
0152
0153 [[nodiscard]] constexpr gp_XY operator+(const gp_XY& theOther) const noexcept
0154 {
0155 return Added(theOther);
0156 }
0157
0158
0159
0160
0161 [[nodiscard]] constexpr double Crossed(const gp_XY& theOther) const noexcept
0162 {
0163 return x * theOther.y - y * theOther.x;
0164 }
0165
0166 [[nodiscard]] constexpr double operator^(const gp_XY& theOther) const noexcept
0167 {
0168 return Crossed(theOther);
0169 }
0170
0171
0172
0173 double CrossMagnitude(const gp_XY& theRight) const
0174 {
0175 return std::abs(x * theRight.y - y * theRight.x);
0176 }
0177
0178
0179
0180 constexpr double CrossSquareMagnitude(const gp_XY& theRight) const noexcept
0181 {
0182 const double aZresult = x * theRight.y - y * theRight.x;
0183 return aZresult * aZresult;
0184 }
0185
0186
0187 constexpr void Divide(const double theScalar)
0188 {
0189 x /= theScalar;
0190 y /= theScalar;
0191 }
0192
0193 constexpr void operator/=(const double theScalar) { Divide(theScalar); }
0194
0195
0196 [[nodiscard]] constexpr gp_XY Divided(const double theScalar) const
0197 {
0198 return gp_XY(x / theScalar, y / theScalar);
0199 }
0200
0201 [[nodiscard]] constexpr gp_XY operator/(const double theScalar) const
0202 {
0203 return Divided(theScalar);
0204 }
0205
0206
0207 constexpr double Dot(const gp_XY& theOther) const noexcept
0208 {
0209 return x * theOther.x + y * theOther.y;
0210 }
0211
0212 constexpr double operator*(const gp_XY& theOther) const noexcept { return Dot(theOther); }
0213
0214
0215
0216
0217
0218 constexpr void Multiply(const double theScalar) noexcept
0219 {
0220 x *= theScalar;
0221 y *= theScalar;
0222 }
0223
0224 constexpr void operator*=(const double theScalar) noexcept { Multiply(theScalar); }
0225
0226
0227
0228
0229
0230 constexpr void Multiply(const gp_XY& theOther) noexcept
0231 {
0232 x *= theOther.x;
0233 y *= theOther.y;
0234 }
0235
0236 constexpr void operator*=(const gp_XY& theOther) noexcept { Multiply(theOther); }
0237
0238
0239 constexpr void Multiply(const gp_Mat2d& theMatrix) noexcept;
0240
0241 constexpr void operator*=(const gp_Mat2d& theMatrix) noexcept { Multiply(theMatrix); }
0242
0243
0244
0245
0246
0247 [[nodiscard]] constexpr gp_XY Multiplied(const double theScalar) const noexcept
0248 {
0249 return gp_XY(x * theScalar, y * theScalar);
0250 }
0251
0252 [[nodiscard]] constexpr gp_XY operator*(const double theScalar) const noexcept
0253 {
0254 return Multiplied(theScalar);
0255 }
0256
0257
0258
0259
0260
0261 [[nodiscard]] constexpr gp_XY Multiplied(const gp_XY& theOther) const noexcept
0262 {
0263 return gp_XY(x * theOther.X(), y * theOther.Y());
0264 }
0265
0266
0267 [[nodiscard]] constexpr gp_XY Multiplied(const gp_Mat2d& theMatrix) const noexcept
0268 {
0269 return gp_XY(theMatrix.myMat[0][0] * x + theMatrix.myMat[0][1] * y,
0270 theMatrix.myMat[1][0] * x + theMatrix.myMat[1][1] * y);
0271 }
0272
0273 [[nodiscard]] constexpr gp_XY operator*(const gp_Mat2d& theMatrix) const noexcept
0274 {
0275 return Multiplied(theMatrix);
0276 }
0277
0278
0279
0280
0281
0282
0283 void Normalize();
0284
0285
0286
0287
0288
0289
0290 [[nodiscard]] gp_XY Normalized() const
0291 {
0292 double aD = Modulus();
0293 Standard_ConstructionError_Raise_if(aD <= gp::Resolution(),
0294 "gp_XY::Normalized() - vector has zero norm");
0295 return gp_XY(x / aD, y / aD);
0296 }
0297
0298
0299
0300
0301 constexpr void Reverse() noexcept
0302 {
0303 x = -x;
0304 y = -y;
0305 }
0306
0307
0308
0309
0310
0311 [[nodiscard]] constexpr gp_XY Reversed() const noexcept { return gp_XY(-x, -y); }
0312
0313 [[nodiscard]] constexpr gp_XY operator-() const noexcept { return Reversed(); }
0314
0315
0316
0317
0318
0319
0320 constexpr void SetLinearForm(const double theA1,
0321 const gp_XY& theXY1,
0322 const double theA2,
0323 const gp_XY& theXY2) noexcept
0324 {
0325 x = theA1 * theXY1.x + theA2 * theXY2.x;
0326 y = theA1 * theXY1.y + theA2 * theXY2.y;
0327 }
0328
0329
0330
0331
0332
0333
0334 constexpr void SetLinearForm(const double theA1,
0335 const gp_XY& theXY1,
0336 const double theA2,
0337 const gp_XY& theXY2,
0338 const gp_XY& theXY3) noexcept
0339 {
0340 x = theA1 * theXY1.x + theA2 * theXY2.x + theXY3.x;
0341 y = theA1 * theXY1.y + theA2 * theXY2.y + theXY3.y;
0342 }
0343
0344
0345
0346
0347
0348
0349 constexpr void SetLinearForm(const double theA1,
0350 const gp_XY& theXY1,
0351 const gp_XY& theXY2) noexcept
0352 {
0353 x = theA1 * theXY1.x + theXY2.x;
0354 y = theA1 * theXY1.y + theXY2.y;
0355 }
0356
0357
0358
0359
0360
0361
0362 constexpr void SetLinearForm(const gp_XY& theXY1, const gp_XY& theXY2) noexcept
0363 {
0364 x = theXY1.x + theXY2.x;
0365 y = theXY1.y + theXY2.y;
0366 }
0367
0368
0369
0370
0371
0372 constexpr void Subtract(const gp_XY& theOther) noexcept
0373 {
0374 x -= theOther.x;
0375 y -= theOther.y;
0376 }
0377
0378 constexpr void operator-=(const gp_XY& theOther) noexcept { Subtract(theOther); }
0379
0380
0381
0382
0383
0384 [[nodiscard]] constexpr gp_XY Subtracted(const gp_XY& theOther) const noexcept
0385 {
0386 return gp_XY(x - theOther.x, y - theOther.y);
0387 }
0388
0389 [[nodiscard]] constexpr gp_XY operator-(const gp_XY& theOther) const noexcept
0390 {
0391 return Subtracted(theOther);
0392 }
0393
0394 private:
0395 double x;
0396 double y;
0397 };
0398
0399
0400
0401 inline constexpr void gp_XY::Multiply(const gp_Mat2d& theMatrix) noexcept
0402 {
0403 const double aXresult = theMatrix.myMat[0][0] * x + theMatrix.myMat[0][1] * y;
0404 y = theMatrix.myMat[1][0] * x + theMatrix.myMat[1][1] * y;
0405 x = aXresult;
0406 }
0407
0408
0409
0410 inline void gp_XY::Normalize()
0411 {
0412 double aD = Modulus();
0413 Standard_ConstructionError_Raise_if(aD <= gp::Resolution(),
0414 "gp_XY::Normalize() - vector has zero norm");
0415 x = x / aD;
0416 y = y / aD;
0417 }
0418
0419
0420
0421
0422
0423 inline constexpr gp_XY operator*(const gp_Mat2d& theMatrix, const gp_XY& theCoord1) noexcept
0424 {
0425 return theCoord1.Multiplied(theMatrix);
0426 }
0427
0428
0429
0430
0431
0432 inline constexpr gp_XY operator*(const double theScalar, const gp_XY& theCoord1) noexcept
0433 {
0434 return theCoord1.Multiplied(theScalar);
0435 }
0436
0437 #endif