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