0031671: Coding Rules - eliminate warnings issued by clang 11
[occt.git] / src / ShapeAnalysis / ShapeAnalysis_BoxBndTree.cxx
1 // Created on: 2005-02-14
2 // Created by: Alexey MORENOV
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <ShapeAnalysis_BoxBndTree.hxx>
17 #include <Standard_NoSuchObject.hxx>
18 #include <ShapeAnalysis_Edge.hxx>
19 #include <TopoDS_Vertex.hxx>
20 #include <TopoDS_Edge.hxx>
21 #include <TopoDS_Wire.hxx>
22 #include <TopoDS.hxx>
23 #include <ShapeAnalysis.hxx>
24 #include <gp_Pnt.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
26 #include <BRep_Tool.hxx>
27 #include <Precision.hxx>
28
29 //=======================================================================
30 //function : Reject
31 //purpose  : 
32 //=======================================================================
33
34 Standard_Boolean ShapeAnalysis_BoxBndTreeSelector::
35   Reject (const Bnd_Box& theBnd) const
36 {
37   Standard_Boolean fch = myFBox.IsOut(theBnd);
38   Standard_Boolean lch = myLBox.IsOut(theBnd);
39   if (fch == Standard_False || lch == Standard_False) return Standard_False;
40   return Standard_True;
41 }
42
43 //=======================================================================
44 //function : Accept
45 //purpose  : 
46 //=======================================================================
47
48 Standard_Boolean ShapeAnalysis_BoxBndTreeSelector::
49   Accept (const Standard_Integer& theObj)
50 {
51   if (theObj < 1 || theObj > mySeq->Length())
52     throw Standard_NoSuchObject("ShapeAnalysis_BoxBndTreeSelector::Accept : no such object for current index");
53   Standard_Boolean IsAccept = Standard_False;
54   if (myList.Contains(theObj))
55     return Standard_False;
56   enum
57   {
58     First = 1,
59     Last = 2
60   };
61    
62   TopoDS_Wire W = TopoDS::Wire (mySeq->Value (theObj));
63   TopoDS_Vertex V1,V2;                         
64   ShapeAnalysis::FindBounds (W,V1,V2);
65   if(myShared){
66     if (myLVertex.IsSame(V1)){      
67       myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
68       IsAccept = Standard_True;
69       myArrIndices(Last) = theObj;
70     }
71     else {
72       if (myLVertex.IsSame(V2)){
73         myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
74         IsAccept = Standard_True;
75         myArrIndices(Last) = theObj;
76       }
77       else {
78         if (myFVertex.IsSame(V2)){
79           myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3);
80           IsAccept = Standard_True;
81           myArrIndices(First) = theObj;
82         }
83         else {
84           if (myFVertex.IsSame(V1)){
85             myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4);
86             IsAccept = Standard_True;
87             myArrIndices(First) = theObj;
88           }
89           else myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
90
91           
92         }
93       }
94     }
95     
96     if (IsAccept){
97       SetNb(theObj);
98       if(myArrIndices(Last))
99         myStop = Standard_True;
100       return Standard_True;
101     }
102     else myStop = Standard_False;
103   }
104   
105   else{
106     gp_Pnt p1 = BRep_Tool::Pnt(V1);
107     gp_Pnt p2 = BRep_Tool::Pnt(V2);
108     
109     Standard_Real tailhead, tailtail, headhead, headtail;
110     tailhead = p1.Distance(myLPnt);
111     tailtail = p2.Distance(myLPnt);
112     headhead = p1.Distance(myFPnt);
113     headtail = p2.Distance(myFPnt);
114     Standard_Real dm1 = tailhead, dm2 = headtail;
115     Standard_Integer res1 = 0, res2 = 0;
116     if (tailhead > tailtail) {res1 = 1; dm1 = tailtail;}
117     if (headtail > headhead) {res2 = 1; dm2 = headhead;}
118     Standard_Integer result = res1;
119     Standard_Real min3d;
120     min3d = Min (dm1, dm2);
121     if (min3d > myMin3d)
122       return Standard_False;
123
124     Standard_Integer minInd = (dm1 > dm2 ?  First : Last );
125     Standard_Integer maxInd = (dm1 > dm2 ? Last : First);
126     myArrIndices(minInd) = theObj;
127     if((min3d - myMin3d) > RealSmall())
128       myArrIndices(maxInd) = 0;
129       
130     myMin3d = min3d;
131     if (min3d > myTol)
132     {
133        myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
134        return Standard_False;
135     }
136     
137     Standard_Integer anObj = (myArrIndices(Last) ? myArrIndices(Last) : myArrIndices(First));
138     SetNb(anObj);
139     
140     if (min3d == 0 && minInd == Last)
141       myStop = Standard_True;
142    
143     if (dm1 > dm2) 
144     {
145       dm1 = dm2; 
146       result = res2 + 2;
147     }
148     if(anObj == theObj)
149     {
150       switch (result) {
151         case 0: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); break; 
152         case 1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);  break;
153         case 2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3);  break;
154         case 3: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4);  break;
155       }
156     }
157       return Standard_True;
158     
159   }  
160    
161   return Standard_False;
162 }
163