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