0024171: Eliminate CLang compiler warning -Wreorder
[occt.git] / src / ShapeAnalysis / ShapeAnalysis_BoxBndTree.cxx
CommitLineData
b311480e 1// Created on: 2005-02-14
2// Created by: Alexey MORENOV
3// Copyright (c) 2005-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21#include <ShapeAnalysis_BoxBndTree.hxx>
22#include <Standard_NoSuchObject.hxx>
23#include <ShapeAnalysis_Edge.hxx>
24#include <TopoDS_Vertex.hxx>
25#include <TopoDS_Edge.hxx>
26#include <TopoDS_Wire.hxx>
27#include <TopoDS.hxx>
28#include <ShapeAnalysis.hxx>
29#include <gp_Pnt.hxx>
30#include <TColStd_ListIteratorOfListOfInteger.hxx>
31#include <BRep_Tool.hxx>
974c25ed 32#include <Precision.hxx>
7fd59977 33
34//=======================================================================
35//function : Reject
36//purpose :
37//=======================================================================
38
39Standard_Boolean ShapeAnalysis_BoxBndTreeSelector::
40 Reject (const Bnd_Box& theBnd) const
41{
42 Standard_Boolean fch = myFBox.IsOut(theBnd);
43 Standard_Boolean lch = myLBox.IsOut(theBnd);
44 if (fch == Standard_False || lch == Standard_False) return Standard_False;
45 return Standard_True;
46}
47
48//=======================================================================
49//function : Accept
50//purpose :
51//=======================================================================
52
53Standard_Boolean ShapeAnalysis_BoxBndTreeSelector::
54 Accept (const Standard_Integer& theObj)
55{
56 if (theObj < 1 || theObj > mySeq->Length())
57 Standard_NoSuchObject::Raise
58 ("ShapeAnalysis_BoxBndTreeSelector::Accept : no such object for current index");
59 Standard_Boolean IsAccept = Standard_False;
60 if (myList.Contains(theObj))
61 return Standard_False;
974c25ed
G
62 enum
63 {
64 First = 1,
65 Last = 2
66 };
7fd59977 67
68 TopoDS_Wire W = TopoDS::Wire (mySeq->Value (theObj));
69 TopoDS_Vertex V1,V2;
70 ShapeAnalysis::FindBounds (W,V1,V2);
71 if(myShared){
72 if (myLVertex.IsSame(V1)){
73 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
74 IsAccept = Standard_True;
974c25ed 75 myArrIndices(Last) = theObj;
7fd59977 76 }
77 else {
78 if (myLVertex.IsSame(V2)){
79 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
80 IsAccept = Standard_True;
974c25ed 81 myArrIndices(Last) = theObj;
7fd59977 82 }
83 else {
84 if (myFVertex.IsSame(V2)){
85 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3);
86 IsAccept = Standard_True;
974c25ed 87 myArrIndices(First) = theObj;
7fd59977 88 }
89 else {
90 if (myFVertex.IsSame(V1)){
91 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4);
92 IsAccept = Standard_True;
974c25ed 93 myArrIndices(First) = theObj;
7fd59977 94 }
95 else myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
96
97
98 }
99 }
100 }
101
102 if (IsAccept){
103 SetNb(theObj);
974c25ed
G
104 if(myArrIndices(Last))
105 myStop = Standard_True;
7fd59977 106 return Standard_True;
107 }
108 else myStop = Standard_False;
109 }
110
111 else{
112 gp_Pnt p1 = BRep_Tool::Pnt(V1);
113 gp_Pnt p2 = BRep_Tool::Pnt(V2);
114
115 Standard_Real tailhead, tailtail, headhead, headtail;
116 tailhead = p1.Distance(myLPnt);
117 tailtail = p2.Distance(myLPnt);
118 headhead = p1.Distance(myFPnt);
119 headtail = p2.Distance(myFPnt);
120 Standard_Real dm1 = tailhead, dm2 = headtail;
121 Standard_Integer res1 = 0, res2 = 0;
122 if (tailhead > tailtail) {res1 = 1; dm1 = tailtail;}
123 if (headtail > headhead) {res2 = 1; dm2 = headhead;}
124 Standard_Integer result = res1;
125 Standard_Real min3d;
126 min3d = Min (dm1, dm2);
127 if (min3d > myMin3d)
128 return Standard_False;
129
974c25ed
G
130 Standard_Integer minInd = (dm1 > dm2 ? First : Last );
131 Standard_Integer maxInd = (dm1 > dm2 ? Last : First);
132 myArrIndices(minInd) = theObj;
133 if((min3d - myMin3d) > RealSmall())
134 myArrIndices(maxInd) = 0;
135
7fd59977 136 myMin3d = min3d;
137 if (min3d > myTol)
138 {
139 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
140 return Standard_False;
141 }
7fd59977 142
974c25ed
G
143 Standard_Integer anObj = (myArrIndices(Last) ? myArrIndices(Last) : myArrIndices(First));
144 SetNb(anObj);
7fd59977 145
974c25ed
G
146 if (min3d == 0 && minInd == Last)
147 myStop = Standard_True;
148
7fd59977 149 if (dm1 > dm2)
150 {
151 dm1 = dm2;
152 result = res2 + 2;
153 }
974c25ed
G
154 if(anObj == theObj)
155 {
156 switch (result) {
7fd59977 157 case 0: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); break;
158 case 1: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); break;
159 case 2: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE3); break;
160 case 3: myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE4); break;
161 }
974c25ed 162 }
7fd59977 163 return Standard_True;
164
165 }
166
167 return Standard_False;
168}
169