1 // Created on: 1992-06-10
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <IntImpParGen.hxx>
19 #include <IntImpParGen_Tool.hxx>
20 #include <IntRes2d_Domain.hxx>
21 #include <IntRes2d_Position.hxx>
22 #include <IntRes2d_Transition.hxx>
24 #define TOLERANCE_ANGULAIRE 0.00000001
25 #define DERIVEE_PREMIERE_NULLE 0.000000000001
26 //----------------------------------------------------------------------
27 Standard_Real IntImpParGen::NormalizeOnDomain(Standard_Real& Param,
28 const IntRes2d_Domain& TheDomain) {
29 Standard_Real modParam = Param;
30 if(TheDomain.IsClosed()) {
31 Standard_Real Periode,t;
32 TheDomain.EquivalentParameters(t,Periode);
34 while( modParam<TheDomain.FirstParameter()
35 && modParam+Periode < TheDomain.LastParameter()) {
38 while( modParam>TheDomain.LastParameter()
39 && modParam-Periode > TheDomain.FirstParameter()) {
45 //----------------------------------------------------------------------
46 void IntImpParGen::DeterminePosition(IntRes2d_Position& Pos1,
47 const IntRes2d_Domain& TheDomain,
49 const Standard_Real Param1) {
53 if(TheDomain.HasFirstPoint()) {
54 if(Pnt1.Distance(TheDomain.FirstPoint())
55 <= TheDomain.FirstTolerance()) {
60 if(TheDomain.HasLastPoint()) {
61 if(Pnt1.Distance(TheDomain.LastPoint())
62 <= TheDomain.LastTolerance()) {
63 if(Pos1==IntRes2d_Head) {
64 if(Abs(Param1-TheDomain.LastParameter())
65 < Abs(Param1-TheDomain.FirstParameter()))
74 //----------------------------------------------------------------------
75 void IntImpParGen::DetermineTransition(const IntRes2d_Position Pos1,
77 const gp_Vec2d& Norm1,
78 IntRes2d_Transition& T1,
79 const IntRes2d_Position Pos2,
81 const gp_Vec2d& Norm2,
82 IntRes2d_Transition& T2,
83 const Standard_Real ) {
85 Standard_Boolean courbure1=Standard_True;
86 Standard_Boolean courbure2=Standard_True;
87 Standard_Boolean decide=Standard_True;
93 if (Tan1.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {
95 courbure1=Standard_False;
96 if (Tan1.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) { // transition undecided
97 decide=Standard_False;
101 if (Tan2.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {
103 courbure2=Standard_False;
104 if (Tan2.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) { // transition undecided
105 decide=Standard_False;
114 Standard_Real sgn=Tan1.Crossed(Tan2);
115 Standard_Real norm=Tan1.Magnitude()*Tan2.Magnitude();
117 if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) { // Transition TOUCH #########
118 Standard_Boolean opos=(Tan1.Dot(Tan2))<0;
119 if (!(courbure1||courbure2)) {
120 T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
121 T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
125 Norm.SetCoord(-Tan1.Y(),Tan1.X());
126 Standard_Real Val1,Val2;
131 Val1=Norm.Dot(Norm1);
137 Val2=Norm.Dot(Norm2);
140 if (Abs(Val1-Val2) <= TOLERANCE_ANGULAIRE) {
141 T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
142 T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
144 else if (Val2 > Val1) {
145 T2.SetValue(Standard_True,Pos2,IntRes2d_Inside,opos);
147 T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
150 T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
153 else { // Val1 > Val2
154 T2.SetValue(Standard_True,Pos2,IntRes2d_Outside,opos);
156 T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
159 T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
165 T1.SetValue(Standard_False,Pos1,IntRes2d_In);
166 T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
169 T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
170 T2.SetValue(Standard_False,Pos2,IntRes2d_In);
175 //----------------------------------------------------------------------
176 Standard_Boolean IntImpParGen::DetermineTransition(const IntRes2d_Position Pos1,
178 IntRes2d_Transition& T1,
179 const IntRes2d_Position Pos2,
181 IntRes2d_Transition& T2,
182 const Standard_Real ) {
184 T1.SetPosition(Pos1);
185 T2.SetPosition(Pos2);
187 Standard_Real Tan1Magnitude = Tan1.Magnitude();
188 if (Tan1Magnitude<=DERIVEE_PREMIERE_NULLE) {
189 return(Standard_False);
192 Standard_Real Tan2Magnitude = Tan2.Magnitude();
193 if (Tan2Magnitude<=DERIVEE_PREMIERE_NULLE) {
194 return(Standard_False);
197 Standard_Real sgn=Tan1.Crossed(Tan2);
198 Standard_Real norm=Tan1Magnitude*Tan2Magnitude;
200 if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) { // Transition TOUCH #########
201 return(Standard_False);
204 T1.SetValue(Standard_False,Pos1,IntRes2d_In);
205 T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
208 T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
209 T2.SetValue(Standard_False,Pos2,IntRes2d_In);
211 return(Standard_True);