0024927: Getting rid of "Persistent" functionality -- Storable
[occt.git] / src / gp / gp_Vec.cxx
CommitLineData
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
21#include <gp_Vec.ixx>
22#include <gp.hxx>
23
24Standard_Boolean gp_Vec::IsEqual
25(const gp_Vec& Other,
26 const Standard_Real LinearTolerance,
27 const Standard_Real AngularTolerance) const
28{
29 if (Magnitude () <= LinearTolerance ||
30 Other.Magnitude () <= LinearTolerance) {
31 Standard_Real val = Magnitude() - Other.Magnitude();
32 if (val < 0) val = - val;
33 return val <= LinearTolerance;
34 }
35 else {
36 Standard_Real val = Magnitude() - Other.Magnitude();
37 if (val < 0) val = - val;
38 return val <= LinearTolerance && Angle(Other) <= AngularTolerance;
39 }
40}
41
42void gp_Vec::Mirror (const gp_Vec& V)
43{
44 Standard_Real D = V.coord.Modulus();
45 if (D > gp::Resolution()) {
46 const gp_XYZ& XYZ = V.coord;
47 Standard_Real A = XYZ.X() / D;
48 Standard_Real B = XYZ.Y() / D;
49 Standard_Real C = XYZ.Z() / D;
50 Standard_Real M1 = 2.0 * A * B;
51 Standard_Real M2 = 2.0 * A * C;
52 Standard_Real M3 = 2.0 * B * C;
53 Standard_Real X = coord.X();
54 Standard_Real Y = coord.Y();
55 Standard_Real Z = coord.Z();
56 coord.SetX(((2.0 * A * A) - 1.0) * X + M1 * Y + M2 * Z);
57 coord.SetY(M1 * X + ((2.0 * B * B) - 1.0) * Y + M3 * Z);
58 coord.SetZ(M2 * X + M3 * Y + ((2.0 * C * C) - 1.0) * Z);
59 }
60}
61
62void gp_Vec::Mirror (const gp_Ax1& A1)
63{
64 const gp_XYZ& V = A1.Direction().XYZ();
65 Standard_Real A = V.X();
66 Standard_Real B = V.Y();
67 Standard_Real C = V.Z();
68 Standard_Real X = coord.X();
69 Standard_Real Y = coord.Y();
70 Standard_Real Z = coord.Z();
71 Standard_Real M1 = 2.0 * A * B;
72 Standard_Real M2 = 2.0 * A * C;
73 Standard_Real M3 = 2.0 * B * C;
74 coord.SetX(((2.0 * A * A) - 1.0) * X + M1 * Y + M2 * Z);
75 coord.SetY(M1 * X + ((2.0 * B * B) - 1.0) * Y + M3 * Z);
76 coord.SetZ(M2 * X + M3 * Y + ((2.0 * C * C) - 1.0) * Z);
77}
78
79void gp_Vec::Mirror (const gp_Ax2& A2)
80{
81 gp_XYZ Z = A2.Direction().XYZ();
82 gp_XYZ MirXYZ = Z.Crossed (coord);
83 if (MirXYZ.Modulus() <= gp::Resolution()) { coord.Reverse(); }
84 else {
85 Z.Cross (MirXYZ);
86 Mirror (Z);
87 }
88}
89
90void gp_Vec::Transform(const gp_Trsf& T)
91{
92 if (T.Form() == gp_Identity || T.Form() == gp_Translation) { }
93 else if (T.Form() == gp_PntMirror) { coord.Reverse(); }
94 else if (T.Form() == gp_Scale) { coord.Multiply (T.ScaleFactor()); }
95 else { coord.Multiply (T.VectorialPart()); }
96}
97
98gp_Vec gp_Vec::Mirrored (const gp_Vec& V) const
99{
100 gp_Vec Vres = *this;
101 Vres.Mirror (V);
102 return Vres;
103}
104
105gp_Vec gp_Vec::Mirrored (const gp_Ax1& A1) const
106{
107 gp_Vec Vres = *this;
108 Vres.Mirror (A1);
109 return Vres;
110}
111
112gp_Vec gp_Vec::Mirrored (const gp_Ax2& A2) const
113{
114 gp_Vec Vres = *this;
115 Vres.Mirror (A2);
116 return Vres;
117}