0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / IntCurve / IntCurve_IntConicConic_Tool.cxx
CommitLineData
b311480e 1// Created on: 1992-05-06
2// Created by: Laurent BUCHARD
3// Copyright (c) 1992-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <IntCurve_IntConicConic_Tool.hxx>
18#include <gp.hxx>
19
20
21#define TOLERANCE_ANGULAIRE 0.00000001
22
23
24
25//======================================================================
26//=== R e s s o u r c e s G e n e r a l e s ===
27//======================================================================
28
29void Determine_Transition_LC(const IntRes2d_Position Pos1,
30 gp_Vec2d& Tan1,
31 const gp_Vec2d& Norm1,
32 IntRes2d_Transition& T1,
33 const IntRes2d_Position Pos2,
34 gp_Vec2d& Tan2,
35 const gp_Vec2d& Norm2,
36 IntRes2d_Transition& T2,
37 const Standard_Real ) {
38
39
40 Standard_Real sgn=Tan1.Crossed(Tan2);
41 Standard_Real norm=Tan1.Magnitude()*Tan2.Magnitude();
42
43 if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) { // Transition TOUCH #########
44 Standard_Boolean opos=(Tan1.Dot(Tan2))<0;
45
46 gp_Vec2d Norm;
47// Modified by Sergey KHROMOV - Thu Nov 2 17:57:15 2000 Begin
48 Tan1.Normalize();
49// Modified by Sergey KHROMOV - Thu Nov 2 17:57:16 2000 End
50 Norm.SetCoord(-Tan1.Y(),Tan1.X());
51
52 Standard_Real Val1=Norm.Dot(Norm1);
53 Standard_Real Val2=Norm.Dot(Norm2);
54
55 if (Abs(Val1-Val2) <= gp::Resolution()) {
56 T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
57 T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
58 }
59 else if (Val2 > Val1) {
60 T2.SetValue(Standard_True,Pos2,IntRes2d_Inside,opos);
61 if (opos) { T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos); }
62 else { T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos); }
63 }
64 else { // Val1 > Val2
65 T2.SetValue(Standard_True,Pos2,IntRes2d_Outside,opos);
66 if (opos) { T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos); }
67 else { T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos); }
68 }
69 }
70 else if (sgn<0) {
71 T1.SetValue(Standard_False,Pos1,IntRes2d_In);
72 T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
73 }
74 else {
75 T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
76 T2.SetValue(Standard_False,Pos2,IntRes2d_In);
77 }
78}
79//----------------------------------------------------------------------
80Standard_Real NormalizeOnCircleDomain(const Standard_Real _Param
81 ,const IntRes2d_Domain& TheDomain) {
82 Standard_Real Param=_Param;
83 while(Param<TheDomain.FirstParameter()) {
84 Param+=PIpPI;
85 }
86 while(Param>TheDomain.LastParameter()) {
87 Param-=PIpPI;
88 }
89 return(Param);
90}
91//----------------------------------------------------------------------
92PeriodicInterval PeriodicInterval::FirstIntersection(PeriodicInterval& PInter)
93{
94 Standard_Real a,b;
95 if(PInter.isnull || isnull) {
96 PeriodicInterval PourSGI; return(PourSGI);
97 }
98 else {
99 if(Length() >= PIpPI)
100 return(PeriodicInterval(PInter.Binf,PInter.Bsup));
101 if(PInter.Length()>=PIpPI)
102 return(PeriodicInterval(Binf,Bsup));
103 if(PInter.Bsup<=Binf) {
104 while(PInter.Binf <= Binf && PInter.Bsup <= Binf) {
105 PInter.Binf+=PIpPI; PInter.Bsup+=PIpPI;
106 }
107 }
108 if(PInter.Binf >= Bsup) {
109 while(PInter.Binf >=Bsup && PInter.Bsup >= Bsup) {
110 PInter.Binf-=PIpPI; PInter.Bsup-=PIpPI;
111 }
112 }
113 if((PInter.Bsup < Binf) || (PInter.Binf > Bsup)) {
114 PeriodicInterval PourSGI; return(PourSGI);
115 }
116 }
117
118 a=(PInter.Binf > Binf)? PInter.Binf : Binf;
119 b=(PInter.Bsup < Bsup)? PInter.Bsup : Bsup;
120
121 return(PeriodicInterval(a,b));
122}
123//----------------------------------------------------------------------
124PeriodicInterval PeriodicInterval::SecondIntersection(PeriodicInterval& PInter)
125{
126 Standard_Real a,b;
127
128
129 if(PInter.isnull
130 || isnull
131 || this->Length()>=PIpPI
132 || PInter.Length()>=PIpPI) {
133 PeriodicInterval PourSGI; return(PourSGI);
134 }
135
136 Standard_Real PInter_inf=PInter.Binf+PIpPI;
137 Standard_Real PInter_sup=PInter.Bsup+PIpPI;
138 if(PInter_inf > Bsup) {
139 PInter_inf=PInter.Binf-PIpPI;
140 PInter_sup=PInter.Bsup-PIpPI;
141 }
142 if((PInter_sup < Binf) || (PInter_inf > Bsup)) {
143 PeriodicInterval PourSGI; return(PourSGI);
144 }
145 else {
146 a=(PInter_inf > Binf)? PInter_inf : Binf;
147 b=(PInter_sup < Bsup)? PInter_sup : Bsup;
148 }
149 return(PeriodicInterval(a,b));
150}
151//----------------------------------------------------------------------
c24d4017 152Interval::Interval() :
153 Binf(0.),
154 Bsup(0.),
155 HasFirstBound(Standard_False),
156 HasLastBound(Standard_False)
157{ IsNull=Standard_True; }
7fd59977 158
159Interval::Interval(const Standard_Real a,const Standard_Real b) {
160 HasFirstBound=HasLastBound=Standard_True;
161 if(a<b) { Binf=a; Bsup=b; }
162 else { Binf=b; Bsup=a; }
163 IsNull=Standard_False;
164}
165
d533dafb 166Interval::Interval(const IntRes2d_Domain& Domain)
167: Binf(0.0),
168 Bsup(0.0)
169{
7fd59977 170 IsNull=Standard_False;
171 if(Domain.HasFirstPoint()) {
172 HasFirstBound=Standard_True;
173 Binf=Domain.FirstParameter()-Domain.FirstTolerance();
174 }
175 else
176 HasFirstBound=Standard_False;
177 if(Domain.HasLastPoint()) {
178 HasLastBound=Standard_True;
179 Bsup=Domain.LastParameter()+Domain.LastTolerance();
180 }
181 else HasLastBound=Standard_False;
182}
183
184Interval::Interval( const Standard_Real a,const Standard_Boolean hf
185 ,const Standard_Real b,const Standard_Boolean hl) {
186 Binf=a; Bsup=b;
187 IsNull=Standard_False;
188 HasFirstBound=hf;
189 HasLastBound=hl;
190}
191
192Standard_Real Interval::Length() { return((IsNull)? -1.0 :Abs(Bsup-Binf)); }
193
194Interval Interval::IntersectionWithBounded(const Interval& Inter) {
195 if(IsNull || Inter.IsNull) { Interval PourSGI; return(PourSGI); }
196 if(!(HasFirstBound || HasLastBound))
197 return(Interval(Inter.Binf,Inter.Bsup));
198 Standard_Real a,b;
199 if(HasFirstBound) {
200 if(Inter.Bsup < Binf) { Interval PourSGI; return(PourSGI); }
201 a=(Inter.Binf < Binf)? Binf : Inter.Binf;
202 }
203 else { a=Inter.Binf; }
204
205 if(HasLastBound) {
206 if(Inter.Binf > Bsup) { Interval PourSGI; return(PourSGI); }
207 b=(Inter.Bsup > Bsup)? Bsup : Inter.Bsup;
208 }
209 else { b=Inter.Bsup; }
210 return(Interval(a,b));
211}