b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
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 |
18 | |
19 | #define No_Standard_OutOfRange |
20 | |
42cf5bc1 |
21 | |
7fd59977 |
22 | #include <gp.hxx> |
42cf5bc1 |
23 | #include <gp_Ax1.hxx> |
24 | #include <gp_Ax2.hxx> |
25 | #include <gp_Dir.hxx> |
26 | #include <gp_Pnt.hxx> |
27 | #include <gp_Trsf.hxx> |
28 | #include <gp_Vec.hxx> |
29 | #include <gp_VectorWithNullMagnitude.hxx> |
30 | #include <gp_XYZ.hxx> |
31 | #include <Standard_ConstructionError.hxx> |
32 | #include <Standard_DomainError.hxx> |
33 | #include <Standard_OutOfRange.hxx> |
7fd59977 |
34 | |
35 | Standard_Boolean gp_Vec::IsEqual |
36 | (const gp_Vec& Other, |
37 | const Standard_Real LinearTolerance, |
38 | const Standard_Real AngularTolerance) const |
39 | { |
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; |
45 | } |
46 | else { |
47 | Standard_Real val = Magnitude() - Other.Magnitude(); |
48 | if (val < 0) val = - val; |
49 | return val <= LinearTolerance && Angle(Other) <= AngularTolerance; |
50 | } |
51 | } |
52 | |
53 | void gp_Vec::Mirror (const gp_Vec& V) |
54 | { |
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); |
70 | } |
71 | } |
72 | |
73 | void gp_Vec::Mirror (const gp_Ax1& A1) |
74 | { |
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); |
88 | } |
89 | |
90 | void gp_Vec::Mirror (const gp_Ax2& A2) |
91 | { |
92 | gp_XYZ Z = A2.Direction().XYZ(); |
93 | gp_XYZ MirXYZ = Z.Crossed (coord); |
94 | if (MirXYZ.Modulus() <= gp::Resolution()) { coord.Reverse(); } |
95 | else { |
96 | Z.Cross (MirXYZ); |
97 | Mirror (Z); |
98 | } |
99 | } |
100 | |
101 | void gp_Vec::Transform(const gp_Trsf& T) |
102 | { |
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()); } |
107 | } |
108 | |
109 | gp_Vec gp_Vec::Mirrored (const gp_Vec& V) const |
110 | { |
111 | gp_Vec Vres = *this; |
112 | Vres.Mirror (V); |
113 | return Vres; |
114 | } |
115 | |
116 | gp_Vec gp_Vec::Mirrored (const gp_Ax1& A1) const |
117 | { |
118 | gp_Vec Vres = *this; |
119 | Vres.Mirror (A1); |
120 | return Vres; |
121 | } |
122 | |
123 | gp_Vec gp_Vec::Mirrored (const gp_Ax2& A2) const |
124 | { |
125 | gp_Vec Vres = *this; |
126 | Vres.Mirror (A2); |
127 | return Vres; |
128 | } |