Warning, file /include/opencascade/gp_Dir2d.hxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _gp_Dir2d_HeaderFile
0016 #define _gp_Dir2d_HeaderFile
0017
0018 #include <gp_XY.hxx>
0019 #include <Standard_ConstructionError.hxx>
0020 #include <Standard_DomainError.hxx>
0021 #include <Standard_OutOfRange.hxx>
0022
0023 class gp_Vec2d;
0024 class gp_Ax2d;
0025 class gp_Trsf2d;
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 class gp_Dir2d
0036 {
0037 public:
0038
0039 DEFINE_STANDARD_ALLOC
0040
0041
0042 gp_Dir2d()
0043 : coord (1., 0.)
0044 {}
0045
0046
0047 gp_Dir2d (const gp_Vec2d& theV);
0048
0049
0050 gp_Dir2d (const gp_XY& theCoord);
0051
0052
0053 gp_Dir2d (const Standard_Real theXv, const Standard_Real theYv);
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 void SetCoord (const Standard_Integer theIndex, const Standard_Real theXi);
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 void SetCoord (const Standard_Real theXv, const Standard_Real theYv);
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 void SetX (const Standard_Real theX);
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115 void SetY (const Standard_Real theY);
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 void SetXY (const gp_XY& theCoord);
0131
0132
0133
0134
0135
0136 Standard_Real Coord (const Standard_Integer theIndex) const { return coord.Coord (theIndex); }
0137
0138
0139
0140 void Coord (Standard_Real& theXv, Standard_Real& theYv) const { coord.Coord (theXv, theYv); }
0141
0142
0143 Standard_Real X() const { return coord.X(); }
0144
0145
0146 Standard_Real Y() const { return coord.Y(); }
0147
0148
0149
0150
0151 const gp_XY& XY() const { return coord; }
0152
0153
0154
0155
0156 Standard_Boolean IsEqual (const gp_Dir2d& theOther, const Standard_Real theAngularTolerance) const;
0157
0158
0159
0160
0161 Standard_Boolean IsNormal (const gp_Dir2d& theOther, const Standard_Real theAngularTolerance) const;
0162
0163
0164
0165
0166 Standard_Boolean IsOpposite (const gp_Dir2d& theOther, const Standard_Real theAngularTolerance) const;
0167
0168
0169
0170
0171
0172 Standard_Boolean IsParallel (const gp_Dir2d& theOther, const Standard_Real theAngularTolerance) const;
0173
0174
0175
0176 Standard_EXPORT Standard_Real Angle (const gp_Dir2d& theOther) const;
0177
0178
0179 Standard_NODISCARD Standard_Real Crossed (const gp_Dir2d& theRight) const { return coord.Crossed (theRight.coord); }
0180
0181 Standard_NODISCARD Standard_Real operator ^ (const gp_Dir2d& theRight) const { return Crossed (theRight); }
0182
0183
0184 Standard_Real Dot (const gp_Dir2d& theOther) const { return coord.Dot (theOther.coord); }
0185
0186 Standard_Real operator * (const gp_Dir2d& theOther) const { return Dot (theOther); }
0187
0188 void Reverse() { coord.Reverse(); }
0189
0190
0191 Standard_NODISCARD gp_Dir2d Reversed() const
0192 {
0193 gp_Dir2d aV = *this;
0194 aV.coord.Reverse();
0195 return aV;
0196 }
0197
0198 Standard_NODISCARD gp_Dir2d operator -() const { return Reversed(); }
0199
0200 Standard_EXPORT void Mirror (const gp_Dir2d& theV);
0201
0202
0203
0204
0205 Standard_NODISCARD Standard_EXPORT gp_Dir2d Mirrored (const gp_Dir2d& theV) const;
0206
0207 Standard_EXPORT void Mirror (const gp_Ax2d& theA);
0208
0209
0210
0211
0212 Standard_NODISCARD Standard_EXPORT gp_Dir2d Mirrored (const gp_Ax2d& theA) const;
0213
0214 void Rotate (const Standard_Real Ang);
0215
0216
0217
0218 Standard_NODISCARD gp_Dir2d Rotated (const Standard_Real theAng) const
0219 {
0220 gp_Dir2d aV = *this;
0221 aV.Rotate (theAng);
0222 return aV;
0223 }
0224
0225 Standard_EXPORT void Transform (const gp_Trsf2d& theT);
0226
0227
0228
0229
0230
0231 Standard_NODISCARD gp_Dir2d Transformed (const gp_Trsf2d& theT) const
0232 {
0233 gp_Dir2d aV = *this;
0234 aV.Transform (theT);
0235 return aV;
0236 }
0237
0238
0239 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0240
0241 private:
0242
0243 gp_XY coord;
0244
0245 };
0246
0247 #include <gp_Ax2d.hxx>
0248 #include <gp_Trsf2d.hxx>
0249
0250
0251
0252
0253
0254 inline gp_Dir2d::gp_Dir2d (const gp_Vec2d& theV)
0255 {
0256 const gp_XY& aXY = theV.XY();
0257 Standard_Real aX = aXY.X();
0258 Standard_Real anY = aXY.Y();
0259 Standard_Real aD = sqrt (aX * aX + anY * anY);
0260 Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm");
0261 coord.SetX (aX / aD);
0262 coord.SetY (anY / aD);
0263 }
0264
0265
0266
0267
0268
0269 inline gp_Dir2d::gp_Dir2d (const gp_XY& theXY)
0270 {
0271 Standard_Real aX = theXY.X();
0272 Standard_Real anY = theXY.Y();
0273 Standard_Real aD = sqrt (aX * aX + anY * anY);
0274 Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm");
0275 coord.SetX (aX / aD);
0276 coord.SetY (anY / aD);
0277 }
0278
0279
0280
0281
0282
0283 inline gp_Dir2d::gp_Dir2d (const Standard_Real theXv,
0284 const Standard_Real theYv)
0285 {
0286 Standard_Real aD = sqrt (theXv * theXv + theYv * theYv);
0287 Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d() - input vector has zero norm");
0288 coord.SetX (theXv / aD);
0289 coord.SetY (theYv / aD);
0290 }
0291
0292
0293
0294
0295
0296 inline void gp_Dir2d::SetCoord (const Standard_Integer theIndex,
0297 const Standard_Real theXi)
0298 {
0299 Standard_Real aX = coord.X();
0300 Standard_Real anY = coord.Y();
0301 Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > 2, "gp_Dir2d::SetCoord() - index is out of range [1, 2]");
0302 if (theIndex == 1)
0303 {
0304 aX = theXi;
0305 }
0306 else
0307 {
0308 anY = theXi;
0309 }
0310 Standard_Real aD = sqrt (aX * aX + anY * anY);
0311 Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d::SetCoord() - result vector has zero norm");
0312 coord.SetX (aX / aD);
0313 coord.SetY (anY / aD);
0314 }
0315
0316
0317
0318
0319
0320 inline void gp_Dir2d::SetCoord (const Standard_Real theXv,
0321 const Standard_Real theYv)
0322 {
0323 Standard_Real aD = sqrt (theXv * theXv + theYv * theYv);
0324 Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d::SetCoord() - result vector has zero norm");
0325 coord.SetX (theXv / aD);
0326 coord.SetY (theYv / aD);
0327 }
0328
0329
0330
0331
0332
0333 inline void gp_Dir2d::SetX (const Standard_Real theX)
0334 {
0335 Standard_Real anY = coord.Y();
0336 Standard_Real aD = sqrt (theX * theX + anY * anY);
0337 Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d::SetX() - result vector has zero norm");
0338 coord.SetX (theX / aD);
0339 coord.SetY (anY / aD);
0340 }
0341
0342
0343
0344
0345
0346 inline void gp_Dir2d::SetY (const Standard_Real theY)
0347 {
0348 Standard_Real aX = coord.X();
0349 Standard_Real aD = sqrt (aX * aX + theY * theY);
0350 Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d::SetY() - result vector has zero norm");
0351 coord.SetX (aX / aD);
0352 coord.SetY (theY / aD);
0353 }
0354
0355
0356
0357
0358
0359 inline void gp_Dir2d::SetXY (const gp_XY& theXY)
0360 {
0361 Standard_Real aX = theXY.X();
0362 Standard_Real anY = theXY.Y();
0363 Standard_Real aD = sqrt (aX * aX + anY * anY);
0364 Standard_ConstructionError_Raise_if (aD <= gp::Resolution(), "gp_Dir2d::SetZ() - result vector has zero norm");
0365 coord.SetX (aX / aD);
0366 coord.SetY (anY / aD);
0367 }
0368
0369
0370
0371
0372
0373 inline Standard_Boolean gp_Dir2d::IsEqual (const gp_Dir2d& theOther,
0374 const Standard_Real theAngularTolerance) const
0375 {
0376 Standard_Real anAng = Angle (theOther);
0377 if (anAng < 0)
0378 {
0379 anAng = -anAng;
0380 }
0381 return anAng <= theAngularTolerance;
0382 }
0383
0384
0385
0386
0387
0388 inline Standard_Boolean gp_Dir2d::IsNormal (const gp_Dir2d& theOther,
0389 const Standard_Real theAngularTolerance) const
0390 {
0391 Standard_Real anAng = Angle (theOther);
0392 if (anAng < 0)
0393 {
0394 anAng = -anAng;
0395 }
0396 anAng = M_PI / 2.0 - anAng;
0397 if (anAng < 0)
0398 {
0399 anAng = -anAng;
0400 }
0401 return anAng <= theAngularTolerance;
0402 }
0403
0404
0405
0406
0407
0408 inline Standard_Boolean gp_Dir2d::IsOpposite (const gp_Dir2d& theOther,
0409 const Standard_Real theAngularTolerance) const
0410 {
0411 Standard_Real anAng = Angle (theOther);
0412 if (anAng < 0)
0413 {
0414 anAng = -anAng;
0415 }
0416 return M_PI - anAng <= theAngularTolerance;
0417 }
0418
0419
0420
0421
0422
0423 inline Standard_Boolean gp_Dir2d::IsParallel (const gp_Dir2d& theOther,
0424 const Standard_Real theAngularTolerance) const
0425 {
0426 Standard_Real anAng = Angle (theOther);
0427 if (anAng < 0)
0428 {
0429 anAng = -anAng;
0430 }
0431 return anAng <= theAngularTolerance || M_PI - anAng <= theAngularTolerance;
0432 }
0433
0434
0435
0436
0437
0438 inline void gp_Dir2d::Rotate (const Standard_Real theAng)
0439 {
0440 gp_Trsf2d aT;
0441 aT.SetRotation (gp_Pnt2d (0.0, 0.0), theAng);
0442 coord.Multiply (aT.HVectorialPart());
0443 }
0444
0445 #endif