0024171: Eliminate CLang compiler warning -Wreorder
[occt.git] / src / ProjLib / ProjLib_Cylinder.cxx
1 // Created on: 1993-08-24
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <Standard_NotImplemented.hxx>
23
24 #include <ProjLib_Cylinder.ixx>
25
26 #include <Precision.hxx>
27 #include <gp_Pln.hxx>
28 #include <gp_Trsf.hxx>
29 #include <gp_Vec.hxx>
30 #include <gp_Ax3.hxx>
31 #include <gp_Vec2d.hxx>
32
33 //=======================================================================
34 //function : ProjLib_Cylinder
35 //purpose  : 
36 //=======================================================================
37
38 ProjLib_Cylinder::ProjLib_Cylinder()
39 {
40 }
41
42
43 //=======================================================================
44 //function : ProjLib_Cylinder
45 //purpose  : 
46 //=======================================================================
47
48 ProjLib_Cylinder::ProjLib_Cylinder(const gp_Cylinder& Cyl)
49 {
50   Init(Cyl);
51 }
52
53
54 //=======================================================================
55 //function : ProjLib_Cylinder
56 //purpose  : 
57 //=======================================================================
58
59 ProjLib_Cylinder::ProjLib_Cylinder(const gp_Cylinder& Cyl, const gp_Lin& L)
60 {
61   Init(Cyl);
62   Project(L);
63 }
64
65
66 //=======================================================================
67 //function : ProjLib_Cylinder
68 //purpose  : 
69 //=======================================================================
70
71 ProjLib_Cylinder::ProjLib_Cylinder(const gp_Cylinder& Cyl, const gp_Circ& C)
72 {
73   Init(Cyl);
74   Project(C);
75 }
76
77
78 //=======================================================================
79 //function : ProjLib_Cylinder
80 //purpose  : 
81 //=======================================================================
82
83 ProjLib_Cylinder::ProjLib_Cylinder(const gp_Cylinder& Cyl, const gp_Elips& E)
84 {
85   Init(Cyl);
86   Project(E);
87 }
88
89
90 //=======================================================================
91 //function : Init
92 //purpose  : 
93 //=======================================================================
94
95 void  ProjLib_Cylinder::Init(const gp_Cylinder& Cyl)
96 {
97   myType = GeomAbs_OtherCurve;
98   myCylinder = Cyl;
99   myIsPeriodic = Standard_False;
100   isDone = Standard_False;
101 }
102
103
104 //=======================================================================
105 //function : EvalPnt2d / EvalDir2d
106 //purpose  : returns the Projected Pnt / Dir in the parametrization range
107 //           of myPlane.
108 //=======================================================================
109
110 static gp_Pnt2d EvalPnt2d( const gp_Pnt& P, const gp_Cylinder& Cy )
111 {
112   gp_Vec OP( Cy.Location(),P);
113   Standard_Real X = OP.Dot(gp_Vec(Cy.Position().XDirection()));
114   Standard_Real Y = OP.Dot(gp_Vec(Cy.Position().YDirection()));
115   Standard_Real Z = OP.Dot(gp_Vec(Cy.Position().Direction()));
116   Standard_Real U ;
117
118   if ( Abs(X) > Precision::PConfusion() ||
119        Abs(Y) > Precision::PConfusion() ) {
120     U = ATan2(Y,X);
121   }
122   else {
123     U = 0.;
124   }
125   return gp_Pnt2d( U, Z);
126 }
127
128
129
130 //=======================================================================
131 //function : Project
132 //purpose  : 
133 //=======================================================================
134
135 void  ProjLib_Cylinder::Project(const gp_Lin& L)
136 {
137   myType = GeomAbs_Line;
138
139   gp_Pnt2d P2d = EvalPnt2d(L.Location(),myCylinder);
140   if ( P2d.X() < 0.) {
141     P2d.SetX(P2d.X()+2*M_PI);
142   }
143   Standard_Real Signe 
144     = L.Direction().Dot(myCylinder.Position().Direction());
145   Signe = (Signe > 0.) ? 1. : -1.;
146   gp_Dir2d D2d(0., Signe);
147   
148   myLin = gp_Lin2d( P2d, D2d);
149   isDone = Standard_True;
150 }
151
152
153 //=======================================================================
154 //function : Project
155 //purpose  : 
156 //=======================================================================
157
158 void  ProjLib_Cylinder::Project(const gp_Circ& C)
159 {
160   myType = GeomAbs_Line;
161
162   gp_Dir ZCyl = myCylinder.Position().XDirection().Crossed
163     (myCylinder.Position().YDirection());
164   gp_Dir ZCir = C.Position().XDirection().Crossed
165     (C.Position().YDirection());
166
167   Standard_Real U = myCylinder.Position().XDirection()
168     .AngleWithRef(C.Position().XDirection(), ZCyl);
169
170   gp_Vec OP( myCylinder.Location(),C.Location());
171   Standard_Real V = OP.Dot(gp_Vec(myCylinder.Position().Direction()));
172
173
174   gp_Pnt2d P2d1 (U, V);
175   gp_Dir2d D2d;
176   if ( ZCyl.Dot(ZCir) > 0.) 
177     D2d.SetCoord(1., 0.);
178   else
179     D2d.SetCoord(-1., 0.);
180
181   myLin = gp_Lin2d(P2d1, D2d);
182   isDone = Standard_True;
183 }
184
185
186 //=======================================================================
187 //function : Project
188 //purpose  : 
189 //=======================================================================
190
191 //void  ProjLib_Cylinder::Project(const gp_Elips& E)
192 void  ProjLib_Cylinder::Project(const gp_Elips& )
193 {
194   // Pour de vastes raisons de periodicite mal gerees,
195   // la projection d`une ellipse sur un cylindre sera passee aux approx.
196   
197   
198 }
199
200 void  ProjLib_Cylinder::Project(const gp_Parab& P)
201 {
202  ProjLib_Projector::Project(P);
203 }
204
205 void  ProjLib_Cylinder::Project(const gp_Hypr& H)
206 {
207  ProjLib_Projector::Project(H);
208 }
209