1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <BOPInt_Tools.ixx>
18 #include <BndLib_Add3dCurve.hxx>
19 #include <Bnd_Box.hxx>
20 #include <Geom_Curve.hxx>
21 #include <GeomAdaptor_Curve.hxx>
23 //=======================================================================
24 //function : CheckCurve
26 //=======================================================================
27 Standard_Boolean BOPInt_Tools::CheckCurve(const Handle (Geom_Curve)& aC3D,
28 const Standard_Real aTolR3D,
31 Standard_Boolean bRet;
32 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, dX, dY, dZ;
33 Standard_Real dS, aTol;
34 GeomAdaptor_Curve aGAC;
37 BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBox);
39 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
45 bRet=(dX>aTol || dY>aTol || dZ>aTol);
51 //=======================================================================
54 //=======================================================================
55 Standard_Boolean BOPInt_Tools::IsOnPave(const Standard_Real aT1,
56 const IntTools_Range& aRange,
57 const Standard_Real aTolerance)
59 Standard_Boolean firstisonpave1, firstisonpave2, bIsOnPave;
61 firstisonpave1 = (Abs(aRange.First() - aT1) < aTolerance);
62 firstisonpave2 = (Abs(aRange.Last() - aT1) < aTolerance);
63 bIsOnPave=(firstisonpave1 || firstisonpave2);
66 //=======================================================================
67 // function: VertexParameters
69 //=======================================================================
70 void BOPInt_Tools::VertexParameters(const IntTools_CommonPrt& aCPart,
74 const IntTools_Range& aR1=aCPart.Range1();
75 aT1=0.5*(aR1.First()+aR1.Last());
77 if((aCPart.VertexParameter1() >= aR1.First()) &&
78 (aCPart.VertexParameter1() <= aR1.Last())) {
79 aT1 = aCPart.VertexParameter1();
82 const IntTools_SequenceOfRanges& aRanges2=aCPart.Ranges2();
83 const IntTools_Range& aR2=aRanges2(1);
84 aT2=0.5*(aR2.First()+aR2.Last());
86 if((aCPart.VertexParameter2() >= aR2.First()) &&
87 (aCPart.VertexParameter2() <= aR2.Last())) {
88 aT2 = aCPart.VertexParameter2();
91 //=======================================================================
92 // function: VertexParameter
94 //=======================================================================
95 void BOPInt_Tools::VertexParameter(const IntTools_CommonPrt& aCPart,
98 const IntTools_Range& aR=aCPart.Range1();
99 aT=0.5*(aR.First()+aR.Last());
100 if((aCPart.VertexParameter1() >= aR.First()) &&
101 (aCPart.VertexParameter1() <= aR.Last())) {
102 aT = aCPart.VertexParameter1();
105 //=======================================================================
106 // function: IsOnPave1
108 //=======================================================================
109 Standard_Boolean BOPInt_Tools::IsOnPave1(const Standard_Real aTR,
110 const IntTools_Range& aCPRange,
111 const Standard_Real aTolerance)
113 Standard_Boolean bIsOnPave;
114 Standard_Real aT1, aT2, dT1, dT2;
116 aT1=aCPRange.First();
118 bIsOnPave=(aTR>=aT1 && aTR<=aT1);
125 bIsOnPave=(dT1<=aTolerance || dT2<=aTolerance);
129 //=======================================================================
130 // function: IsInRange
132 //=======================================================================
133 Standard_Boolean BOPInt_Tools::IsInRange(const IntTools_Range& aRRef,
134 const IntTools_Range& aR,
135 const Standard_Real aTolerance)
137 Standard_Boolean bIsIn;
138 Standard_Real aT1, aT2, aTRef1, aTRef2;
141 aRRef.Range(aTRef1, aTRef2);
146 bIsIn = (aT1>=aTRef1 && aT1<=aTRef2) ||
147 (aT2>=aTRef1 && aT2<=aTRef2);
152 //=======================================================================
155 //=======================================================================
156 Standard_Integer BOPInt_Tools::SegPln(const gp_Lin& theLin,
157 const Standard_Real theTLin1,
158 const Standard_Real theTLin2,
159 const Standard_Real theTolLin,
160 const gp_Pln& thePln,
161 const Standard_Real theTolPln,
163 Standard_Real& theTP,
164 Standard_Real& theTolP,
165 Standard_Real& theTPmin,
166 Standard_Real& theTPmax)
168 Standard_Integer iRet;
169 Standard_Real aTol, aA, aB, aC, aD, aE, aH, aTP, aDist1, aDist2;
173 aTol=theTolLin+theTolPln;
175 const gp_Ax3& aPosPln=thePln.Position();
176 const gp_Dir& aDirPln=aPosPln.Direction();
177 const gp_Pnt& aLocPln=aPosPln.Location();
179 const gp_Dir& aDirLin=theLin.Direction();
180 const gp_Pnt& aLocLin=theLin.Location();
182 aP1.SetXYZ(aLocLin.XYZ()+theTLin1*aDirLin.XYZ());
183 aDist1=aDirPln.X()*(aP1.X()-aLocPln.X())+
184 aDirPln.Y()*(aP1.Y()-aLocPln.Y())+
185 aDirPln.Z()*(aP1.Z()-aLocPln.Z());
187 aP2.SetXYZ(aLocLin.XYZ()+theTLin2*aDirLin.XYZ());
188 aDist2=aDirPln.X()*(aP2.X()-aLocPln.X())+
189 aDirPln.Y()*(aP2.Y()-aLocPln.Y())+
190 aDirPln.Z()*(aP2.Z()-aLocPln.Z());
192 if (aDist1<aTol && aDist2<aTol){
193 iRet=1; // common block
197 if (aDist1*aDist2 > 0.) {
198 iRet=2; // segment lays on one side to the Plane
202 thePln.Coefficients(aA, aB, aC, aD);
203 aE=aA*aLocLin.X()+aB*aLocLin.Y()+aC*aLocLin.Z()+aD;
204 aH=aA*aDirLin.X()+aB*aDirLin.Y()+aC*aDirLin.Z();
206 if (aTP < theTLin1-aTol || aTP > theTLin2+aTol) {
207 iRet=3; // no intersections due to range of the Line
212 theP.SetXYZ(aLocLin.XYZ()+aTP*aDirLin.XYZ());
214 theTPmin=theTP-theTolPln;
215 theTPmax=theTP+theTolPln;
216 iRet=0; // intersection point