File indexing completed on 2026-09-18 09:20:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _gp_Mat_HeaderFile
0016 #define _gp_Mat_HeaderFile
0017
0018 #include <gp.hxx>
0019 #include <Standard_OutOfRange.hxx>
0020 #include <Standard_OStream.hxx>
0021 #include <Standard_ConstructionError.hxx>
0022
0023 class gp_XYZ;
0024
0025
0026
0027 class gp_Mat
0028 {
0029 public:
0030 DEFINE_STANDARD_ALLOC
0031
0032
0033 constexpr gp_Mat() noexcept
0034 : myMat{{0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}}
0035 {
0036 }
0037
0038 constexpr gp_Mat(const double theA11,
0039 const double theA12,
0040 const double theA13,
0041 const double theA21,
0042 const double theA22,
0043 const double theA23,
0044 const double theA31,
0045 const double theA32,
0046 const double theA33) noexcept;
0047
0048
0049
0050 Standard_EXPORT gp_Mat(const gp_XYZ& theCol1, const gp_XYZ& theCol2, const gp_XYZ& theCol3);
0051
0052
0053
0054
0055 Standard_EXPORT void SetCol(const int theCol, const gp_XYZ& theValue);
0056
0057
0058
0059 Standard_EXPORT void SetCols(const gp_XYZ& theCol1, const gp_XYZ& theCol2, const gp_XYZ& theCol3);
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 Standard_EXPORT void SetCross(const gp_XYZ& theRef);
0070
0071
0072
0073
0074
0075
0076
0077
0078 constexpr void SetDiagonal(const double theX1, const double theX2, const double theX3) noexcept
0079 {
0080 myMat[0][0] = theX1;
0081 myMat[1][1] = theX2;
0082 myMat[2][2] = theX3;
0083 }
0084
0085
0086
0087
0088
0089
0090 Standard_EXPORT void SetDot(const gp_XYZ& theRef) noexcept;
0091
0092
0093 constexpr void SetIdentity() noexcept
0094 {
0095 myMat[0][0] = myMat[1][1] = myMat[2][2] = 1.0;
0096 myMat[0][1] = myMat[0][2] = myMat[1][0] = myMat[1][2] = myMat[2][0] = myMat[2][1] = 0.0;
0097 }
0098
0099
0100
0101
0102
0103 Standard_EXPORT void SetRotation(const gp_XYZ& theAxis, const double theAng);
0104
0105
0106
0107 Standard_EXPORT void SetRow(const int theRow, const gp_XYZ& theValue);
0108
0109
0110
0111 Standard_EXPORT void SetRows(const gp_XYZ& theRow1, const gp_XYZ& theRow2, const gp_XYZ& theRow3);
0112
0113
0114
0115
0116
0117
0118
0119
0120 constexpr void SetScale(const double theS) noexcept
0121 {
0122 myMat[0][0] = myMat[1][1] = myMat[2][2] = theS;
0123 myMat[0][1] = myMat[0][2] = myMat[1][0] = myMat[1][2] = myMat[2][0] = myMat[2][1] = 0.0;
0124 }
0125
0126
0127
0128 void SetValue(const int theRow, const int theCol, const double theValue)
0129 {
0130 Standard_OutOfRange_Raise_if(theRow < 1 || theRow > 3 || theCol < 1 || theCol > 3, " ");
0131 myMat[theRow - 1][theCol - 1] = theValue;
0132 }
0133
0134
0135
0136 Standard_EXPORT gp_XYZ Column(const int theCol) const;
0137
0138
0139 constexpr double Determinant() const noexcept
0140 {
0141 const double a00 = myMat[0][0], a01 = myMat[0][1], a02 = myMat[0][2];
0142 const double a10 = myMat[1][0], a11 = myMat[1][1], a12 = myMat[1][2];
0143 const double a20 = myMat[2][0], a21 = myMat[2][1], a22 = myMat[2][2];
0144
0145 return a00 * (a11 * a22 - a21 * a12)
0146 - a01 * (a10 * a22 - a20 * a12)
0147 + a02 * (a10 * a21 - a20 * a11);
0148
0149 }
0150
0151
0152 Standard_EXPORT gp_XYZ Diagonal() const;
0153
0154
0155
0156 Standard_EXPORT gp_XYZ Row(const int theRow) const;
0157
0158
0159
0160 const double& Value(const int theRow, const int theCol) const
0161 {
0162 Standard_OutOfRange_Raise_if(theRow < 1 || theRow > 3 || theCol < 1 || theCol > 3, " ");
0163 return myMat[theRow - 1][theCol - 1];
0164 }
0165
0166 const double& operator()(const int theRow, const int theCol) const
0167 {
0168 return Value(theRow, theCol);
0169 }
0170
0171
0172
0173 double& ChangeValue(const int theRow, const int theCol)
0174 {
0175 Standard_OutOfRange_Raise_if(theRow < 1 || theRow > 3 || theCol < 1 || theCol > 3, " ");
0176 return myMat[theRow - 1][theCol - 1];
0177 }
0178
0179 double& operator()(const int theRow, const int theCol) { return ChangeValue(theRow, theCol); }
0180
0181
0182
0183
0184 constexpr bool IsSingular() const noexcept
0185 {
0186
0187 const double aDet = Determinant();
0188 return (aDet < 0.0 ? -aDet : aDet) <= gp::Resolution();
0189 }
0190
0191 constexpr void Add(const gp_Mat& theOther) noexcept;
0192
0193 constexpr void operator+=(const gp_Mat& theOther) noexcept { Add(theOther); }
0194
0195
0196
0197
0198 [[nodiscard]] constexpr gp_Mat Added(const gp_Mat& theOther) const noexcept;
0199
0200 [[nodiscard]] constexpr gp_Mat operator+(const gp_Mat& theOther) const noexcept
0201 {
0202 return Added(theOther);
0203 }
0204
0205 constexpr void Divide(const double theScalar);
0206
0207 constexpr void operator/=(const double theScalar) { Divide(theScalar); }
0208
0209
0210 [[nodiscard]] constexpr gp_Mat Divided(const double theScalar) const;
0211
0212 [[nodiscard]] constexpr gp_Mat operator/(const double theScalar) const
0213 {
0214 return Divided(theScalar);
0215 }
0216
0217 Standard_EXPORT void Invert();
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229 [[nodiscard]] Standard_EXPORT gp_Mat Inverted() const;
0230
0231
0232 [[nodiscard]] constexpr gp_Mat Multiplied(const gp_Mat& theOther) const noexcept
0233 {
0234 gp_Mat aNewMat = *this;
0235 aNewMat.Multiply(theOther);
0236 return aNewMat;
0237 }
0238
0239 [[nodiscard]] constexpr gp_Mat operator*(const gp_Mat& theOther) const noexcept
0240 {
0241 return Multiplied(theOther);
0242 }
0243
0244
0245 constexpr void Multiply(const gp_Mat& theOther) noexcept;
0246
0247 constexpr void operator*=(const gp_Mat& theOther) noexcept { Multiply(theOther); }
0248
0249 constexpr void PreMultiply(const gp_Mat& theOther) noexcept;
0250
0251 [[nodiscard]] constexpr gp_Mat Multiplied(const double theScalar) const noexcept;
0252
0253 [[nodiscard]] constexpr gp_Mat operator*(const double theScalar) const noexcept
0254 {
0255 return Multiplied(theScalar);
0256 }
0257
0258
0259 constexpr void Multiply(const double theScalar) noexcept;
0260
0261 constexpr void operator*=(const double theScalar) noexcept { Multiply(theScalar); }
0262
0263 Standard_EXPORT void Power(const int N);
0264
0265
0266
0267
0268
0269
0270 [[nodiscard]] gp_Mat Powered(const int theN) const
0271 {
0272 gp_Mat aMatN = *this;
0273 aMatN.Power(theN);
0274 return aMatN;
0275 }
0276
0277 constexpr void Subtract(const gp_Mat& theOther) noexcept;
0278
0279 constexpr void operator-=(const gp_Mat& theOther) noexcept { Subtract(theOther); }
0280
0281
0282
0283 [[nodiscard]] constexpr gp_Mat Subtracted(const gp_Mat& theOther) const noexcept;
0284
0285 [[nodiscard]] constexpr gp_Mat operator-(const gp_Mat& theOther) const noexcept
0286 {
0287 return Subtracted(theOther);
0288 }
0289
0290 void Transpose();
0291
0292
0293 [[nodiscard]] gp_Mat Transposed() const
0294 {
0295 gp_Mat aNewMat = *this;
0296 aNewMat.Transpose();
0297 return aNewMat;
0298 }
0299
0300
0301 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0302
0303 friend class gp_XYZ;
0304 friend class gp_Trsf;
0305 friend class gp_GTrsf;
0306
0307 private:
0308 double myMat[3][3];
0309 };
0310
0311
0312
0313 inline constexpr gp_Mat::gp_Mat(const double theA11,
0314 const double theA12,
0315 const double theA13,
0316 const double theA21,
0317 const double theA22,
0318 const double theA23,
0319 const double theA31,
0320 const double theA32,
0321 const double theA33) noexcept
0322 : myMat{{theA11, theA12, theA13}, {theA21, theA22, theA23}, {theA31, theA32, theA33}}
0323 {
0324 }
0325
0326
0327
0328 inline constexpr void gp_Mat::Add(const gp_Mat& theOther) noexcept
0329 {
0330 myMat[0][0] += theOther.myMat[0][0];
0331 myMat[0][1] += theOther.myMat[0][1];
0332 myMat[0][2] += theOther.myMat[0][2];
0333 myMat[1][0] += theOther.myMat[1][0];
0334 myMat[1][1] += theOther.myMat[1][1];
0335 myMat[1][2] += theOther.myMat[1][2];
0336 myMat[2][0] += theOther.myMat[2][0];
0337 myMat[2][1] += theOther.myMat[2][1];
0338 myMat[2][2] += theOther.myMat[2][2];
0339 }
0340
0341
0342
0343 inline constexpr gp_Mat gp_Mat::Added(const gp_Mat& theOther) const noexcept
0344 {
0345 gp_Mat aNewMat(*this);
0346 aNewMat.Add(theOther);
0347 return aNewMat;
0348 }
0349
0350
0351
0352 inline constexpr void gp_Mat::Divide(const double theScalar)
0353 {
0354 Standard_ConstructionError_Raise_if((theScalar < 0.0 ? -theScalar : theScalar)
0355 <= gp::Resolution(),
0356 "gp_Mat : Divide by 0");
0357 const double anUnSurScalar = 1.0 / theScalar;
0358 myMat[0][0] *= anUnSurScalar;
0359 myMat[0][1] *= anUnSurScalar;
0360 myMat[0][2] *= anUnSurScalar;
0361 myMat[1][0] *= anUnSurScalar;
0362 myMat[1][1] *= anUnSurScalar;
0363 myMat[1][2] *= anUnSurScalar;
0364 myMat[2][0] *= anUnSurScalar;
0365 myMat[2][1] *= anUnSurScalar;
0366 myMat[2][2] *= anUnSurScalar;
0367 }
0368
0369
0370
0371 inline constexpr gp_Mat gp_Mat::Divided(const double theScalar) const
0372 {
0373 gp_Mat aNewMat(*this);
0374 aNewMat.Divide(theScalar);
0375 return aNewMat;
0376 }
0377
0378
0379
0380 inline constexpr void gp_Mat::Multiply(const gp_Mat& theOther) noexcept
0381 {
0382 const double aT00 = myMat[0][0] * theOther.myMat[0][0] + myMat[0][1] * theOther.myMat[1][0]
0383 + myMat[0][2] * theOther.myMat[2][0];
0384 const double aT01 = myMat[0][0] * theOther.myMat[0][1] + myMat[0][1] * theOther.myMat[1][1]
0385 + myMat[0][2] * theOther.myMat[2][1];
0386 const double aT02 = myMat[0][0] * theOther.myMat[0][2] + myMat[0][1] * theOther.myMat[1][2]
0387 + myMat[0][2] * theOther.myMat[2][2];
0388 const double aT10 = myMat[1][0] * theOther.myMat[0][0] + myMat[1][1] * theOther.myMat[1][0]
0389 + myMat[1][2] * theOther.myMat[2][0];
0390 const double aT11 = myMat[1][0] * theOther.myMat[0][1] + myMat[1][1] * theOther.myMat[1][1]
0391 + myMat[1][2] * theOther.myMat[2][1];
0392 const double aT12 = myMat[1][0] * theOther.myMat[0][2] + myMat[1][1] * theOther.myMat[1][2]
0393 + myMat[1][2] * theOther.myMat[2][2];
0394 const double aT20 = myMat[2][0] * theOther.myMat[0][0] + myMat[2][1] * theOther.myMat[1][0]
0395 + myMat[2][2] * theOther.myMat[2][0];
0396 const double aT21 = myMat[2][0] * theOther.myMat[0][1] + myMat[2][1] * theOther.myMat[1][1]
0397 + myMat[2][2] * theOther.myMat[2][1];
0398 const double aT22 = myMat[2][0] * theOther.myMat[0][2] + myMat[2][1] * theOther.myMat[1][2]
0399 + myMat[2][2] * theOther.myMat[2][2];
0400 myMat[0][0] = aT00;
0401 myMat[0][1] = aT01;
0402 myMat[0][2] = aT02;
0403 myMat[1][0] = aT10;
0404 myMat[1][1] = aT11;
0405 myMat[1][2] = aT12;
0406 myMat[2][0] = aT20;
0407 myMat[2][1] = aT21;
0408 myMat[2][2] = aT22;
0409 }
0410
0411
0412
0413 inline constexpr void gp_Mat::PreMultiply(const gp_Mat& theOther) noexcept
0414 {
0415 const double aT00 = theOther.myMat[0][0] * myMat[0][0] + theOther.myMat[0][1] * myMat[1][0]
0416 + theOther.myMat[0][2] * myMat[2][0];
0417 const double aT01 = theOther.myMat[0][0] * myMat[0][1] + theOther.myMat[0][1] * myMat[1][1]
0418 + theOther.myMat[0][2] * myMat[2][1];
0419 const double aT02 = theOther.myMat[0][0] * myMat[0][2] + theOther.myMat[0][1] * myMat[1][2]
0420 + theOther.myMat[0][2] * myMat[2][2];
0421 const double aT10 = theOther.myMat[1][0] * myMat[0][0] + theOther.myMat[1][1] * myMat[1][0]
0422 + theOther.myMat[1][2] * myMat[2][0];
0423 const double aT11 = theOther.myMat[1][0] * myMat[0][1] + theOther.myMat[1][1] * myMat[1][1]
0424 + theOther.myMat[1][2] * myMat[2][1];
0425 const double aT12 = theOther.myMat[1][0] * myMat[0][2] + theOther.myMat[1][1] * myMat[1][2]
0426 + theOther.myMat[1][2] * myMat[2][2];
0427 const double aT20 = theOther.myMat[2][0] * myMat[0][0] + theOther.myMat[2][1] * myMat[1][0]
0428 + theOther.myMat[2][2] * myMat[2][0];
0429 const double aT21 = theOther.myMat[2][0] * myMat[0][1] + theOther.myMat[2][1] * myMat[1][1]
0430 + theOther.myMat[2][2] * myMat[2][1];
0431 const double aT22 = theOther.myMat[2][0] * myMat[0][2] + theOther.myMat[2][1] * myMat[1][2]
0432 + theOther.myMat[2][2] * myMat[2][2];
0433 myMat[0][0] = aT00;
0434 myMat[0][1] = aT01;
0435 myMat[0][2] = aT02;
0436 myMat[1][0] = aT10;
0437 myMat[1][1] = aT11;
0438 myMat[1][2] = aT12;
0439 myMat[2][0] = aT20;
0440 myMat[2][1] = aT21;
0441 myMat[2][2] = aT22;
0442 }
0443
0444
0445
0446 inline constexpr gp_Mat gp_Mat::Multiplied(const double theScalar) const noexcept
0447 {
0448 gp_Mat aNewMat(*this);
0449 aNewMat.Multiply(theScalar);
0450 return aNewMat;
0451 }
0452
0453
0454
0455 inline constexpr void gp_Mat::Multiply(const double theScalar) noexcept
0456 {
0457 myMat[0][0] *= theScalar;
0458 myMat[0][1] *= theScalar;
0459 myMat[0][2] *= theScalar;
0460 myMat[1][0] *= theScalar;
0461 myMat[1][1] *= theScalar;
0462 myMat[1][2] *= theScalar;
0463 myMat[2][0] *= theScalar;
0464 myMat[2][1] *= theScalar;
0465 myMat[2][2] *= theScalar;
0466 }
0467
0468
0469
0470 inline constexpr void gp_Mat::Subtract(const gp_Mat& theOther) noexcept
0471 {
0472 myMat[0][0] -= theOther.myMat[0][0];
0473 myMat[0][1] -= theOther.myMat[0][1];
0474 myMat[0][2] -= theOther.myMat[0][2];
0475 myMat[1][0] -= theOther.myMat[1][0];
0476 myMat[1][1] -= theOther.myMat[1][1];
0477 myMat[1][2] -= theOther.myMat[1][2];
0478 myMat[2][0] -= theOther.myMat[2][0];
0479 myMat[2][1] -= theOther.myMat[2][1];
0480 myMat[2][2] -= theOther.myMat[2][2];
0481 }
0482
0483
0484
0485 inline constexpr gp_Mat gp_Mat::Subtracted(const gp_Mat& theOther) const noexcept
0486 {
0487 gp_Mat aNewMat(*this);
0488 aNewMat.Subtract(theOther);
0489 return aNewMat;
0490 }
0491
0492
0493
0494
0495
0496
0497
0498
0499 #if defined(__APPLE__) && (__apple_build_version__ > 9020000)
0500 __attribute__((optnone))
0501 #endif
0502 inline void
0503 gp_Mat::Transpose()
0504 {
0505 std::swap(myMat[0][1], myMat[1][0]);
0506 std::swap(myMat[0][2], myMat[2][0]);
0507 std::swap(myMat[1][2], myMat[2][1]);
0508 }
0509
0510
0511
0512
0513
0514 inline constexpr gp_Mat operator*(const double theScalar, const gp_Mat& theMat3D) noexcept
0515 {
0516 return theMat3D.Multiplied(theScalar);
0517 }
0518
0519 #endif