File indexing completed on 2026-09-22 08:58:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _gp_Trsf2d_HeaderFile
0016 #define _gp_Trsf2d_HeaderFile
0017
0018 #include <gp_TrsfForm.hxx>
0019 #include <gp_Mat2d.hxx>
0020 #include <gp_XY.hxx>
0021 #include <Standard_OutOfRange.hxx>
0022
0023 class gp_Trsf;
0024 class gp_Pnt2d;
0025 class gp_Ax2d;
0026 class gp_Vec2d;
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 class gp_Trsf2d
0045 {
0046 public:
0047 DEFINE_STANDARD_ALLOC
0048
0049
0050 constexpr gp_Trsf2d() noexcept;
0051
0052
0053
0054 gp_Trsf2d(const gp_Trsf& theT);
0055
0056
0057
0058 void SetMirror(const gp_Pnt2d& theP) noexcept;
0059
0060
0061
0062 Standard_EXPORT void SetMirror(const gp_Ax2d& theA) noexcept;
0063
0064
0065
0066
0067 void SetRotation(const gp_Pnt2d& theP, const double theAng);
0068
0069
0070
0071 void SetScale(const gp_Pnt2d& theP, const double theS);
0072
0073
0074
0075 Standard_EXPORT void SetTransformation(const gp_Ax2d& theFromSystem1,
0076 const gp_Ax2d& theToSystem2);
0077
0078
0079
0080
0081
0082 Standard_EXPORT void SetTransformation(const gp_Ax2d& theToSystem);
0083
0084
0085
0086 void SetTranslation(const gp_Vec2d& theV);
0087
0088
0089
0090 void SetTranslation(const gp_Pnt2d& theP1, const gp_Pnt2d& theP2);
0091
0092
0093 Standard_EXPORT void SetTranslationPart(const gp_Vec2d& theV);
0094
0095
0096 Standard_EXPORT void SetScaleFactor(const double theS);
0097
0098
0099
0100 constexpr bool IsNegative() const noexcept { return (matrix.Determinant() < 0.0); }
0101
0102
0103
0104
0105
0106 constexpr gp_TrsfForm Form() const noexcept { return shape; }
0107
0108
0109 constexpr double ScaleFactor() const noexcept { return scale; }
0110
0111
0112 constexpr const gp_XY& TranslationPart() const noexcept { return loc; }
0113
0114
0115
0116 Standard_EXPORT gp_Mat2d VectorialPart() const;
0117
0118
0119
0120
0121
0122 constexpr const gp_Mat2d& HVectorialPart() const noexcept { return matrix; }
0123
0124
0125
0126 Standard_EXPORT double RotationPart() const;
0127
0128
0129
0130
0131 constexpr double Value(const int theRow, const int theCol) const;
0132
0133 Standard_EXPORT void Invert();
0134
0135
0136
0137
0138
0139 [[nodiscard]] gp_Trsf2d Inverted() const
0140 {
0141 gp_Trsf2d aT = *this;
0142 aT.Invert();
0143 return aT;
0144 }
0145
0146 [[nodiscard]] gp_Trsf2d Multiplied(const gp_Trsf2d& theT) const
0147 {
0148 gp_Trsf2d aTresult(*this);
0149 aTresult.Multiply(theT);
0150 return aTresult;
0151 }
0152
0153 [[nodiscard]] gp_Trsf2d operator*(const gp_Trsf2d& theT) const { return Multiplied(theT); }
0154
0155
0156
0157 Standard_EXPORT void Multiply(const gp_Trsf2d& theT);
0158
0159 void operator*=(const gp_Trsf2d& theT) { Multiply(theT); }
0160
0161
0162
0163 Standard_EXPORT void PreMultiply(const gp_Trsf2d& theT);
0164
0165 Standard_EXPORT void Power(const int theN);
0166
0167
0168
0169
0170
0171
0172
0173
0174 gp_Trsf2d Powered(const int theN)
0175 {
0176 gp_Trsf2d aT = *this;
0177 aT.Power(theN);
0178 return aT;
0179 }
0180
0181 constexpr void Transforms(double& theX, double& theY) const noexcept;
0182
0183
0184 constexpr void Transforms(gp_XY& theCoord) const noexcept;
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196 Standard_EXPORT void SetValues(const double a11,
0197 const double a12,
0198 const double a13,
0199 const double a21,
0200 const double a22,
0201 const double a23);
0202
0203 friend class gp_GTrsf2d;
0204
0205 protected:
0206
0207 Standard_EXPORT void Orthogonalize();
0208
0209 private:
0210 double scale;
0211 gp_TrsfForm shape;
0212 gp_Mat2d matrix;
0213 gp_XY loc;
0214 };
0215
0216 #include <gp_Trsf.hxx>
0217 #include <gp_Pnt2d.hxx>
0218
0219
0220
0221 inline constexpr gp_Trsf2d::gp_Trsf2d() noexcept
0222 : scale(1.0),
0223 shape(gp_Identity),
0224
0225 loc(0.0, 0.0)
0226 {
0227 matrix.SetIdentity();
0228 }
0229
0230
0231
0232 inline gp_Trsf2d::gp_Trsf2d(const gp_Trsf& theT)
0233 : scale(theT.ScaleFactor()),
0234 shape(theT.Form()),
0235 loc(theT.TranslationPart().X(), theT.TranslationPart().Y())
0236 {
0237 const gp_Mat& M = theT.HVectorialPart();
0238 matrix(1, 1) = M(1, 1);
0239 matrix(1, 2) = M(1, 2);
0240 matrix(2, 1) = M(2, 1);
0241 matrix(2, 2) = M(2, 2);
0242 }
0243
0244
0245
0246 inline void gp_Trsf2d::SetRotation(const gp_Pnt2d& theP, const double theAng)
0247 {
0248 shape = gp_Rotation;
0249 scale = 1.0;
0250 loc = theP.XY();
0251 loc.Reverse();
0252 matrix.SetRotation(theAng);
0253 loc.Multiply(matrix);
0254 loc.Add(theP.XY());
0255 }
0256
0257
0258
0259 inline void gp_Trsf2d::SetMirror(const gp_Pnt2d& theP) noexcept
0260 {
0261 shape = gp_PntMirror;
0262 scale = -1.0;
0263 matrix.SetIdentity();
0264 loc = theP.XY();
0265 loc.Multiply(2.0);
0266 }
0267
0268
0269
0270 inline void gp_Trsf2d::SetScale(const gp_Pnt2d& theP, const double theS)
0271 {
0272 shape = gp_Scale;
0273 scale = theS;
0274 matrix.SetIdentity();
0275 loc = theP.XY();
0276 loc.Multiply(1.0 - theS);
0277 }
0278
0279
0280
0281 inline void gp_Trsf2d::SetTranslation(const gp_Vec2d& theV)
0282 {
0283 shape = gp_Translation;
0284 scale = 1.0;
0285 matrix.SetIdentity();
0286 loc = theV.XY();
0287 }
0288
0289
0290
0291 inline void gp_Trsf2d::SetTranslation(const gp_Pnt2d& theP1, const gp_Pnt2d& theP2)
0292 {
0293 shape = gp_Translation;
0294 scale = 1.0;
0295 matrix.SetIdentity();
0296 loc = (theP2.XY()).Subtracted(theP1.XY());
0297 }
0298
0299
0300
0301 inline constexpr double gp_Trsf2d::Value(const int theRow, const int theCol) const
0302 {
0303 Standard_OutOfRange_Raise_if(theRow < 1 || theRow > 2 || theCol < 1 || theCol > 3, " ");
0304 if (theCol < 3)
0305 {
0306 return scale * matrix.myMat[theRow - 1][theCol - 1];
0307 }
0308 else
0309 {
0310 return loc.Coord(theRow);
0311 }
0312 }
0313
0314
0315
0316 inline constexpr void gp_Trsf2d::Transforms(double& theX, double& theY) const noexcept
0317 {
0318 gp_XY aDoublet(theX, theY);
0319 aDoublet.Multiply(matrix);
0320 if (scale != 1.0)
0321 {
0322 aDoublet.Multiply(scale);
0323 }
0324 aDoublet.Add(loc);
0325 aDoublet.Coord(theX, theY);
0326 }
0327
0328
0329
0330 inline constexpr void gp_Trsf2d::Transforms(gp_XY& theCoord) const noexcept
0331 {
0332 theCoord.Multiply(matrix);
0333 if (scale != 1.0)
0334 {
0335 theCoord.Multiply(scale);
0336 }
0337 theCoord.Add(loc);
0338 }
0339
0340 #endif