0024171: Eliminate CLang compiler warning -Wreorder
[occt.git] / src / BRepMesh / BRepMesh_CircleTool.cxx
CommitLineData
b311480e 1// Created on: 1993-06-15
2// Created by: Didier PIFFAULT
3// Copyright (c) 1993-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
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.
10//
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.
13//
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.
20
0d88155b
O
21
22#include <BRepMesh_CircleTool.ixx>
23#include <gp_XY.hxx>
24#include <Precision.hxx>
25#include <BRepMesh_Circ.hxx>
26#include <BRepMesh_CircleInspector.hxx>
27#include <BRepMesh_BaseAllocator.hxx>
28
29
30//=======================================================================
31//function : BRepMesh_CircleInspector
32//purpose : Constructor
0d88155b
O
33//=======================================================================
34
35BRepMesh_CircleInspector::BRepMesh_CircleInspector (Standard_Real theTol,
36 Standard_Integer nbComp,
37 const BRepMesh_BaseAllocator& theAlloc)
38 : myTol(theTol*theTol),
39 myResInd(theAlloc),
40 myInitCircle(nbComp)
41{
42 // myTol = theTol*theTol;
43}
44
45//=======================================================================
46//function : Inspect
47//purpose :
48//
49//=======================================================================
50NCollection_CellFilter_Action BRepMesh_CircleInspector::Inspect (const Standard_Integer theTarget)
51{
52 const BRepMesh_Circ& Circ = myInitCircle(theTarget);
53 Standard_Real R = Circ.Radius();
54 if(R < 0)
55 return CellFilter_Purge;
56 Standard_Real dx,dy;
57 const gp_XY& aLoc=Circ.Location();
58 dx=myCurrent.X()-aLoc.X();
59 dy=myCurrent.Y()-aLoc.Y();
60 if ((dx*dx+dy*dy)-(R*R) <= myTol)
61 myResInd.Append(theTarget);
62 return CellFilter_Keep;
63}
64
65
66//=======================================================================
67//function : BRepMesh_CircleTool
68//purpose :
69//=======================================================================
70BRepMesh_CircleTool::BRepMesh_CircleTool(const BRepMesh_BaseAllocator& theAlloc)
71: Tolerance(Precision::PConfusion()),
72Allocator(theAlloc),
73CellFilter(10, theAlloc),
74Selector(Tolerance,64,theAlloc)
75{
76 Tolerance=Tolerance*Tolerance;
77}
78
79//=======================================================================
80//function : BRepMesh_CircleTool
81//purpose :
82//=======================================================================
83BRepMesh_CircleTool::BRepMesh_CircleTool(const Standard_Integer nbComp,
84 const BRepMesh_BaseAllocator& theAlloc)
85 : Tolerance(Precision::PConfusion()),
86 Allocator(theAlloc),
87 CellFilter(10, theAlloc),
88 Selector(Tolerance,Max(nbComp,64),theAlloc)
89{
90 Tolerance=Tolerance*Tolerance;
91}
92
93
94//=======================================================================
95//function : Initialize
96//purpose :
97//=======================================================================
98void BRepMesh_CircleTool::Initialize(const Standard_Integer /*nbComp*/)
99{
100 Tolerance=Precision::PConfusion();
101 Tolerance=Tolerance*Tolerance;
102}
103
104void BRepMesh_CircleTool::SetCellSize(const Standard_Real theSize)
105{
106 CellFilter.Reset(theSize, Allocator);
107}
108
109void BRepMesh_CircleTool::SetCellSize(const Standard_Real theXSize,
110 const Standard_Real theYSize)
111{
112 Standard_Real aCellSize[2];
113 aCellSize[0] = theXSize;
114 aCellSize[1] = theYSize;
115
116 CellFilter.Reset(aCellSize, Allocator);
117}
118
119
120void BRepMesh_CircleTool::SetMinMaxSize(const gp_XY& theMin,
121 const gp_XY& theMax)
122{
123 FaceMin = theMin;
124 FaceMax = theMax;
125}
126
127//=======================================================================
128//function : Add
129//purpose :
130//=======================================================================
131void BRepMesh_CircleTool::Add(const gp_Circ2d& theCirc,
132 const Standard_Integer theIndex)
133{
134 gp_XY aCoord(theCirc.Location().Coord());
135 Standard_Real R = theCirc.Radius();
136 BRepMesh_Circ aCir(aCoord, R);
137
138 //compute coords
139 Standard_Real xMax=Min(aCoord.X()+R,FaceMax.X());
140 Standard_Real xMin=Max(aCoord.X()-R,FaceMin.X());
141 Standard_Real yMax=Min(aCoord.Y()+R,FaceMax.Y());
142 Standard_Real yMin=Max(aCoord.Y()-R,FaceMin.Y());
143
144 gp_XY MinPnt(xMin,yMin);
145 gp_XY MaxPnt(xMax,yMax);
146
147 CellFilter.Add(theIndex, MinPnt, MaxPnt);
148 Selector.Add(theIndex, aCir);
149}
150
151//=======================================================================
152//function : Add
153//purpose :
154//=======================================================================
155Standard_Boolean BRepMesh_CircleTool::Add(const gp_XY& p1,
156 const gp_XY& p2,
157 const gp_XY& p3,
158 const Standard_Integer theIndex)
159{
160 gp_XY m1((p1.X()+p2.X())/2., (p1.Y()+p2.Y())/2.);
161 gp_XY m2((p2.X()+p3.X())/2., (p2.Y()+p3.Y())/2.);
162 gp_XY m3((p3.X()+p1.X())/2., (p3.Y()+p1.Y())/2.);
163 Standard_Real dx=m1.X()-m2.X();
164 Standard_Real dy=m1.Y()-m2.Y();
165 Standard_Real d12=(dx*dx)+(dy*dy);
166 dx=m2.X()-m3.X();
167 dy=m2.Y()-m3.Y();
168 Standard_Real d23=(dx*dx)+(dy*dy);
169 dx=m3.X()-m1.X();
170 dy=m3.Y()-m1.Y();
171 Standard_Real d31=(dx*dx)+(dy*dy);
172 gp_XY pl11, pl12, pl21, pl22;
173
174 if (d12>d23 && d12>d31) {
175 dy=p2.Y()-p1.Y();
176 dx=p1.X()-p2.X();
177 if (dy!=0. || dx!=0.) {
178 pl11 = m1;
179 pl12 = gp_XY(dy, dx);
180 }
181 else return Standard_False;
182
183 dy=p3.Y()-p2.Y();
184 dx=p2.X()-p3.X();
185 if (dy!=0. || dx!=0.) {
186 pl21 = m2;
187 pl22 = gp_XY(dy, dx);
188 }
189 else return Standard_False;
190 }
191 else {
192 if (d23>d31) {
193 dy=p3.Y()-p2.Y();
194 dx=p2.X()-p3.X();
195 if (dy!=0. || dx!=0.) {
196 pl11 = m2;
197 pl12 = gp_XY(dy, dx);
198 }
199 else return Standard_False;
200
201 dy=p1.Y()-p3.Y();
202 dx=p3.X()-p1.X();
203 if (dy!=0. || dx!=0.) {
204 pl21 = m3;
205 pl22 = gp_XY(dy, dx);
206 }
207 else return Standard_False;
208 }
209 else {
210 dy=p1.Y()-p3.Y();
211 dx=p3.X()-p1.X();
212 if (dy!=0. || dx!=0.) {
213 pl11 = m3;
214 pl12 = gp_XY(dy, dx);
215 }
216 else return Standard_False;
217
218 dy=p2.Y()-p1.Y();
219 dx=p1.X()-p2.X();
220 if (dy!=0. || dx!=0.) {
221 pl21 = m1;
222 pl22 = gp_XY(dy, dx);
223 }
224 else return Standard_False;
225 }
226 }
227
228 gp_XY aVecO1O2 = pl21 - pl11;
229 Standard_Real aCrossD1D2 = pl12 ^ pl22;
230 Standard_Real theSinAngle = Abs(aCrossD1D2);
231 if (theSinAngle < gp::Resolution())
232 return Standard_False;
233 Standard_Real theParam1 = (aVecO1O2 ^ pl22) / aCrossD1D2;
234 gp_XY pInt = pl11+pl12*theParam1;
235 dx=p1.X()-pInt.X();
236 dy=p1.Y()-pInt.Y();
237 Standard_Real R = Sqrt(dx*dx+dy*dy);
238 BRepMesh_Circ aCir(pInt, R);
239
240 //compute coords
241 Standard_Real xMax=Min(pInt.X()+R,FaceMax.X());
242 Standard_Real xMin=Max(pInt.X()-R,FaceMin.X());
243 Standard_Real yMax=Min(pInt.Y()+R,FaceMax.Y());
244 Standard_Real yMin=Max(pInt.Y()-R,FaceMin.Y());
245
246 gp_XY MinPnt(xMin,yMin);
247 gp_XY MaxPnt(xMax,yMax);
248
249 CellFilter.Add(theIndex, MinPnt, MaxPnt);
250
251 Selector.Add(theIndex, aCir);
252 return Standard_True;
253}
254
255//=======================================================================
256//function : Delete
257//purpose :
258//=======================================================================
259void BRepMesh_CircleTool::Delete(const Standard_Integer theIndex)
260{
261 BRepMesh_Circ& Circ = Selector.GetCirc(theIndex);
262 if(Circ.Radius() > 0.) {
263 Circ.SetRadius(-1);
264 }
265}
266
267//=======================================================================
268//function : Select
269//purpose :
270//=======================================================================
271BRepMesh_ListOfInteger& BRepMesh_CircleTool::Select(const gp_XY& thePnt)
272{
273 Selector.ClerResList();
274 Selector.SetCurrent(thePnt);
275 CellFilter.Inspect (thePnt, Selector);
276 return Selector.GetCoincidentInd();
277}
278
279void BRepMesh_CircleTool::MocAdd(const Standard_Integer theIndex)
280{
281 gp_XY nullPnt(0.,0.);
282 BRepMesh_Circ theNullCir(nullPnt, -1.);
283 Selector.Add(theIndex, theNullCir);
284}