File indexing completed on 2026-09-27 09:17:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _gp_XYZ_HeaderFile
0016 #define _gp_XYZ_HeaderFile
0017
0018 #include <gp.hxx>
0019 #include <gp_Mat.hxx>
0020 #include <Standard_ConstructionError.hxx>
0021 #include <Standard_OutOfRange.hxx>
0022 #include <Standard_OStream.hxx>
0023 #include <Standard_SStream.hxx>
0024
0025 #include <cmath>
0026
0027
0028
0029
0030
0031
0032
0033 class gp_XYZ
0034 {
0035 public:
0036 DEFINE_STANDARD_ALLOC
0037
0038
0039 constexpr gp_XYZ() noexcept
0040 : x(0.),
0041 y(0.),
0042 z(0.)
0043 {
0044 }
0045
0046
0047 constexpr gp_XYZ(const double theX, const double theY, const double theZ) noexcept
0048 : x(theX),
0049 y(theY),
0050 z(theZ)
0051 {
0052 }
0053
0054
0055
0056 constexpr void SetCoord(const double theX, const double theY, const double theZ) noexcept
0057 {
0058 x = theX;
0059 y = theY;
0060 z = theZ;
0061 }
0062
0063
0064
0065
0066
0067
0068 constexpr void SetCoord(const int theIndex, const double theXi)
0069 {
0070 Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > 3, nullptr);
0071 if (theIndex == 1)
0072 {
0073 x = theXi;
0074 }
0075 else if (theIndex == 2)
0076 {
0077 y = theXi;
0078 }
0079 else
0080 {
0081 z = theXi;
0082 }
0083 }
0084
0085
0086 constexpr void SetX(const double theX) noexcept { x = theX; }
0087
0088
0089 constexpr void SetY(const double theY) noexcept { y = theY; }
0090
0091
0092 constexpr void SetZ(const double theZ) noexcept { z = theZ; }
0093
0094
0095
0096
0097
0098
0099
0100 constexpr double Coord(const int theIndex) const
0101 {
0102 Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > 3, nullptr);
0103 if (theIndex == 1)
0104 {
0105 return x;
0106 }
0107 else if (theIndex == 2)
0108 {
0109 return y;
0110 }
0111 return z;
0112 }
0113
0114 constexpr double& ChangeCoord(const int theIndex)
0115 {
0116 Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > 3, nullptr);
0117 if (theIndex == 1)
0118 {
0119 return x;
0120 }
0121 else if (theIndex == 2)
0122 {
0123 return y;
0124 }
0125 return z;
0126 }
0127
0128 constexpr void Coord(double& theX, double& theY, double& theZ) const noexcept
0129 {
0130 theX = x;
0131 theY = y;
0132 theZ = z;
0133 }
0134
0135
0136
0137
0138 constexpr const double* GetData() const noexcept { return (&x); }
0139
0140
0141
0142
0143 double* ChangeData() noexcept { return (&x); }
0144
0145
0146 constexpr double X() const noexcept { return x; }
0147
0148
0149 constexpr double Y() const noexcept { return y; }
0150
0151
0152 constexpr double Z() const noexcept { return z; }
0153
0154
0155
0156 double Modulus() const { return std::sqrt(x * x + y * y + z * z); }
0157
0158
0159 constexpr double SquareModulus() const noexcept { return (x * x + y * y + z * z); }
0160
0161
0162
0163
0164 bool IsEqual(const gp_XYZ& theOther, const double theTolerance) const
0165
0166 {
0167 return (std::abs(x - theOther.x) < theTolerance) && (std::abs(y - theOther.y) < theTolerance)
0168 && (std::abs(z - theOther.z) < theTolerance);
0169 }
0170
0171
0172
0173
0174
0175
0176 constexpr void Add(const gp_XYZ& theOther) noexcept
0177 {
0178 x += theOther.x;
0179 y += theOther.y;
0180 z += theOther.z;
0181 }
0182
0183 constexpr void operator+=(const gp_XYZ& theOther) noexcept { Add(theOther); }
0184
0185
0186
0187
0188
0189
0190 [[nodiscard]] constexpr gp_XYZ Added(const gp_XYZ& theOther) const noexcept
0191 {
0192 return gp_XYZ(x + theOther.x, y + theOther.y, z + theOther.z);
0193 }
0194
0195 [[nodiscard]] constexpr gp_XYZ operator+(const gp_XYZ& theOther) const noexcept
0196 {
0197 return Added(theOther);
0198 }
0199
0200
0201
0202
0203
0204
0205 constexpr void Cross(const gp_XYZ& theOther) noexcept;
0206
0207 constexpr void operator^=(const gp_XYZ& theOther) noexcept { Cross(theOther); }
0208
0209
0210
0211
0212
0213
0214 [[nodiscard]] constexpr gp_XYZ Crossed(const gp_XYZ& theOther) const noexcept
0215 {
0216 return gp_XYZ(y * theOther.z - z * theOther.y,
0217 z * theOther.x - x * theOther.z,
0218 x * theOther.y - y * theOther.x);
0219 }
0220
0221 [[nodiscard]] constexpr gp_XYZ operator^(const gp_XYZ& theOther) const noexcept
0222 {
0223 return Crossed(theOther);
0224 }
0225
0226
0227
0228 double CrossMagnitude(const gp_XYZ& theRight) const;
0229
0230
0231
0232 constexpr double CrossSquareMagnitude(const gp_XYZ& theRight) const noexcept;
0233
0234
0235
0236 constexpr void CrossCross(const gp_XYZ& theCoord1, const gp_XYZ& theCoord2) noexcept;
0237
0238
0239
0240 [[nodiscard]] constexpr gp_XYZ CrossCrossed(const gp_XYZ& theCoord1,
0241 const gp_XYZ& theCoord2) const noexcept
0242 {
0243 gp_XYZ aCoord0 = *this;
0244 aCoord0.CrossCross(theCoord1, theCoord2);
0245 return aCoord0;
0246 }
0247
0248
0249 constexpr void Divide(const double theScalar)
0250 {
0251 x /= theScalar;
0252 y /= theScalar;
0253 z /= theScalar;
0254 }
0255
0256 constexpr void operator/=(const double theScalar) { Divide(theScalar); }
0257
0258
0259 [[nodiscard]] constexpr gp_XYZ Divided(const double theScalar) const
0260 {
0261 return gp_XYZ(x / theScalar, y / theScalar, z / theScalar);
0262 }
0263
0264 [[nodiscard]] constexpr gp_XYZ operator/(const double theScalar) const
0265 {
0266 return Divided(theScalar);
0267 }
0268
0269
0270 constexpr double Dot(const gp_XYZ& theOther) const noexcept
0271 {
0272 return (x * theOther.x + y * theOther.y + z * theOther.z);
0273 }
0274
0275 constexpr double operator*(const gp_XYZ& theOther) const noexcept { return Dot(theOther); }
0276
0277
0278 constexpr double DotCross(const gp_XYZ& theCoord1, const gp_XYZ& theCoord2) const noexcept;
0279
0280
0281
0282
0283
0284
0285 constexpr void Multiply(const double theScalar) noexcept
0286 {
0287 x *= theScalar;
0288 y *= theScalar;
0289 z *= theScalar;
0290 }
0291
0292 constexpr void operator*=(const double theScalar) noexcept { Multiply(theScalar); }
0293
0294
0295
0296
0297
0298
0299 constexpr void Multiply(const gp_XYZ& theOther) noexcept
0300 {
0301 x *= theOther.x;
0302 y *= theOther.y;
0303 z *= theOther.z;
0304 }
0305
0306 constexpr void operator*=(const gp_XYZ& theOther) noexcept { Multiply(theOther); }
0307
0308
0309 constexpr void Multiply(const gp_Mat& theMatrix) noexcept;
0310
0311 constexpr void operator*=(const gp_Mat& theMatrix) noexcept { Multiply(theMatrix); }
0312
0313
0314
0315
0316
0317
0318 [[nodiscard]] constexpr gp_XYZ Multiplied(const double theScalar) const noexcept
0319 {
0320 return gp_XYZ(x * theScalar, y * theScalar, z * theScalar);
0321 }
0322
0323 [[nodiscard]] constexpr gp_XYZ operator*(const double theScalar) const noexcept
0324 {
0325 return Multiplied(theScalar);
0326 }
0327
0328
0329
0330
0331
0332
0333 [[nodiscard]] constexpr gp_XYZ Multiplied(const gp_XYZ& theOther) const noexcept
0334 {
0335 return gp_XYZ(x * theOther.x, y * theOther.y, z * theOther.z);
0336 }
0337
0338
0339 [[nodiscard]] constexpr gp_XYZ Multiplied(const gp_Mat& theMatrix) const noexcept
0340 {
0341
0342 return gp_XYZ(theMatrix.myMat[0][0] * x + theMatrix.myMat[0][1] * y + theMatrix.myMat[0][2] * z,
0343 theMatrix.myMat[1][0] * x + theMatrix.myMat[1][1] * y + theMatrix.myMat[1][2] * z,
0344 theMatrix.myMat[2][0] * x + theMatrix.myMat[2][1] * y
0345 + theMatrix.myMat[2][2] * z);
0346 }
0347
0348 [[nodiscard]] constexpr gp_XYZ operator*(const gp_Mat& theMatrix) const noexcept
0349 {
0350 return Multiplied(theMatrix);
0351 }
0352
0353
0354
0355
0356
0357
0358
0359 void Normalize();
0360
0361
0362
0363
0364
0365
0366
0367 [[nodiscard]] gp_XYZ Normalized() const
0368 {
0369 const double aD = Modulus();
0370 Standard_ConstructionError_Raise_if(aD <= gp::Resolution(),
0371 "gp_XYZ::Normalized() - vector has zero norm");
0372 return gp_XYZ(x / aD, y / aD, z / aD);
0373 }
0374
0375
0376
0377
0378
0379
0380 constexpr void Reverse() noexcept
0381 {
0382 x = -x;
0383 y = -y;
0384 z = -z;
0385 }
0386
0387
0388
0389
0390
0391
0392 [[nodiscard]] constexpr gp_XYZ Reversed() const noexcept { return gp_XYZ(-x, -y, -z); }
0393
0394
0395
0396
0397
0398
0399 constexpr void Subtract(const gp_XYZ& theOther) noexcept
0400 {
0401 x -= theOther.x;
0402 y -= theOther.y;
0403 z -= theOther.z;
0404 }
0405
0406 constexpr void operator-=(const gp_XYZ& theOther) noexcept { Subtract(theOther); }
0407
0408
0409
0410
0411
0412
0413 [[nodiscard]] constexpr gp_XYZ Subtracted(const gp_XYZ& theOther) const noexcept
0414 {
0415 return gp_XYZ(x - theOther.x, y - theOther.y, z - theOther.z);
0416 }
0417
0418 [[nodiscard]] constexpr gp_XYZ operator-(const gp_XYZ& theOther) const noexcept
0419 {
0420 return Subtracted(theOther);
0421 }
0422
0423
0424
0425
0426
0427 constexpr void SetLinearForm(const double theA1,
0428 const gp_XYZ& theXYZ1,
0429 const double theA2,
0430 const gp_XYZ& theXYZ2,
0431 const double theA3,
0432 const gp_XYZ& theXYZ3,
0433 const gp_XYZ& theXYZ4) noexcept
0434 {
0435 x = theA1 * theXYZ1.x + theA2 * theXYZ2.x + theA3 * theXYZ3.x + theXYZ4.x;
0436 y = theA1 * theXYZ1.y + theA2 * theXYZ2.y + theA3 * theXYZ3.y + theXYZ4.y;
0437 z = theA1 * theXYZ1.z + theA2 * theXYZ2.z + theA3 * theXYZ3.z + theXYZ4.z;
0438 }
0439
0440
0441
0442
0443
0444 constexpr void SetLinearForm(const double theA1,
0445 const gp_XYZ& theXYZ1,
0446 const double theA2,
0447 const gp_XYZ& theXYZ2,
0448 const double theA3,
0449 const gp_XYZ& theXYZ3) noexcept
0450 {
0451 x = theA1 * theXYZ1.x + theA2 * theXYZ2.x + theA3 * theXYZ3.x;
0452 y = theA1 * theXYZ1.y + theA2 * theXYZ2.y + theA3 * theXYZ3.y;
0453 z = theA1 * theXYZ1.z + theA2 * theXYZ2.z + theA3 * theXYZ3.z;
0454 }
0455
0456
0457
0458
0459
0460 constexpr void SetLinearForm(const double theA1,
0461 const gp_XYZ& theXYZ1,
0462 const double theA2,
0463 const gp_XYZ& theXYZ2,
0464 const gp_XYZ& theXYZ3) noexcept
0465 {
0466 x = theA1 * theXYZ1.x + theA2 * theXYZ2.x + theXYZ3.x;
0467 y = theA1 * theXYZ1.y + theA2 * theXYZ2.y + theXYZ3.y;
0468 z = theA1 * theXYZ1.z + theA2 * theXYZ2.z + theXYZ3.z;
0469 }
0470
0471
0472
0473
0474
0475 constexpr void SetLinearForm(const double theA1,
0476 const gp_XYZ& theXYZ1,
0477 const double theA2,
0478 const gp_XYZ& theXYZ2) noexcept
0479 {
0480 x = theA1 * theXYZ1.x + theA2 * theXYZ2.x;
0481 y = theA1 * theXYZ1.y + theA2 * theXYZ2.y;
0482 z = theA1 * theXYZ1.z + theA2 * theXYZ2.z;
0483 }
0484
0485
0486
0487
0488
0489 constexpr void SetLinearForm(const double theA1,
0490 const gp_XYZ& theXYZ1,
0491 const gp_XYZ& theXYZ2) noexcept
0492 {
0493 x = theA1 * theXYZ1.x + theXYZ2.x;
0494 y = theA1 * theXYZ1.y + theXYZ2.y;
0495 z = theA1 * theXYZ1.z + theXYZ2.z;
0496 }
0497
0498
0499
0500
0501
0502 constexpr void SetLinearForm(const gp_XYZ& theXYZ1, const gp_XYZ& theXYZ2) noexcept
0503 {
0504 x = theXYZ1.x + theXYZ2.x;
0505 y = theXYZ1.y + theXYZ2.y;
0506 z = theXYZ1.z + theXYZ2.z;
0507 }
0508
0509
0510 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0511
0512
0513 Standard_EXPORT bool InitFromJson(const Standard_SStream& theSStream, int& theStreamPos);
0514
0515 private:
0516 double x;
0517 double y;
0518 double z;
0519 };
0520
0521
0522
0523 inline constexpr void gp_XYZ::Cross(const gp_XYZ& theRight) noexcept
0524 {
0525 const double aXresult = y * theRight.z - z * theRight.y;
0526 const double aYresult = z * theRight.x - x * theRight.z;
0527 z = x * theRight.y - y * theRight.x;
0528 x = aXresult;
0529 y = aYresult;
0530 }
0531
0532
0533
0534 inline double gp_XYZ::CrossMagnitude(const gp_XYZ& theRight) const
0535 {
0536 return sqrt(CrossSquareMagnitude(theRight));
0537 }
0538
0539
0540
0541 inline constexpr double gp_XYZ::CrossSquareMagnitude(const gp_XYZ& theRight) const noexcept
0542 {
0543 const double aXresult = y * theRight.z - z * theRight.y;
0544 const double aYresult = z * theRight.x - x * theRight.z;
0545 const double aZresult = x * theRight.y - y * theRight.x;
0546 return aXresult * aXresult + aYresult * aYresult + aZresult * aZresult;
0547 }
0548
0549
0550
0551 inline constexpr void gp_XYZ::CrossCross(const gp_XYZ& theCoord1, const gp_XYZ& theCoord2) noexcept
0552 {
0553
0554 const double aCrossX = theCoord1.y * theCoord2.z - theCoord1.z * theCoord2.y;
0555 const double aCrossY = theCoord1.z * theCoord2.x - theCoord1.x * theCoord2.z;
0556 const double aCrossZ = theCoord1.x * theCoord2.y - theCoord1.y * theCoord2.x;
0557
0558
0559 const double aXresult = y * aCrossZ - z * aCrossY;
0560 const double aYresult = z * aCrossX - x * aCrossZ;
0561
0562 z = x * aCrossY - y * aCrossX;
0563 x = aXresult;
0564 y = aYresult;
0565 }
0566
0567
0568
0569 inline constexpr double gp_XYZ::DotCross(const gp_XYZ& theCoord1,
0570 const gp_XYZ& theCoord2) const noexcept
0571 {
0572 const double aXresult = theCoord1.y * theCoord2.z - theCoord1.z * theCoord2.y;
0573 const double anYresult = theCoord1.z * theCoord2.x - theCoord1.x * theCoord2.z;
0574 const double aZresult = theCoord1.x * theCoord2.y - theCoord1.y * theCoord2.x;
0575 return (x * aXresult + y * anYresult + z * aZresult);
0576 }
0577
0578
0579
0580 inline constexpr void gp_XYZ::Multiply(const gp_Mat& theMatrix) noexcept
0581 {
0582
0583 const double aOrigX = x;
0584 const double aOrigY = y;
0585 const double aOrigZ = z;
0586
0587
0588 x = theMatrix.myMat[0][0] * aOrigX + theMatrix.myMat[0][1] * aOrigY
0589 + theMatrix.myMat[0][2] * aOrigZ;
0590 y = theMatrix.myMat[1][0] * aOrigX + theMatrix.myMat[1][1] * aOrigY
0591 + theMatrix.myMat[1][2] * aOrigZ;
0592 z = theMatrix.myMat[2][0] * aOrigX + theMatrix.myMat[2][1] * aOrigY
0593 + theMatrix.myMat[2][2] * aOrigZ;
0594 }
0595
0596
0597
0598 inline void gp_XYZ::Normalize()
0599 {
0600 double aD = Modulus();
0601 Standard_ConstructionError_Raise_if(aD <= gp::Resolution(),
0602 "gp_XYZ::Normalize() - vector has zero norm");
0603 x = x / aD;
0604 y = y / aD;
0605 z = z / aD;
0606 }
0607
0608
0609
0610 inline constexpr gp_XYZ operator*(const gp_Mat& theMatrix, const gp_XYZ& theCoord1) noexcept
0611 {
0612 return theCoord1.Multiplied(theMatrix);
0613 }
0614
0615
0616
0617 inline constexpr gp_XYZ operator*(const double theScalar, const gp_XYZ& theCoord1) noexcept
0618 {
0619 return theCoord1.Multiplied(theScalar);
0620 }
0621
0622 #endif