Integration of OCCT 6.5.0 from SVN
[occt.git] / src / IntImpParGen / IntImpParGen.cxx
CommitLineData
7fd59977 1// File: IntImpParGen_Tool.hxx
2// Created: Wed Jun 10 15:04:00 1992
3// Author: Laurent BUCHARD
4// <lbr@sdsun2>
5
6
7
8#include <IntImpParGen.ixx>
9#include <IntRes2d_Domain.hxx>
10#include <IntRes2d_Position.hxx>
11#include <IntRes2d_Transition.hxx>
12#include <gp_Vec2d.hxx>
13#include <gp_Pnt2d.hxx>
14
15
16
17
18#include <IntImpParGen_Tool.hxx>
19#include <gp.hxx>
20
21
22#define TOLERANCE_ANGULAIRE 0.00000001
23#define DERIVEE_PREMIERE_NULLE 0.000000000001
24//----------------------------------------------------------------------
25Standard_Real IntImpParGen::NormalizeOnDomain(Standard_Real& Param,
26 const IntRes2d_Domain& TheDomain) {
27 Standard_Real modParam = Param;
28 if(TheDomain.IsClosed()) {
29 Standard_Real Periode,t;
30 TheDomain.EquivalentParameters(t,Periode);
31 Periode-=t;
32 while( modParam<TheDomain.FirstParameter()
33 && modParam+Periode < TheDomain.LastParameter()) {
34 modParam+=Periode;
35 }
36 while( modParam>TheDomain.LastParameter()
37 && modParam-Periode > TheDomain.FirstParameter()) {
38 modParam-=Periode;
39 }
40 }
41 return(modParam);
42}
43//----------------------------------------------------------------------
44void IntImpParGen::DeterminePosition(IntRes2d_Position& Pos1,
45 const IntRes2d_Domain& TheDomain,
46 const gp_Pnt2d& Pnt1,
47 const Standard_Real Param1) {
48
49 Pos1=IntRes2d_Middle;
50
51 if(TheDomain.HasFirstPoint()) {
52 if(Pnt1.Distance(TheDomain.FirstPoint())
53 <= TheDomain.FirstTolerance()) {
54 Pos1=IntRes2d_Head;
55 }
56 }
57
58 if(TheDomain.HasLastPoint()) {
59 if(Pnt1.Distance(TheDomain.LastPoint())
60 <= TheDomain.LastTolerance()) {
61 if(Pos1==IntRes2d_Head) {
62 if(Abs(Param1-TheDomain.LastParameter())
63 < Abs(Param1-TheDomain.FirstParameter()))
64 Pos1=IntRes2d_End;
65 }
66 else {
67 Pos1=IntRes2d_End;
68 }
69 }
70 }
71}
72//----------------------------------------------------------------------
73void IntImpParGen::DetermineTransition(const IntRes2d_Position Pos1,
74 gp_Vec2d& Tan1,
75 const gp_Vec2d& Norm1,
76 IntRes2d_Transition& T1,
77 const IntRes2d_Position Pos2,
78 gp_Vec2d& Tan2,
79 const gp_Vec2d& Norm2,
80 IntRes2d_Transition& T2,
81 const Standard_Real ) {
82
83 Standard_Boolean courbure1=Standard_True;
84 Standard_Boolean courbure2=Standard_True;
85 Standard_Boolean decide=Standard_True;
86
87 T1.SetPosition(Pos1);
88 T2.SetPosition(Pos2);
89
90
91 if (Tan1.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {
92 Tan1=Norm1;
93 courbure1=Standard_False;
94 if (Tan1.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) { // transition undecided
95 decide=Standard_False;
96 }
97 }
98
99 if (Tan2.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {
100 Tan2=Norm2;
101 courbure2=Standard_False;
102 if (Tan2.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) { // transition undecided
103 decide=Standard_False;
104 }
105 }
106
107 if (!decide) {
108 T1.SetValue(Pos1);
109 T2.SetValue(Pos2);
110 }
111 else {
112 Standard_Real sgn=Tan1.Crossed(Tan2);
113 Standard_Real norm=Tan1.Magnitude()*Tan2.Magnitude();
114
115 if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) { // Transition TOUCH #########
116 Standard_Boolean opos=(Tan1.Dot(Tan2))<0;
117 if (!(courbure1||courbure2)) {
118 T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
119 T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
120 }
121 else {
122 gp_Vec2d Norm;
123 Tan1.Normalized();
124 Norm.SetCoord(-Tan1.Y(),Tan1.X());
125 Standard_Real Val1,Val2;
126 if (!courbure1) {
127 Val1=0.0;
128 }
129 else {
130 Val1=Norm.Dot(Norm1);
131 }
132 if (!courbure2) {
133 Val2=0.0;
134 }
135 else {
136 Val2=Norm.Dot(Norm2);
137 }
138
139 if (Abs(Val1-Val2) <= TOLERANCE_ANGULAIRE) {
140 T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
141 T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
142 }
143 else if (Val2 > Val1) {
144 T2.SetValue(Standard_True,Pos2,IntRes2d_Inside,opos);
145 if (opos) {
146 T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
147 }
148 else {
149 T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
150 }
151 }
152 else { // Val1 > Val2
153 T2.SetValue(Standard_True,Pos2,IntRes2d_Outside,opos);
154 if (opos) {
155 T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
156 }
157 else {
158 T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
159 }
160 }
161 }
162 }
163 else if (sgn<0) {
164 T1.SetValue(Standard_False,Pos1,IntRes2d_In);
165 T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
166 }
167 else { // sgn>0
168 T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
169 T2.SetValue(Standard_False,Pos2,IntRes2d_In);
170 }
171 }
172}
173
174//----------------------------------------------------------------------
175Standard_Boolean IntImpParGen::DetermineTransition(const IntRes2d_Position Pos1,
176 gp_Vec2d& Tan1,
177 IntRes2d_Transition& T1,
178 const IntRes2d_Position Pos2,
179 gp_Vec2d& Tan2,
180 IntRes2d_Transition& T2,
181 const Standard_Real ) {
182
183 T1.SetPosition(Pos1);
184 T2.SetPosition(Pos2);
185
186 Standard_Real Tan1Magnitude = Tan1.Magnitude();
187 if (Tan1Magnitude<=DERIVEE_PREMIERE_NULLE) {
188 return(Standard_False);
189 }
190
191 Standard_Real Tan2Magnitude = Tan2.Magnitude();
192 if (Tan2Magnitude<=DERIVEE_PREMIERE_NULLE) {
193 return(Standard_False);
194 }
195
196 Standard_Real sgn=Tan1.Crossed(Tan2);
197 Standard_Real norm=Tan1Magnitude*Tan2Magnitude;
198
199 if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) { // Transition TOUCH #########
200 return(Standard_False);
201 }
202 else if (sgn<0) {
203 T1.SetValue(Standard_False,Pos1,IntRes2d_In);
204 T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
205 }
206 else { // sgn>0
207 T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
208 T2.SetValue(Standard_False,Pos2,IntRes2d_In);
209 }
210 return(Standard_True);
211}
212
213
214
215
216
217
218
219
220