1 // Created on: 1992-06-10
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
24 #include <IntImpParGen.ixx>
25 #include <IntRes2d_Domain.hxx>
26 #include <IntRes2d_Position.hxx>
27 #include <IntRes2d_Transition.hxx>
28 #include <gp_Vec2d.hxx>
29 #include <gp_Pnt2d.hxx>
34 #include <IntImpParGen_Tool.hxx>
38 #define TOLERANCE_ANGULAIRE 0.00000001
39 #define DERIVEE_PREMIERE_NULLE 0.000000000001
40 //----------------------------------------------------------------------
41 Standard_Real IntImpParGen::NormalizeOnDomain(Standard_Real& Param,
42 const IntRes2d_Domain& TheDomain) {
43 Standard_Real modParam = Param;
44 if(TheDomain.IsClosed()) {
45 Standard_Real Periode,t;
46 TheDomain.EquivalentParameters(t,Periode);
48 while( modParam<TheDomain.FirstParameter()
49 && modParam+Periode < TheDomain.LastParameter()) {
52 while( modParam>TheDomain.LastParameter()
53 && modParam-Periode > TheDomain.FirstParameter()) {
59 //----------------------------------------------------------------------
60 void IntImpParGen::DeterminePosition(IntRes2d_Position& Pos1,
61 const IntRes2d_Domain& TheDomain,
63 const Standard_Real Param1) {
67 if(TheDomain.HasFirstPoint()) {
68 if(Pnt1.Distance(TheDomain.FirstPoint())
69 <= TheDomain.FirstTolerance()) {
74 if(TheDomain.HasLastPoint()) {
75 if(Pnt1.Distance(TheDomain.LastPoint())
76 <= TheDomain.LastTolerance()) {
77 if(Pos1==IntRes2d_Head) {
78 if(Abs(Param1-TheDomain.LastParameter())
79 < Abs(Param1-TheDomain.FirstParameter()))
88 //----------------------------------------------------------------------
89 void IntImpParGen::DetermineTransition(const IntRes2d_Position Pos1,
91 const gp_Vec2d& Norm1,
92 IntRes2d_Transition& T1,
93 const IntRes2d_Position Pos2,
95 const gp_Vec2d& Norm2,
96 IntRes2d_Transition& T2,
97 const Standard_Real ) {
99 Standard_Boolean courbure1=Standard_True;
100 Standard_Boolean courbure2=Standard_True;
101 Standard_Boolean decide=Standard_True;
103 T1.SetPosition(Pos1);
104 T2.SetPosition(Pos2);
107 if (Tan1.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {
109 courbure1=Standard_False;
110 if (Tan1.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) { // transition undecided
111 decide=Standard_False;
115 if (Tan2.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {
117 courbure2=Standard_False;
118 if (Tan2.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) { // transition undecided
119 decide=Standard_False;
128 Standard_Real sgn=Tan1.Crossed(Tan2);
129 Standard_Real norm=Tan1.Magnitude()*Tan2.Magnitude();
131 if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) { // Transition TOUCH #########
132 Standard_Boolean opos=(Tan1.Dot(Tan2))<0;
133 if (!(courbure1||courbure2)) {
134 T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
135 T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
140 Norm.SetCoord(-Tan1.Y(),Tan1.X());
141 Standard_Real Val1,Val2;
146 Val1=Norm.Dot(Norm1);
152 Val2=Norm.Dot(Norm2);
155 if (Abs(Val1-Val2) <= TOLERANCE_ANGULAIRE) {
156 T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
157 T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
159 else if (Val2 > Val1) {
160 T2.SetValue(Standard_True,Pos2,IntRes2d_Inside,opos);
162 T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
165 T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
168 else { // Val1 > Val2
169 T2.SetValue(Standard_True,Pos2,IntRes2d_Outside,opos);
171 T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
174 T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
180 T1.SetValue(Standard_False,Pos1,IntRes2d_In);
181 T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
184 T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
185 T2.SetValue(Standard_False,Pos2,IntRes2d_In);
190 //----------------------------------------------------------------------
191 Standard_Boolean IntImpParGen::DetermineTransition(const IntRes2d_Position Pos1,
193 IntRes2d_Transition& T1,
194 const IntRes2d_Position Pos2,
196 IntRes2d_Transition& T2,
197 const Standard_Real ) {
199 T1.SetPosition(Pos1);
200 T2.SetPosition(Pos2);
202 Standard_Real Tan1Magnitude = Tan1.Magnitude();
203 if (Tan1Magnitude<=DERIVEE_PREMIERE_NULLE) {
204 return(Standard_False);
207 Standard_Real Tan2Magnitude = Tan2.Magnitude();
208 if (Tan2Magnitude<=DERIVEE_PREMIERE_NULLE) {
209 return(Standard_False);
212 Standard_Real sgn=Tan1.Crossed(Tan2);
213 Standard_Real norm=Tan1Magnitude*Tan2Magnitude;
215 if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) { // Transition TOUCH #########
216 return(Standard_False);
219 T1.SetValue(Standard_False,Pos1,IntRes2d_In);
220 T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
223 T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
224 T2.SetValue(Standard_False,Pos2,IntRes2d_In);
226 return(Standard_True);