1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 // JCV 30/08/90 Modif passage version C++ 2.0 sur Sun
16 // JCV 1/10/90 Changement de nom du package vgeom -> gp
17 // JCV 07/12/90 Modifs suite a l'introduction des classes XYZ et Mat dans gp
19 #define No_Standard_OutOfRange
27 #include <gp_Trsf.hxx>
29 #include <gp_VectorWithNullMagnitude.hxx>
31 #include <Standard_ConstructionError.hxx>
32 #include <Standard_DomainError.hxx>
33 #include <Standard_OutOfRange.hxx>
35 Standard_Boolean gp_Vec::IsEqual
37 const Standard_Real LinearTolerance,
38 const Standard_Real AngularTolerance) const
40 if (Magnitude () <= LinearTolerance ||
41 Other.Magnitude () <= LinearTolerance) {
42 Standard_Real val = Magnitude() - Other.Magnitude();
43 if (val < 0) val = - val;
44 return val <= LinearTolerance;
47 Standard_Real val = Magnitude() - Other.Magnitude();
48 if (val < 0) val = - val;
49 return val <= LinearTolerance && Angle(Other) <= AngularTolerance;
53 void gp_Vec::Mirror (const gp_Vec& V)
55 Standard_Real D = V.coord.Modulus();
56 if (D > gp::Resolution()) {
57 const gp_XYZ& XYZ = V.coord;
58 Standard_Real A = XYZ.X() / D;
59 Standard_Real B = XYZ.Y() / D;
60 Standard_Real C = XYZ.Z() / D;
61 Standard_Real M1 = 2.0 * A * B;
62 Standard_Real M2 = 2.0 * A * C;
63 Standard_Real M3 = 2.0 * B * C;
64 Standard_Real X = coord.X();
65 Standard_Real Y = coord.Y();
66 Standard_Real Z = coord.Z();
67 coord.SetX(((2.0 * A * A) - 1.0) * X + M1 * Y + M2 * Z);
68 coord.SetY(M1 * X + ((2.0 * B * B) - 1.0) * Y + M3 * Z);
69 coord.SetZ(M2 * X + M3 * Y + ((2.0 * C * C) - 1.0) * Z);
73 void gp_Vec::Mirror (const gp_Ax1& A1)
75 const gp_XYZ& V = A1.Direction().XYZ();
76 Standard_Real A = V.X();
77 Standard_Real B = V.Y();
78 Standard_Real C = V.Z();
79 Standard_Real X = coord.X();
80 Standard_Real Y = coord.Y();
81 Standard_Real Z = coord.Z();
82 Standard_Real M1 = 2.0 * A * B;
83 Standard_Real M2 = 2.0 * A * C;
84 Standard_Real M3 = 2.0 * B * C;
85 coord.SetX(((2.0 * A * A) - 1.0) * X + M1 * Y + M2 * Z);
86 coord.SetY(M1 * X + ((2.0 * B * B) - 1.0) * Y + M3 * Z);
87 coord.SetZ(M2 * X + M3 * Y + ((2.0 * C * C) - 1.0) * Z);
90 void gp_Vec::Mirror (const gp_Ax2& A2)
92 gp_XYZ Z = A2.Direction().XYZ();
93 gp_XYZ MirXYZ = Z.Crossed (coord);
94 if (MirXYZ.Modulus() <= gp::Resolution()) { coord.Reverse(); }
101 void gp_Vec::Transform(const gp_Trsf& T)
103 if (T.Form() == gp_Identity || T.Form() == gp_Translation) { }
104 else if (T.Form() == gp_PntMirror) { coord.Reverse(); }
105 else if (T.Form() == gp_Scale) { coord.Multiply (T.ScaleFactor()); }
106 else { coord.Multiply (T.VectorialPart()); }
109 gp_Vec gp_Vec::Mirrored (const gp_Vec& V) const
116 gp_Vec gp_Vec::Mirrored (const gp_Ax1& A1) const
123 gp_Vec gp_Vec::Mirrored (const gp_Ax2& A2) const