0024096: Eliminate compiler warning C4505 in MSVC++ with warning level 4
[occt.git] / src / ProjLib / ProjLib_Cone.cxx
CommitLineData
b311480e 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
7fd59977 21
22
23
24#include <ProjLib_Cone.ixx>
25
26#include <Precision.hxx>
27#include <gp.hxx>
28#include <gp_Vec.hxx>
29#include <gp_Trsf.hxx>
30#include <gp_Vec2d.hxx>
31#include <ElSLib.hxx>
32
33//=======================================================================
34//function : ProjLib_Cone
35//purpose :
36//=======================================================================
37
38ProjLib_Cone::ProjLib_Cone()
39{
40}
41
42
43//=======================================================================
44//function : ProjLib_Cone
45//purpose :
46//=======================================================================
47
48ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co)
49{
50 Init(Co);
51}
52
53
54//=======================================================================
55//function : ProjLib_Cone
56//purpose :
57//=======================================================================
58
59ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co, const gp_Lin& L)
60{
61 Init(Co);
62 Project(L);
63}
64
65
66//=======================================================================
67//function : ProjLib_Cone
68//purpose :
69//=======================================================================
70
71ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co, const gp_Circ& C)
72{
73 Init(Co);
74 Project(C);
75}
76
77
78//=======================================================================
79//function : Init
80//purpose :
81//=======================================================================
82
83void ProjLib_Cone::Init(const gp_Cone& Co)
84{
85 myType = GeomAbs_OtherCurve;
86 myCone = Co;
87 myIsPeriodic = Standard_False;
88 isDone = Standard_False;
89}
90
7fd59977 91//=======================================================================
92//function : Project
93//purpose :
94//=======================================================================
95
96void ProjLib_Cone::Project(const gp_Lin& L)
97{
98
99 Standard_Real U,V;
100
101 // Compute V
102 V = gp_Vec(myCone.Location(),L.Location())
103 .Dot(gp_Vec(myCone.Position().Direction()));
104 V /= Cos( myCone.SemiAngle());
105
106 // Compute U
107 gp_Ax3 CPos = myCone.Position();
108 gp_Dir ZCone = CPos.XDirection() ^ CPos.YDirection();
109
110 gp_Ax3 RightHanded(CPos.Location(), ZCone, CPos.XDirection());
111 gp_Trsf T;
112 T.SetTransformation(RightHanded);
113
114 gp_Dir D = L.Position().Direction();
115 D.Transform(T);
116
117 if ( D.Z() < 0.) D.Reverse();
118 D.SetCoord(3, 0.);
119 U = gp::DX().AngleWithRef( D, gp::DZ());
120
121 Standard_Integer a1 =
122 (ZCone.IsEqual(CPos.Direction(), Precision::Angular())) ? 1 : -1;
123 Standard_Integer a2 =
124 (myCone.SemiAngle() > 0) ? 1 : -1;
c6541a0c 125 if ( ( a1 * a2) == -1) U -= M_PI;
7fd59977 126
c6541a0c 127 if ( U < 0.) U += 2.*M_PI;
7fd59977 128
129 gp_Pnt P;
130 gp_Vec Vu, Vv;
131
132 ElSLib::ConeD1(U, V, CPos, myCone.RefRadius(), myCone.SemiAngle(),
133 P, Vu, Vv);
134
135 if(Vv.IsParallel(gp_Vec(L.Position().Direction()), Precision::Angular())) {
136
137 myType = GeomAbs_Line;
138
139 gp_Pnt2d P2d(U,V);
140
141 Standard_Real Signe = L.Direction().Dot(myCone.Position().Direction());
142 Signe = (Signe > 0.) ? 1. : -1.;
143 gp_Dir2d D2d(0., Signe);
144
145 myLin = gp_Lin2d( P2d, D2d);
146
147 isDone = Standard_True;
148 }
149
150}
151
152
153//=======================================================================
154//function : Project
155//purpose :
156//=======================================================================
157
158void ProjLib_Cone::Project(const gp_Circ& C)
159{
160 myType = GeomAbs_Line;
161
162 gp_Ax3 ConePos = myCone.Position();
163 gp_Ax3 CircPos = C.Position();
164
165 gp_Dir ZCone = ConePos.XDirection().Crossed(ConePos.YDirection());
166 gp_Dir ZCir = CircPos.XDirection().Crossed(CircPos.YDirection());
167
168 Standard_Real U, V;
169 Standard_Real x = ConePos.XDirection().Dot(CircPos.XDirection());
170 Standard_Real y = ConePos.YDirection().Dot(CircPos.XDirection());
171 Standard_Real z
172 = gp_Vec(myCone.Location(),C.Location()).Dot(ConePos.Direction());
173
174 // pour trouver le point U V, on reprend le code de ElSLib
175 // sans appliquer la Trsf au point ( aller retour inutile).
176 if ( x == 0.0 && y == 0.0 ) {
177 U = 0.;
178 }
179 else if ( -myCone.RefRadius() > z * Tan(myCone.SemiAngle())) {
180 U = ATan2(-y, -x);
181 }
182 else {
183 U = ATan2( y, x);
184 }
c6541a0c 185 if ( U < 0.) U += 2*M_PI;
7fd59977 186
187 V = z / Cos(myCone.SemiAngle());
188
189 gp_Pnt2d P2d1 (U, V);
190 gp_Dir2d D2d;
191 if ( ZCone.Dot(ZCir) > 0.)
192 D2d.SetCoord(1., 0.);
193 else
194 D2d.SetCoord(-1., 0.);
195
196 myLin = gp_Lin2d(P2d1, D2d);
197 isDone = Standard_True;
198}
199
200void ProjLib_Cone::Project(const gp_Elips& E)
201{
202 ProjLib_Projector::Project(E);
203}
204
205void ProjLib_Cone::Project(const gp_Parab& P)
206{
207 ProjLib_Projector::Project(P);
208}
209
210void ProjLib_Cone::Project(const gp_Hypr& H)
211{
212 ProjLib_Projector::Project(H);
213}
214