1 // Created on: 1991-10-30
2 // Created by: Modelisation
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
22 #include <Bnd_Box2d.ixx>
23 #include <Standard_Stream.hxx>
25 //-- #include <Precision.hxx> Precision::Infinite() -> 1e+100
27 //=======================================================================
30 //=======================================================================
32 void Bnd_Box2d::Update (const Standard_Real x, const Standard_Real y,
33 const Standard_Real X, const Standard_Real Y)
35 if (Flags & VoidMask) {
43 if (!(Flags & XminMask) && (x < Xmin)) Xmin = x;
44 if (!(Flags & XmaxMask) && (X > Xmax)) Xmax = X;
45 if (!(Flags & YminMask) && (y < Ymin)) Ymin = y;
46 if (!(Flags & YmaxMask) && (Y > Ymax)) Ymax = Y;
50 //=======================================================================
53 //=======================================================================
55 void Bnd_Box2d::Update (const Standard_Real X, const Standard_Real Y)
57 if (Flags & VoidMask) {
65 if (!(Flags & XminMask) && (X < Xmin)) Xmin = X;
66 else if (!(Flags & XmaxMask) && (X > Xmax)) Xmax = X;
67 if (!(Flags & YminMask) && (Y < Ymin)) Ymin = Y;
68 else if (!(Flags & YmaxMask) && (Y > Ymax)) Ymax = Y;
72 //=======================================================================
75 //=======================================================================
77 void Bnd_Box2d::Get (Standard_Real& x, Standard_Real& y,
78 Standard_Real& Xm, Standard_Real& Ym) const
81 Standard_ConstructionError::Raise("Bnd_Box is void");
82 Standard_Real pinf = 1e+100; //-- Precision::Infinite();
83 if (Flags & XminMask) x = -pinf;
85 if (Flags & XmaxMask) Xm = pinf;
87 if (Flags & YminMask) y = -pinf;
89 if (Flags & YmaxMask) Ym = pinf;
93 //=======================================================================
94 //function : Transformed
96 //=======================================================================
98 Bnd_Box2d Bnd_Box2d::Transformed (const gp_Trsf2d& T) const
100 gp_TrsfForm F = T.Form();
101 Bnd_Box2d newb(*this);
102 if ( IsVoid() ) return newb;
104 if (F == gp_Identity) {}
105 else if (F == gp_Translation) {
107 (T.TranslationPart()).Coord(DX,DY);
108 if (!(Flags & XminMask)) newb.Xmin += DX;
109 if (!(Flags & XmaxMask)) newb.Xmax += DX;
110 if (!(Flags & YminMask)) newb.Ymin += DY;
111 if (!(Flags & YmaxMask)) newb.Ymax += DY;
115 Standard_Boolean Vertex[4];
117 Vertex[0] = Standard_True;
118 Vertex[1] = Standard_True;
119 Vertex[2] = Standard_True;
120 Vertex[3] = Standard_True;
122 // Standard_Integer vertices = 0;
123 Standard_Integer directions = 0;
125 if (Flags & XminMask) {
126 D[directions].SetCoord(-1., 0.);
128 Vertex[0] = Vertex[2] = Standard_False;
130 if (Flags & XmaxMask) {
131 D[directions].SetCoord( 1., 0.);
133 Vertex[1] = Vertex[3] = Standard_False;
135 if (Flags & YminMask) {
136 D[directions].SetCoord( 0.,-1.);
138 Vertex[0] = Vertex[1] = Standard_False;
140 if (Flags & YmaxMask) {
141 D[directions].SetCoord( 0., 1.);
143 Vertex[2] = Vertex[3] = Standard_False;
148 for (i = 0; i < directions; i++) {
152 P[0].SetCoord(Xmin,Ymin);
153 P[1].SetCoord(Xmax,Ymin);
154 P[2].SetCoord(Xmin,Ymax);
155 P[3].SetCoord(Xmax,Ymax);
177 //=======================================================================
180 //=======================================================================
182 void Bnd_Box2d::Add (const Bnd_Box2d& Other)
184 if (IsWhole()) return;
185 else if (Other.IsVoid()) return;
186 else if (Other.IsWhole()) SetWhole();
187 else if (IsVoid()) (*this) = Other;
190 if ( ! IsOpenXmin() )
192 if (Other.IsOpenXmin()) OpenXmin();
193 else if (Xmin > Other.Xmin) Xmin = Other.Xmin;
195 if ( ! IsOpenXmax() )
197 if (Other.IsOpenXmax()) OpenXmax();
198 else if (Xmax < Other.Xmax) Xmax = Other.Xmax;
200 if ( ! IsOpenYmin() )
202 if (Other.IsOpenYmin()) OpenYmin();
203 else if (Ymin > Other.Ymin) Ymin = Other.Ymin;
205 if ( ! IsOpenYmax() )
207 if (Other.IsOpenYmax()) OpenYmax();
208 else if (Ymax < Other.Ymax) Ymax = Other.Ymax;
210 Gap = Max (Gap, Other.Gap);
214 //=======================================================================
217 //=======================================================================
219 void Bnd_Box2d::Add (const gp_Dir2d& D)
221 Standard_Real DX = D.X();
222 Standard_Real DY = D.Y();
224 if (DX < -RealEpsilon())
226 else if (DX > RealEpsilon())
229 if (DY < -RealEpsilon())
231 else if (DY > RealEpsilon())
235 //=======================================================================
238 //=======================================================================
240 Standard_Boolean Bnd_Box2d::IsOut (const gp_Pnt2d& P) const
242 if (IsWhole()) return Standard_False;
243 else if (IsVoid()) return Standard_True;
245 Standard_Real X = P.X();
246 Standard_Real Y = P.Y();
247 if (!(Flags & XminMask) && (X < (Xmin-Gap))) return Standard_True;
248 else if (!(Flags & XmaxMask) && (X > (Xmax+Gap))) return Standard_True;
249 else if (!(Flags & YminMask) && (Y < (Ymin-Gap))) return Standard_True;
250 else if (!(Flags & YmaxMask) && (Y > (Ymax+Gap))) return Standard_True;
251 else return Standard_False;
255 //=======================================================================
258 //=======================================================================
260 Standard_Boolean Bnd_Box2d::IsOut (const Bnd_Box2d& Other) const
262 if (IsWhole()) return Standard_False;
263 else if (IsVoid()) return Standard_True;
264 else if (Other.IsWhole()) return Standard_False;
265 else if (Other.IsVoid()) return Standard_True;
267 Standard_Real OXmin,OXmax,OYmin,OYmax;
268 Other.Get(OXmin,OYmin,OXmax,OYmax);
269 if (!(Flags & XminMask) && (OXmax < (Xmin-Gap))) return Standard_True;
270 else if (!(Flags & XmaxMask) && (OXmin > (Xmax+Gap))) return Standard_True;
271 else if (!(Flags & YminMask) && (OYmax < (Ymin-Gap))) return Standard_True;
272 else if (!(Flags & YmaxMask) && (OYmin > (Ymax+Gap))) return Standard_True;
274 return Standard_False;
277 //=======================================================================
280 //=======================================================================
282 void Bnd_Box2d::Dump () const
285 if (IsVoid()) cout << "Void";
286 else if (IsWhole()) cout << "Whole";
288 cout << "\n Xmin : ";
289 if (IsOpenXmin()) cout << "Infinite";
291 cout << "\n Xmax : ";
292 if (IsOpenXmax()) cout << "Infinite";
294 cout << "\n Ymin : ";
295 if (IsOpenYmin()) cout << "Infinite";
297 cout << "\n Ymax : ";
298 if (IsOpenYmax()) cout << "Infinite";
301 cout << "\n Gap : " << Gap;