0023620: Follow up of 0022939 - make Bezier curve/surface evaluation thread-safe
[occt.git] / src / Geom / Geom_Direction.cxx
1 // Created on: 1993-03-10
2 // Created by: JCV
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Geom_Direction.hxx>
19 #include <Geom_Geometry.hxx>
20 #include <Geom_Vector.hxx>
21 #include <gp.hxx>
22 #include <gp_Dir.hxx>
23 #include <gp_Trsf.hxx>
24 #include <Standard_ConstructionError.hxx>
25 #include <Standard_Type.hxx>
26
27 typedef Geom_Direction         Direction;
28 typedef Geom_Vector            Vector;
29 typedef gp_Ax1  Ax1;
30 typedef gp_Ax2  Ax2;
31 typedef gp_Pnt  Pnt;
32 typedef gp_Trsf Trsf;
33
34
35
36 //=======================================================================
37 //function : Copy
38 //purpose  : 
39 //=======================================================================
40
41 Handle(Geom_Geometry) Geom_Direction::Copy() const {
42
43   Handle(Geom_Direction) D;
44   D = new Direction (gpVec);
45   return D; 
46 }
47
48 //=======================================================================
49 //function : Geom_Direction
50 //purpose  : 
51 //=======================================================================
52
53 Geom_Direction::Geom_Direction (const Standard_Real X, const Standard_Real Y, const Standard_Real Z) {
54
55    Standard_Real D = sqrt (X * X + Y * Y + Z * Z);
56    Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
57    gpVec = gp_Vec (X/D, Y/D, Z/D);
58 }
59
60 Geom_Direction::Geom_Direction (const gp_Dir& V)  { gpVec = V; }
61
62 void Geom_Direction::SetDir (const gp_Dir& V)     { gpVec = V; }
63
64 gp_Dir Geom_Direction::Dir () const               {  return gpVec; }
65
66 Standard_Real Geom_Direction::Magnitude () const           { return 1.0; }
67
68 Standard_Real Geom_Direction::SquareMagnitude () const     { return 1.0; }
69
70 void Geom_Direction::SetCoord (const Standard_Real X, const Standard_Real Y, const Standard_Real Z) {
71
72   Standard_Real D = Sqrt (X * X + Y * Y + Z * Z);
73   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
74   gpVec = gp_Vec(X/D, Y/D, Z/D);
75 }
76
77
78 void Geom_Direction::SetX (const Standard_Real X) {
79
80   Standard_Real D = Sqrt (X * X + gpVec.Y() * gpVec.Y() + gpVec.Z() * gpVec.Z());
81   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
82   gpVec = gp_Vec (X/D, gpVec.Y()/D, gpVec.Z()/D);
83 }
84
85
86 void Geom_Direction::SetY (const Standard_Real Y) {
87
88   Standard_Real D = Sqrt (gpVec.X() * gpVec.X() + Y * Y + gpVec.Z() * gpVec.Z());
89   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
90   gpVec = gp_Vec (gpVec.X()/D, Y/D, gpVec.Z()/D);
91 }
92
93
94 void Geom_Direction::SetZ (const Standard_Real Z) {
95
96   Standard_Real D = Sqrt (gpVec.X() * gpVec.X() + gpVec.Y() * gpVec.Y() + Z * Z);
97   Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
98   gpVec = gp_Vec (gpVec.X()/D, gpVec.Y()/D, Z/D);
99 }
100
101
102 void Geom_Direction::Cross (const Handle(Geom_Vector)& Other) {
103
104   gp_Dir V (gpVec.Crossed(Other->Vec()));
105   gpVec = V;
106 }
107
108
109 void Geom_Direction::CrossCross (
110 const Handle(Geom_Vector)& V1, const Handle(Geom_Vector)& V2) {
111
112   gp_Dir V (gpVec.CrossCrossed (V1->Vec(), V2->Vec()));
113   gpVec = V;
114 }
115
116
117 Handle(Geom_Vector) Geom_Direction::Crossed (const Handle(Geom_Vector)& Other)
118 const {
119
120    gp_Dir V (gpVec.Crossed (Other->Vec()));
121    return new Direction (V);
122 }
123
124
125 Handle(Geom_Vector) Geom_Direction::CrossCrossed (
126 const Handle(Geom_Vector)& V1, const Handle(Geom_Vector)& V2) const {
127
128   gp_Dir V (gpVec.CrossCrossed (V1->Vec(), V2->Vec()));
129   return new Direction (V);
130 }
131
132
133 void Geom_Direction::Transform (const gp_Trsf& T) { 
134
135   gp_Dir V (gpVec);
136   V.Transform (T);
137   gpVec = V;
138 }